grew_ast.mli 6.3 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 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40

  (* ---------------------------------------------------------------------- *)
  (* simple_ident: V.cat *)
  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

41
  (* -------------------------------------------------------------------------------- *)
42 43
  (* command_node_ident: V, V#alpha, V.cat, V#alpha.cat, p_obj.loc *)
  type command_node_ident =
44 45
    | No_sharp of string
    | Sharp of string * string
46 47
  val parse_command_node_ident: string -> command_node_ident
  val dump_command_node_ident: command_node_ident -> string
48

49
  val base_command_node_ident: command_node_ident -> string
50

51 52 53 54 55
  (* ---------------------------------------------------------------------- *)
  (* 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
56

57
  (* ---------------------------------------------------------------------- *)
58
  type feature_kind =
59 60
    | Equality of feature_value list
    | Disequality of feature_value list
bguillaum's avatar
bguillaum committed
61
    | Equal_param of string (* $ident *)
bguillaum's avatar
bguillaum committed
62
    | Absent
bguillaum's avatar
bguillaum committed
63 64

  type u_feature = {
65 66 67
    name: feature_name;
    kind: feature_kind;
  }
bguillaum's avatar
bguillaum committed
68 69 70 71
  type feature = u_feature * Loc.t

  type u_node = {
      node_id: Id.name;
72
      position: float option;
bguillaum's avatar
bguillaum committed
73 74 75 76
      fs: feature list;
    }
  type node = u_node * Loc.t

77 78
  type edge_label = string (* p_obj.agt:suj *)

bguillaum's avatar
bguillaum committed
79 80 81
  (* (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
82 83 84
  type u_edge = {
      edge_id: Id.name option;
      src: Id.name;
85
      edge_labels: edge_label list;
bguillaum's avatar
bguillaum committed
86 87 88 89 90
      tar: Id.name;
      negative: bool;
    }
  type edge = u_edge * Loc.t

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

94
  type u_const =
95 96 97 98
    | 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
99 100 101
    | Feature_eq of feature_ident * feature_ident
    | Feature_diseq of feature_ident * feature_ident
    | Feature_ineq of ineq * feature_ident * feature_ident
bguillaum's avatar
bguillaum committed
102 103
  type const = u_const * Loc.t

bguillaum's avatar
bguillaum committed
104
  type basic = {
bguillaum's avatar
bguillaum committed
105 106 107 108 109
      pat_nodes: node list;
      pat_edges: edge list;
      pat_const: const list;
    }

110 111 112 113 114
  type pattern = {
      pat_pos: basic;
      pat_negs: basic list;
    }

bguillaum's avatar
bguillaum committed
115
  type concat_item =
116
    | Qfn_item of feature_ident
bguillaum's avatar
bguillaum committed
117
    | String_item of string
118
    | Param_item of string
119

120
  type u_command =
121
    | Del_edge_expl of (command_node_ident * command_node_ident * edge_label)
bguillaum's avatar
bguillaum committed
122
    | Del_edge_name of string
123
    | Add_edge of (command_node_ident * command_node_ident * edge_label)
124 125

    (* 4 args: source, target, labels, flag true iff negative cst *)
bguillaum's avatar
bguillaum committed
126 127 128
    | 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)
129

130 131 132 133 134 135 136
    | 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
137
  type command = u_command * Loc.t
bguillaum's avatar
bguillaum committed
138

bguillaum's avatar
bguillaum committed
139 140
  type rule = {
      rule_id:Id.name;
bguillaum's avatar
bguillaum committed
141 142
      pos_basic: basic;
      neg_basics: basic list;
bguillaum's avatar
bguillaum committed
143
      commands: command list;
144
      param: (string list * string list) option; (* (files, vars) *)
bguillaum's avatar
bguillaum committed
145
      lex_par: string list option; (* lexical parameters in the file *)
bguillaum's avatar
bguillaum committed
146
      rule_doc:string list;
bguillaum's avatar
bguillaum committed
147 148
      rule_loc: Loc.t;
    }
149

bguillaum's avatar
bguillaum committed
150 151
  type modul = {
      module_id:Id.name;
152
      local_labels: (string * string list) list;
153
      suffixes: string list;
bguillaum's avatar
bguillaum committed
154 155
      rules: rule list;
      confluent: bool;
bguillaum's avatar
bguillaum committed
156
      module_doc:string list;
bguillaum's avatar
bguillaum committed
157
      mod_loc:Loc.t;
158
      mod_dir: string; (* the directory where the module is defined (for lp file localisation) *)
bguillaum's avatar
bguillaum committed
159
    }
160

bguillaum's avatar
bguillaum committed
161 162 163
  type sequence = {
      seq_name:string;
      seq_mod:string list;
bguillaum's avatar
bguillaum committed
164
      seq_doc:string list;
bguillaum's avatar
bguillaum committed
165 166
      seq_loc:Loc.t;
    }
167 168

  type module_or_include =
bguillaum's avatar
bguillaum committed
169
    | Modul of modul
170
    | Includ of (string * Loc.t)
bguillaum's avatar
bguillaum committed
171 172

  type grs_with_include = {
bguillaum's avatar
bguillaum committed
173
      domain_wi: Domain.t;
174
      labels_wi: (string * string list) list;    (* the list of global edge labels *)
175
      modules_wi: module_or_include list;
bguillaum's avatar
bguillaum committed
176 177 178
      sequences_wi: sequence list;
    }

179
  (* a GRS: graph rewriting system *)
bguillaum's avatar
bguillaum committed
180
  type grs = {
bguillaum's avatar
bguillaum committed
181
      domain: Domain.t;
182
      labels: (string * string list) list;
bguillaum's avatar
bguillaum committed
183 184 185 186 187
      modules: modul list;
      sequences: sequence list;
    }

  type gr = {
188 189 190 191
    meta: (string * string) list;
    nodes: node list;
    edges: edge list;
  }
bguillaum's avatar
bguillaum committed
192 193

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