grew_ast.mli 4.94 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 41 42 43 44
  (* -------------------------------------------------------------------------------- *)
  (* 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

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

  type u_feature = {
52 53 54
    name: feature_name;
    kind: feature_kind;
  }
bguillaum's avatar
bguillaum committed
55 56 57 58
  type feature = u_feature * Loc.t

  type u_node = {
      node_id: Id.name;
59
      position: float option;
bguillaum's avatar
bguillaum committed
60 61 62 63
      fs: feature list;
    }
  type node = u_node * Loc.t

64 65
  type edge_label = string (* p_obj.agt:suj *)

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

75

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

79
  type u_const =
80 81 82 83 84 85 86
    | 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
87 88
  type const = u_const * Loc.t

bguillaum's avatar
bguillaum committed
89
  type basic = {
bguillaum's avatar
bguillaum committed
90 91 92 93 94 95
      pat_nodes: node list;
      pat_edges: edge list;
      pat_const: const list;
    }

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

100
  type u_command =
101
    | Del_edge_expl of (act_id * act_id * edge_label)
bguillaum's avatar
bguillaum committed
102
    | Del_edge_name of string
103 104 105 106 107 108 109 110 111 112 113
    | 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
114
  type command = u_command * Loc.t
bguillaum's avatar
bguillaum committed
115

bguillaum's avatar
bguillaum committed
116 117
  type rule = {
      rule_id:Id.name;
bguillaum's avatar
bguillaum committed
118 119
      pos_basic: basic;
      neg_basics: basic list;
bguillaum's avatar
bguillaum committed
120
      commands: command list;
121 122
      param: (string list * string list) option; (* (files, vars) *)
      lp: string list option; (* lexical parameters in the file *)
bguillaum's avatar
bguillaum committed
123
      rule_doc:string list;
bguillaum's avatar
bguillaum committed
124 125
      rule_loc: Loc.t;
    }
126

bguillaum's avatar
bguillaum committed
127 128
  type modul = {
      module_id:Id.name;
129
      local_labels: (string * string list) list;
130
      suffixes: string list;
bguillaum's avatar
bguillaum committed
131 132
      rules: rule list;
      confluent: bool;
bguillaum's avatar
bguillaum committed
133
      module_doc:string list;
bguillaum's avatar
bguillaum committed
134
      mod_loc:Loc.t;
135
      mod_dir: string; (* the directory where the module is defined (for lp file localisation) *)
bguillaum's avatar
bguillaum committed
136
    }
137

bguillaum's avatar
bguillaum committed
138 139 140
  type sequence = {
      seq_name:string;
      seq_mod:string list;
bguillaum's avatar
bguillaum committed
141
      seq_doc:string list;
bguillaum's avatar
bguillaum committed
142 143
      seq_loc:Loc.t;
    }
144 145

  type module_or_include =
bguillaum's avatar
bguillaum committed
146
    | Modul of modul
147
    | Includ of (string * Loc.t)
bguillaum's avatar
bguillaum committed
148 149

  type grs_with_include = {
bguillaum's avatar
bguillaum committed
150
      domain_wi: Domain.t;
151
      labels_wi: (string * string list) list;    (* the list of global edge labels *)
152
      modules_wi: module_or_include list;
bguillaum's avatar
bguillaum committed
153 154 155
      sequences_wi: sequence list;
    }

156
  (* a GRS: graph rewriting system *)
bguillaum's avatar
bguillaum committed
157
  type grs = {
bguillaum's avatar
bguillaum committed
158
      domain: Domain.t;
159
      labels: (string * string list) list;
bguillaum's avatar
bguillaum committed
160 161 162 163 164
      modules: modul list;
      sequences: sequence list;
    }

  type gr = {
165 166 167 168
    meta: (string * string) list;
    nodes: node list;
    edges: edge list;
  }
bguillaum's avatar
bguillaum committed
169 170

  val empty_grs: grs
bguillaum's avatar
bguillaum committed
171 172 173 174 175 176

  (* type for the grep mode *)
  type isolated_pattern = {
      isol_pos: basic;
      isol_negs: basic list;
    }
bguillaum's avatar
bguillaum committed
177
end (* module Ast *)