grew_ast.mli 7.09 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 35 36 37 38 39 40
  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

  (* ---------------------------------------------------------------------- *)
  (* 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
41 42 43 44 45 46 47
  (* ---------------------------------------------------------------------- *)
  (* 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

  (* ---------------------------------------------------------------------- *)
48 49
  (* command_node_ident: V, V#alpha, V.cat, V#alpha.cat, p_obj.loc *)
  type command_node_ident =
50 51
    | No_sharp of string
    | Sharp of string * string
52 53
  val parse_command_node_ident: string -> command_node_ident
  val dump_command_node_ident: command_node_ident -> string
54

55
  val base_command_node_ident: command_node_ident -> string
56

57 58 59 60 61
  (* ---------------------------------------------------------------------- *)
  (* command_feature_ident: V.cat, V#alpha.cat *)
  type command_feature_ident = command_node_ident * feature_name
  val parse_command_feature_ident: string -> command_feature_ident
  val dump_command_feature_ident: command_feature_ident -> string
62

63
  (* ---------------------------------------------------------------------- *)
64
  type feature_kind =
65 66
    | Equality of feature_value list
    | Disequality of feature_value list
bguillaum's avatar
bguillaum committed
67
    | Equal_param of string (* $ident *)
bguillaum's avatar
bguillaum committed
68
    | Absent
bguillaum's avatar
bguillaum committed
69 70

  type u_feature = {
71 72 73
    name: feature_name;
    kind: feature_kind;
  }
bguillaum's avatar
bguillaum committed
74 75 76 77
  type feature = u_feature * Loc.t

  type u_node = {
      node_id: Id.name;
78
      position: float option;
bguillaum's avatar
bguillaum committed
79 80 81 82
      fs: feature list;
    }
  type node = u_node * Loc.t

83 84
  type edge_label = string (* p_obj.agt:suj *)

bguillaum's avatar
bguillaum committed
85 86 87
  (* (list of edge_label separated by '|', bool true iff it is a negative constraint) *)
  type edge_label_cst = edge_label list * bool

bguillaum's avatar
bguillaum committed
88 89 90
  type u_edge = {
      edge_id: Id.name option;
      src: Id.name;
bguillaum's avatar
bguillaum committed
91
      edge_label_cst: edge_label_cst;
bguillaum's avatar
bguillaum committed
92 93 94 95
      tar: Id.name;
    }
  type edge = u_edge * Loc.t

bguillaum's avatar
bguillaum committed
96 97 98
  type ineq = Lt | Gt | Le | Ge
  val string_of_ineq: ineq -> string

99
  type u_const =
100 101
    | Cst_out of Id.name * edge_label_cst
    | Cst_in of Id.name * edge_label_cst
102 103 104
    | Feature_eq of feature_ident * feature_ident
    | Feature_diseq of feature_ident * feature_ident
    | Feature_ineq of ineq * feature_ident * feature_ident
105
    | Feature_ineq_cst of ineq * feature_ident * float
bguillaum's avatar
bguillaum committed
106
    | Feature_re 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

bguillaum's avatar
bguillaum committed
110 111
  type const = u_const * Loc.t

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

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

123 124
  val complete_pattern : pattern -> pattern

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

130
  type u_command =
131
    | Del_edge_expl of (command_node_ident * command_node_ident * edge_label)
bguillaum's avatar
bguillaum committed
132
    | Del_edge_name of string
133
    | Add_edge of (command_node_ident * command_node_ident * edge_label)
134 135

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

140 141 142 143 144 145 146
    | Merge_node of (command_node_ident * command_node_ident)
    | New_neighbour of (Id.name * command_node_ident * edge_label)
    | Del_node of command_node_ident
    | Activate of command_node_ident

    | Del_feat of command_feature_ident
    | Update_feat of command_feature_ident * concat_item list
bguillaum's avatar
bguillaum committed
147
  type command = u_command * Loc.t
bguillaum's avatar
bguillaum committed
148

bguillaum's avatar
bguillaum committed
149 150
  type rule = {
      rule_id:Id.name;
151
      pattern: pattern;
bguillaum's avatar
bguillaum committed
152
      commands: command list;
153
      param: (string list * string list) option; (* (files, vars) *)
bguillaum's avatar
bguillaum committed
154
      lex_par: string list option; (* lexical parameters in the file *)
bguillaum's avatar
bguillaum committed
155
      rule_doc:string list;
bguillaum's avatar
bguillaum committed
156 157
      rule_loc: Loc.t;
    }
158

bguillaum's avatar
bguillaum committed
159 160
  type modul = {
      module_id:Id.name;
161
      local_labels: (string * string list) list;
162
      suffixes: string list;
bguillaum's avatar
bguillaum committed
163 164
      rules: rule list;
      confluent: bool;
bguillaum's avatar
bguillaum committed
165
      module_doc:string list;
bguillaum's avatar
bguillaum committed
166
      mod_loc:Loc.t;
167
      mod_dir: string; (* the directory where the module is defined (for lp file localisation) *)
bguillaum's avatar
bguillaum committed
168
    }
169

170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189
  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)
190 191

  type module_or_include =
bguillaum's avatar
bguillaum committed
192
    | Modul of modul
193
    | Includ of (string * Loc.t)
bguillaum's avatar
bguillaum committed
194

195 196 197 198 199
  type domain = {
      feature_domain: Feature_domain.feature_spec list;
      label_domain: (string * string list) list;
    }

200 201 202 203
  type domain_wi = Dom of domain | Dom_file of string

  type grs_wi = {
      domain_wi: domain_wi;
204
      modules_wi: module_or_include list;
bguillaum's avatar
bguillaum committed
205 206 207
      sequences_wi: sequence list;
    }

208
  (* a GRS: graph rewriting system *)
bguillaum's avatar
bguillaum committed
209
  type grs = {
210
      domain: domain;
bguillaum's avatar
bguillaum committed
211 212 213 214 215
      modules: modul list;
      sequences: sequence list;
    }

  type gr = {
216
    meta: string list;
217 218 219
    nodes: node list;
    edges: edge list;
  }
bguillaum's avatar
bguillaum committed
220 221

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