grew_ast.mli 4.51 KB
Newer Older
bguillaum's avatar
bguillaum committed
1 2 3
open Grew_utils
 
module Ast : sig
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
  type feature_name = string (* cat, num, ... *)
  type feature_atom = string (* V, N, inf, ... *)
  type feature_value = string (* V, 4, "free text", ... *)

  (* -------------------------------------------------------------------------------- *)
  (* complex_id: V, V#alpha, V.cat, V#alpha.cat, p_obj.loc *)
  type complex_id =
    | No_sharp of string
    | Sharp of string * string
  val complex_id_to_string: complex_id -> string

  (* simple_id: V *)
  type simple_id = Id.name
  val simple_id_of_ci: complex_id -> string
  val is_simple: complex_id -> bool

  (* label_id: V *)
  type label_id = Id.name
  val label_id_of_ci: complex_id -> string

  (* act_id: V, V#alpha *)
  type act_id = Id.name * string option
  val act_id_of_ci: complex_id -> act_id
  val act_id_to_string: act_id -> string

  (* simple_qfn: V.cat *)
  type simple_qfn = Id.name * feature_name
  val simple_qfn_of_ci: complex_id -> simple_qfn
  val simple_qfn_to_string: simple_qfn -> string

  (* act_id: V.cat, V#alpha.cat *)
  type act_qfn = act_id * feature_name
  val act_qfn_of_ci: complex_id -> act_qfn


bguillaum's avatar
bguillaum committed
39
  type feature_spec = 
40 41 42
    | Closed of feature_name * feature_atom list (* cat:V,N *)
    | Open of feature_name (* phon, lemma, ... *)
    | Int of feature_name (* position *)
bguillaum's avatar
bguillaum committed
43

bguillaum's avatar
bguillaum committed
44
  type domain = feature_spec list
bguillaum's avatar
bguillaum committed
45
  val normalize_domain: domain -> domain
46

bguillaum's avatar
bguillaum committed
47
  type feature_kind = 
48 49 50
    | Equality of feature_value list
    | Disequality of feature_value list
    | Param of string (* $ident *)
bguillaum's avatar
bguillaum committed
51
    | Absent
bguillaum's avatar
bguillaum committed
52 53

  type u_feature = {
54 55 56
    name: feature_name;
    kind: feature_kind;
  }
bguillaum's avatar
bguillaum committed
57 58 59 60 61 62 63 64 65
  type feature = u_feature * Loc.t

  type u_node = {
      node_id: Id.name;
      position: int option;
      fs: feature list;
    }
  type node = u_node * Loc.t

66 67
  type edge_label = string (* p_obj.agt:suj *)

bguillaum's avatar
bguillaum committed
68 69 70
  type u_edge = {
      edge_id: Id.name option;
      src: Id.name;
71
      edge_labels: edge_label list;
bguillaum's avatar
bguillaum committed
72 73 74 75 76
      tar: Id.name;
      negative: bool;
    }
  type edge = u_edge * Loc.t

77

bguillaum's avatar
bguillaum committed
78 79 80
  type ineq = Lt | Gt | Le | Ge
  val string_of_ineq: ineq -> string

bguillaum's avatar
bguillaum committed
81
  type u_const = 
82 83 84 85 86 87 88
    | Start of Id.name * edge_label list (* (source, labels) *)
    | Cst_out of Id.name
    | End of Id.name * edge_label list (* (target, labels) *)
    | Cst_in of Id.name
    | Feature_eq of simple_qfn * simple_qfn
    | Feature_diseq of simple_qfn * simple_qfn
    | Feature_ineq of ineq * simple_qfn * simple_qfn
bguillaum's avatar
bguillaum committed
89 90 91 92 93 94 95 96 97
  type const = u_const * Loc.t

  type pattern = {
      pat_nodes: node list;
      pat_edges: edge list;
      pat_const: const list;
    }

  type concat_item =
98
    | Qfn_item of complex_id
bguillaum's avatar
bguillaum committed
99
    | String_item of string
100
    | Param_item of string
101

bguillaum's avatar
bguillaum committed
102
  type u_command = 
103
    | Del_edge_expl of (act_id * act_id * edge_label)
bguillaum's avatar
bguillaum committed
104
    | Del_edge_name of string
105 106 107 108 109 110 111 112 113 114 115
    | Add_edge of (act_id * act_id * edge_label)
    | Shift_in of (act_id * act_id)
    | Shift_out of (act_id * act_id)
    | Shift_edge of (act_id * act_id)
    | Merge_node of (act_id * act_id)
    | New_neighbour of (Id.name * act_id * edge_label)
    | Del_node of act_id
    | Activate of act_id

    | Del_feat of act_qfn
    | Update_feat of act_qfn * concat_item list
bguillaum's avatar
bguillaum committed
116
  type command = u_command * Loc.t
bguillaum's avatar
bguillaum committed
117

bguillaum's avatar
bguillaum committed
118 119 120 121 122
  type rule = {
      rule_id:Id.name;
      pos_pattern: pattern;
      neg_patterns: pattern list;
      commands: command list;
123 124
      param: (string list * string list) option; (* (files, vars) *)
      lp: string list option; (* lexical parameters in the file *)
bguillaum's avatar
bguillaum committed
125
      rule_doc:string list;
bguillaum's avatar
bguillaum committed
126 127 128 129 130
      rule_loc: Loc.t;
    }
        
  type modul = {
      module_id:Id.name;
131
      local_labels: (string * string list) list;
132
      new_node_names: string list;
bguillaum's avatar
bguillaum committed
133 134
      rules: rule list;
      confluent: bool;
bguillaum's avatar
bguillaum committed
135
      module_doc:string list;
bguillaum's avatar
bguillaum committed
136
      mod_loc:Loc.t;
137
      mod_dir: string; (* the directory where the module is defined (for lp file localisation) *)
bguillaum's avatar
bguillaum committed
138 139 140 141 142
    }
        
  type sequence = {
      seq_name:string;
      seq_mod:string list;
bguillaum's avatar
bguillaum committed
143
      seq_doc:string list;
bguillaum's avatar
bguillaum committed
144 145 146 147 148 149 150 151
      seq_loc:Loc.t;
    }
        
(** 
    a GRS: graph rewriting system 
 *)
  type module_or_include = 
    | Modul of modul
152
    | Includ of (string * Loc.t)
bguillaum's avatar
bguillaum committed
153 154 155

  type grs_with_include = {
      domain_wi: domain;
156
      labels_wi: (string * string list) list;    (* the list of global edge labels *)
bguillaum's avatar
bguillaum committed
157 158 159 160 161 162
      modules_wi: module_or_include list; 
      sequences_wi: sequence list;
    }

  type grs = {
      domain: domain;
163
      labels: (string * string list) list;
bguillaum's avatar
bguillaum committed
164 165 166 167 168
      modules: modul list;
      sequences: sequence list;
    }

  type gr = {
169 170 171 172
    meta: (string * string) list;
    nodes: node list;
    edges: edge list;
  }
bguillaum's avatar
bguillaum committed
173 174

  val empty_grs: grs
bguillaum's avatar
bguillaum committed
175
end (* module Ast *)