grew_ast.mli 6.84 KB
Newer Older
bguillaum's avatar
bguillaum committed
1 2 3 4 5 6 7 8 9 10
(**********************************************************************************)
(*    Libcaml-grew - a Graph Rewriting library dedicated to NLP applications      *)
(*                                                                                *)
(*    Copyright 2011-2013 Inria, Université de Lorraine                           *)
(*                                                                                *)
(*    Webpage: http://grew.loria.fr                                               *)
(*    License: CeCILL (see LICENSE folder or "http://www.cecill.info")            *)
(*    Authors: see AUTHORS file                                                   *)
(**********************************************************************************)

bguillaum's avatar
bguillaum committed
11
open Grew_base
12
open Grew_types
13

bguillaum's avatar
bguillaum committed
14
module Ast : sig
15 16

  (* ---------------------------------------------------------------------- *)
bguillaum's avatar
bguillaum committed
17
  (* simple_ident: cat or V *)
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
  type simple_ident = Id.name
  val parse_simple_ident: string -> simple_ident
  val is_simple_ident: string -> bool
  val dump_simple_ident: simple_ident -> string

  (* ---------------------------------------------------------------------- *)
  (* label_ident: D:mod.dis *)
  type label_ident = string
  val parse_label_ident: string -> label_ident
  val dump_label_ident: label_ident -> string

  (* ---------------------------------------------------------------------- *)
  (* pattern_label_ident: D:mod.* *)
  type pattern_label_ident = string
  val parse_pattern_label_ident: string -> pattern_label_ident
  val dump_pattern_label_ident: pattern_label_ident -> string

35 36 37 38 39 40
  (* ---------------------------------------------------------------------- *)
  (* node_ident: W0.5 *)
  type node_ident = string
  val parse_node_ident: string -> node_ident
  val dump_node_ident: node_ident -> string

41 42 43 44 45 46
  (* ---------------------------------------------------------------------- *)
  (* feature_ident: V.cat *)
  type feature_ident = Id.name * feature_name
  val parse_feature_ident: string -> feature_ident
  val dump_feature_ident: feature_ident -> string

bguillaum's avatar
bguillaum committed
47 48 49 50 51 52
  (* ---------------------------------------------------------------------- *)
  (* simple_or_feature_ident: union of simple_ident and feature_ident *)
  (* Note: used for parsing of "X < Y" and "X.feat < Y.feat" without conflicts *)
  type simple_or_feature_ident = Id.name * feature_name option
  val parse_simple_or_feature_ident: string -> simple_or_feature_ident

53
  (* ---------------------------------------------------------------------- *)
54
  type feature_kind =
55 56
    | Equality of feature_value list
    | Disequality of feature_value list
bguillaum's avatar
bguillaum committed
57
    | Equal_param of string (* $ident *)
bguillaum's avatar
bguillaum committed
58
    | Absent
bguillaum's avatar
bguillaum committed
59 60

  type u_feature = {
61 62 63
    name: feature_name;
    kind: feature_kind;
  }
bguillaum's avatar
bguillaum committed
64 65 66 67
  type feature = u_feature * Loc.t

  type u_node = {
      node_id: Id.name;
68
      position: float option;
bguillaum's avatar
bguillaum committed
69 70 71 72
      fs: feature list;
    }
  type node = u_node * Loc.t

73 74
  val grewpy_compare: node -> node -> int

75 76
  type edge_label = string (* p_obj.agt:suj *)

77 78 79 80
  type edge_label_cst =
    | Pos_list of edge_label list (*  X|Y|Z    *)
    | Neg_list of edge_label list (*  ^X|Y|Z   *)
    | Regexp of string            (*  re"a.*"  *)
bguillaum's avatar
bguillaum committed
81

bguillaum's avatar
bguillaum committed
82 83 84
  type u_edge = {
      edge_id: Id.name option;
      src: Id.name;
bguillaum's avatar
bguillaum committed
85
      edge_label_cst: edge_label_cst;
bguillaum's avatar
bguillaum committed
86 87 88 89
      tar: Id.name;
    }
  type edge = u_edge * Loc.t

bguillaum's avatar
bguillaum committed
90 91 92
  type ineq = Lt | Gt | Le | Ge
  val string_of_ineq: ineq -> string

93
  type u_const =
94 95
    | Cst_out of Id.name * edge_label_cst
    | Cst_in of Id.name * edge_label_cst
96 97 98
    | Feature_eq of feature_ident * feature_ident
    | Feature_diseq of feature_ident * feature_ident
    | Feature_ineq of ineq * feature_ident * feature_ident
99
    | Feature_ineq_cst of ineq * feature_ident * float
bguillaum's avatar
bguillaum committed
100 101 102
    | Feature_float of feature_ident * float
    | Feature_diff_float of feature_ident * float

bguillaum's avatar
bguillaum committed
103
    | Feature_re of feature_ident * string
bguillaum's avatar
bguillaum committed
104 105 106
    | Feature_cst of feature_ident * string
    | Feature_diff_cst of feature_ident * string

bguillaum's avatar
bguillaum committed
107 108
    | Prec of Id.name * Id.name
    | Lprec of Id.name * Id.name
bguillaum's avatar
bguillaum committed
109 110
  type const = u_const * Loc.t

bguillaum's avatar
bguillaum committed
111
  type basic = {
bguillaum's avatar
bguillaum committed
112 113 114 115 116
      pat_nodes: node list;
      pat_edges: edge list;
      pat_const: const list;
    }

117 118 119 120 121
  type pattern = {
      pat_pos: basic;
      pat_negs: basic list;
    }

122 123
  val complete_pattern : pattern -> pattern

bguillaum's avatar
bguillaum committed
124
  type concat_item =
125
    | Qfn_item of feature_ident
bguillaum's avatar
bguillaum committed
126
    | String_item of string
127
    | Param_item of string
128

129
  type u_command =
bguillaum's avatar
bguillaum committed
130
    | Del_edge_expl of (Id.name * Id.name * edge_label)
bguillaum's avatar
bguillaum committed
131
    | Del_edge_name of string
bguillaum's avatar
bguillaum committed
132
    | Add_edge of (Id.name * Id.name * edge_label)
133 134

    (* 4 args: source, target, labels, flag true iff negative cst *)
bguillaum's avatar
bguillaum committed
135 136 137
    | Shift_in of (Id.name * Id.name * edge_label_cst)
    | Shift_out of (Id.name * Id.name * edge_label_cst)
    | Shift_edge of (Id.name * Id.name * edge_label_cst)
138

bguillaum's avatar
bguillaum committed
139 140
    | Merge_node of (Id.name * Id.name)
    | New_neighbour of (Id.name * Id.name * edge_label)
bguillaum's avatar
bguillaum committed
141 142 143 144 145

    | New_node of Id.name
    | New_before of (Id.name * Id.name)
    | New_after of (Id.name * Id.name)

bguillaum's avatar
bguillaum committed
146
    | Del_node of Id.name
147

bguillaum's avatar
bguillaum committed
148 149
    | Del_feat of feature_ident
    | Update_feat of feature_ident * concat_item list
bguillaum's avatar
bguillaum committed
150
  val string_of_u_command:  u_command -> string
bguillaum's avatar
bguillaum committed
151
  type command = u_command * Loc.t
bguillaum's avatar
bguillaum committed
152

bguillaum's avatar
bguillaum committed
153 154 155 156


  val replace_new_neighbour: command list -> command list

bguillaum's avatar
bguillaum committed
157 158
  type rule = {
      rule_id:Id.name;
159
      pattern: pattern;
bguillaum's avatar
bguillaum committed
160
      commands: command list;
161
      param: (string list * string list) option; (* (files, vars) *)
bguillaum's avatar
bguillaum committed
162
      lex_par: string list option; (* lexical parameters in the file *)
bguillaum's avatar
bguillaum committed
163
      rule_doc:string list;
bguillaum's avatar
bguillaum committed
164 165
      rule_loc: Loc.t;
    }
166

bguillaum's avatar
bguillaum committed
167 168
  type modul = {
      module_id:Id.name;
169
      local_labels: (string * string list) list;
bguillaum's avatar
bguillaum committed
170 171
      rules: rule list;
      confluent: bool;
bguillaum's avatar
bguillaum committed
172
      module_doc:string list;
bguillaum's avatar
bguillaum committed
173
      mod_loc:Loc.t;
174
      mod_dir: string; (* the directory where the module is defined (for lp file localisation) *)
bguillaum's avatar
bguillaum committed
175
    }
176

177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196
  type old_sequence = {
    seq_name:string;
    seq_mod:string list;
    seq_doc:string list;
    seq_loc:Loc.t;
  }

  type new_sequence =
    | Ref of string
    | List of new_sequence list
    | Plus of new_sequence list
    | Star of new_sequence
    | Diamond of new_sequence

  val new_sequence_to_string : new_sequence -> string
  val flatten : new_sequence -> new_sequence

  type sequence =
  | Old of old_sequence
  | New of ((string * Loc.t) * new_sequence)
197 198

  type module_or_include =
bguillaum's avatar
bguillaum committed
199
    | Modul of modul
200
    | Includ of (string * Loc.t)
bguillaum's avatar
bguillaum committed
201

202 203 204 205 206
  type domain = {
      feature_domain: Feature_domain.feature_spec list;
      label_domain: (string * string list) list;
    }

207 208 209
  type domain_wi = Dom of domain | Dom_file of string

  type grs_wi = {
bguillaum's avatar
bguillaum committed
210
      domain_wi: domain_wi option;
211
      modules_wi: module_or_include list;
bguillaum's avatar
bguillaum committed
212 213 214
      sequences_wi: sequence list;
    }

215
  (* a GRS: graph rewriting system *)
bguillaum's avatar
bguillaum committed
216
  type grs = {
bguillaum's avatar
bguillaum committed
217
      domain: domain option;
bguillaum's avatar
bguillaum committed
218 219 220 221 222
      modules: modul list;
      sequences: sequence list;
    }

  type gr = {
223
    meta: string list;
224 225 226
    nodes: node list;
    edges: edge list;
  }
bguillaum's avatar
bguillaum committed
227 228

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