gr_grs_parser.mly 24.9 KB
Newer Older
pj2m's avatar
pj2m committed
1 2
%{

bguillaum's avatar
bguillaum committed
3 4
open Grew_ast
open Grew_utils
pj2m's avatar
pj2m committed
5

6
(* Some intermediate sum types used in sub-functions when building the ast *)
pj2m's avatar
pj2m committed
7
type pat_item = 
bguillaum's avatar
bguillaum committed
8 9 10
  | Pat_node of Ast.node
  | Pat_edge of Ast.edge
  | Pat_const of Ast.const
pj2m's avatar
pj2m committed
11 12

type graph_item =
13
  | Graph_meta of (string * string)
bguillaum's avatar
bguillaum committed
14 15
  | Graph_node of Ast.node
  | Graph_edge of Ast.edge
pj2m's avatar
pj2m committed
16 17 18 19 20

let get_loc () = (!Parser_global.current_file,!Parser_global.current_line+1)
let localize t = (t,get_loc ())
%}

21 22 23 24 25 26 27 28 29 30
%token LACC                        /* { */
%token RACC                        /* } */
%token LBRACKET                    /* [ */
%token RBRACKET                    /* ] */
%token LPAREN                      /* ( */
%token RPAREN                      /* ) */
%token DDOT                        /* : */
%token COMA                        /* , */
%token SEMIC                       /* ; */
%token STAR                        /* * */
bguillaum's avatar
bguillaum committed
31
%token SHARP                       /* # */
bguillaum's avatar
bguillaum committed
32
%token PLUS                        /* + */
33 34
%token EQUAL                       /* = */
%token DISEQUAL                    /* <> */
bguillaum's avatar
bguillaum committed
35 36 37 38 39 40

%token LT                          /* < */
%token GT                          /* > */
%token LE                          /* <= or  */
%token GE                          /* >= or  */

41 42 43 44 45 46 47 48 49
%token PIPE                        /* | */
%token GOTO_NODE                   /* -> */
%token LTR_EDGE_LEFT               /* -[ */
%token LTR_EDGE_LEFT_NEG           /* -[^ */
%token LTR_EDGE_RIGHT              /* ]-> */
%token RTL_EDGE_LEFT               /* <-[ */
%token RTL_EDGE_RIGHT              /* ]- */
%token LONGARROW                   /* ==> */

50
%token INCLUDE                     /* include */
51
%token FEATURES                    /* features */
bguillaum's avatar
bguillaum committed
52 53
%token FEATURE                     /* feature */
%token FILE                        /* file */
54 55 56 57 58 59 60
%token LABELS                      /* labels */
%token MATCH                       /* match */
%token WITHOUT                     /* without */
%token COMMANDS                    /* commands */
%token MODULE                      /* module */
%token CONFLUENT                   /* confluent */
%token RULE                        /* rule */
bguillaum's avatar
bguillaum committed
61
%token LEX_RULE                    /* lex_rule */
62
%token FILTER                      /* filter */
63 64 65 66 67 68
%token SEQUENCES                   /* sequences */
%token GRAPH                       /* graph */

%token DEL_EDGE                    /* del_edge */
%token ADD_EDGE                    /* add_edge */
%token MERGE                       /* merge */
69 70
%token SHIFT_IN                    /* shift_in */
%token SHIFT_OUT                   /* shift_out */
71 72 73 74 75
%token SHIFT                       /* shift */
%token DEL_NODE                    /* del_node */
%token ADD_NODE                    /* add_node */
%token DEL_FEAT                    /* del_feat */

76 77
%token <string> PAT                /* $id */
%token <string> CMD                /* @id */
bguillaum's avatar
bguillaum committed
78

bguillaum's avatar
bguillaum committed
79
%token <string>           IDENT    /* indentifier */
80
%token <Grew_ast.Ast.qfn> QFN      /* ident.ident */
bguillaum's avatar
bguillaum committed
81 82 83
%token <string>           STRING
%token <int>              INT
%token <string list>      COMMENT
84
%token <string list>      LP
pj2m's avatar
pj2m committed
85

86
%token EOF                         /* end of file */
pj2m's avatar
pj2m committed
87

bguillaum's avatar
bguillaum committed
88 89 90
%start <Grew_ast.Ast.grs_with_include> grs_with_include
%start <Grew_ast.Ast.grs> grs
%start <Grew_ast.Ast.gr> gr
91
%start <Grew_ast.Ast.module_or_include list> included
pj2m's avatar
pj2m committed
92 93
%%

bguillaum's avatar
bguillaum committed
94 95 96 97 98 99 100 101 102 103 104

%public separated_list_final_opt(separator,X):
|                                                               { [] }
|   x=X                                                         { [x] }
|   x=X; separator; xs = separated_list_final_opt(separator,X)  { x :: xs }

%public separated_nonempty_list_final_opt(separator,X):
|   x=X                                                                  { [x] }
|   x=X; separator                                                       { [x] }
|   x=X; separator; xs = separated_nonempty_list_final_opt(separator,X)  { x :: xs }

105

pj2m's avatar
pj2m committed
106
/*=============================================================================================*/
107
/*  BASIC DEFINITIONS                                                                          */
pj2m's avatar
pj2m committed
108
/*=============================================================================================*/
109 110 111 112
value:
        | v = IDENT { v }
        | v = STRING { v }
        | v = INT { string_of_int v }
pj2m's avatar
pj2m committed
113

114 115 116
/*=============================================================================================*/
/*  GREW GRAPH                                                                                 */
/*=============================================================================================*/
pj2m's avatar
pj2m committed
117
gr: 
bguillaum's avatar
bguillaum committed
118
        | GRAPH LACC items = separated_list_final_opt(SEMIC,gr_item) RACC EOF 
119 120
            {
             {
121
              Ast.meta = List_.opt_map (function Graph_meta n -> Some n | _ -> None) items;
bguillaum's avatar
bguillaum committed
122 123
              Ast.nodes = List_.opt_map (function Graph_node n -> Some n | _ -> None) items;
              Ast.edges = List_.opt_map (function Graph_edge n -> Some n | _ -> None) items;
124 125
            }
           }
bguillaum's avatar
bguillaum committed
126

pj2m's avatar
pj2m committed
127
gr_item:
128 129 130 131
        (* sentence = "Jean dort." *)
        | id = IDENT EQUAL value = value
            { Graph_meta (id, value) }

bguillaum's avatar
bguillaum committed
132
        (* B (1) [phon="pense", lemma="penser", cat=v, mood=ind ] *)
bguillaum's avatar
bguillaum committed
133
        | id = IDENT position = option(delimited(LPAREN,num,RPAREN)) feats = delimited(LBRACKET,separated_list_final_opt(COMA,node_features),RBRACKET) 
bguillaum's avatar
bguillaum committed
134
            { Graph_node (localize {Ast.node_id = id; position=position; fs=feats}) }
pj2m's avatar
pj2m committed
135

bguillaum's avatar
bguillaum committed
136
        (* A -[x|y|z]-> B*)
bguillaum's avatar
bguillaum committed
137
        | n1 = IDENT labels = delimited(LTR_EDGE_LEFT,separated_nonempty_list(PIPE,label_ident),LTR_EDGE_RIGHT) n2 = IDENT
bguillaum's avatar
bguillaum committed
138
            { Graph_edge (localize {Ast.edge_id = None; src=n1; edge_labels=labels; tar=n2; negative=false; }) }
pj2m's avatar
pj2m committed
139

bguillaum's avatar
bguillaum committed
140
num:
141
        | INT { $1 }
pj2m's avatar
pj2m committed
142

143 144
label_ident:
        | x = separated_nonempty_list(DDOT,IDENT) { String.concat ":" x }
pj2m's avatar
pj2m committed
145 146 147 148 149 150 151 152 153 154 155 156 157 158









/*=============================================================================================*/
/*  GREW GRAPH SYSTEM REWRITING                                                                */
/*=============================================================================================*/


159 160 161
grs_with_include:
        | f = features_group g = global_labels m = module_or_include_list s = sequences EOF 
            {
bguillaum's avatar
bguillaum committed
162
             { Ast.domain_wi=f; 
163 164 165 166 167 168
               labels_wi=g; 
               modules_wi=m; 
               sequences_wi=s;
             }
           }
     
pj2m's avatar
pj2m committed
169
grs:
170 171
        | f = features_group g = global_labels m = modules s = sequences EOF 
            {
bguillaum's avatar
bguillaum committed
172
             { Ast.domain=f; 
173 174 175 176 177
               labels=g; 
               modules=m; 
               sequences=s;
             }
           }
178 179 180 181 182
       
module_or_include_list:
        | x = list(module_or_include) { x }

module_or_include:
bguillaum's avatar
bguillaum committed
183
        | m = grew_module        { Ast.Modul m }
184
        | INCLUDE sub = subfile SEMIC { Ast.Includ sub } 
pj2m's avatar
pj2m committed
185

186 187
subfile:
        | f = STRING  { localize f }
pj2m's avatar
pj2m committed
188 189 190 191 192 193 194 195 196 197 198 199 200 201

/*=============================================================================================*/
/*                                                                                             */
/* FEATURES DOMAIN DEFINITION                                                                  */
/*                                                                                             */
/* features {                                                                                  */
/*      cat: n, np, v, adj;                                                                    */
/*      mood: inf, ind, subj, pastp, presp;                                                    */
/*      lemma: *; phon: *                                                                      */
/* }                                                                                           */
/*                                                                                             */
/*=============================================================================================*/

features_group:
202 203
        | FEATURES x = features { x }
        
pj2m's avatar
pj2m committed
204
%inline features:
bguillaum's avatar
bguillaum committed
205 206
        | LACC x = separated_nonempty_list_final_opt(SEMIC,feature) RACC { x }

pj2m's avatar
pj2m committed
207
%inline feature:
208
        | name = feature_name DDOT values = features_values 
bguillaum's avatar
bguillaum committed
209 210 211 212 213
            {
              match values with
                | ["*"] -> Ast.Open name
                | ["#"] -> Ast.Int name
                | _ -> Ast.Closed (name, List.sort Pervasives.compare values)
214
            }
pj2m's avatar
pj2m committed
215 216

feature_name:
217
        | word = IDENT { word }
pj2m's avatar
pj2m committed
218 219

features_values:
220
        | STAR { ["*"] }
bguillaum's avatar
bguillaum committed
221
        | SHARP { ["#"] }
222
        | x = separated_nonempty_list(COMA,value) { x }
pj2m's avatar
pj2m committed
223 224 225 226 227 228 229 230 231 232 233


/*=============================================================================================*/
/*                                                                                             */
/* GLOBAL LABELS DEFINITION                                                                    */
/*                                                                                             */
/* labels { OBJ, SUBJ, DE_OBJ, ANT }                                                           */
/*                                                                                             */
/*=============================================================================================*/

%inline labels:
bguillaum's avatar
bguillaum committed
234
        | x = delimited(LACC,separated_nonempty_list_final_opt(COMA,label),RACC) { x }
235
        
pj2m's avatar
pj2m committed
236
%inline label:
237
        (* | x = IDENT color = option(ddot_color)  { (x, color) } *)
pj2m's avatar
pj2m committed
238

239
        | x = label_ident display = list(CMD)  { (x, display) }
pj2m's avatar
pj2m committed
240 241

global_labels:
242
        | LABELS x = labels { x }
pj2m's avatar
pj2m committed
243 244 245 246 247 248 249 250 251 252 253 254


/*=============================================================================================*/
/*                                                                                             */
/* MODULE DEFINITION                                                                           */
/*                                                                                             */
/* module p7_to_p7p-mc {                                                                       */
/*   ...                                                                                       */
/* }                                                                                           */
/*                                                                                             */
/*=============================================================================================*/

255
included:
256
        | x = list (module_or_include) EOF { x }
257

pj2m's avatar
pj2m committed
258
modules:
259 260
        | x = list(grew_module) { x }
        
pj2m's avatar
pj2m committed
261
grew_module: 
262
        | doc = option(module_doc) MODULE conf = boption(CONFLUENT) id = module_id LACC l = option(local_labels) r = rules RACC 
263 264
           {
            { Ast.module_id = fst id; 
bguillaum's avatar
bguillaum committed
265 266
              local_labels = (match l with None -> [] | Some x -> x);
              rules = r;
267
              confluent = conf;
bguillaum's avatar
bguillaum committed
268
              module_doc = (match doc with Some d -> d | None -> []);
269 270
              mod_loc = (!Parser_global.current_file, snd id);
              mod_dir = "";
271 272
            }
          }
pj2m's avatar
pj2m committed
273 274

module_id:
275
        | id = IDENT { (id,!Parser_global.current_line+1) }
pj2m's avatar
pj2m committed
276 277

module_doc:
278
        | comment = COMMENT { comment } 
pj2m's avatar
pj2m committed
279 280 281 282 283 284 285 286 287 288 289 290

/*=============================================================================================*/
/*                                                                                             */
/* LOCAL LABELS DEFINITION                                                                     */
/*                                                                                             */
/* labels {ANT_TMP}                                                                            */
/*                                                                                             */
/*=============================================================================================*/



local_labels:
291
        | LABELS x = labels { x }
pj2m's avatar
pj2m committed
292 293 294 295 296 297 298 299 300 301 302 303


/*=============================================================================================*/
/*                                                                                             */
/* RULES DEFINITION                                                                            */
/*                                                                                             */
/* rule ant_prorel_init {                                                                      */
/*   ...                                                                                       */
/* }                                                                                           */
/*=============================================================================================*/

rules:
304
        | r = list(rule) { r }
pj2m's avatar
pj2m committed
305 306

rule: 
307 308
        | doc = option(rule_doc) RULE id = rule_id LACC p = pos_item n = list(neg_item) cmds = commands RACC 
            { 
bguillaum's avatar
bguillaum committed
309
              { Ast.rule_id = fst id;
310 311
                pos_pattern = p;
                neg_patterns = n;
bguillaum's avatar
bguillaum committed
312
                commands = cmds;
bguillaum's avatar
bguillaum committed
313
                param = None;
314
                lp = None;
bguillaum's avatar
bguillaum committed
315
                rule_doc = begin match doc with Some d -> d | None -> [] end;
316 317 318
                rule_loc = (!Parser_global.current_file,snd id);
              }
            }         
319
        | doc = option(rule_doc) LEX_RULE id = rule_id param=option(param) LACC p = pos_item n = list(neg_item) cmds = commands RACC lp = option(lp)
bguillaum's avatar
bguillaum committed
320 321 322 323
            { 
              { Ast.rule_id = fst id;
                pos_pattern = p;
                neg_patterns = n;
bguillaum's avatar
bguillaum committed
324
                commands = cmds;
bguillaum's avatar
bguillaum committed
325
                param = param;
326
                lp = lp;
bguillaum's avatar
bguillaum committed
327
                rule_doc = begin match doc with Some d -> d | None -> [] end;
bguillaum's avatar
bguillaum committed
328 329 330
                rule_loc = (!Parser_global.current_file,snd id);
              }
            }         
331 332 333 334 335 336 337
        | doc = option(rule_doc) FILTER id = rule_id LACC p = pos_item n = list(neg_item) RACC 
            { 
              { Ast.rule_id = fst id;
                pos_pattern = p;
                neg_patterns = n;
                commands = [];
                param = None;
338
                lp = None;
bguillaum's avatar
bguillaum committed
339
                rule_doc = begin match doc with Some d -> d | None -> [] end;
340 341 342
                rule_loc = (!Parser_global.current_file,snd id);
              }
            }
343 344 345 346

lp:
        | lp = LP  {lp}

bguillaum's avatar
bguillaum committed
347
param:
348 349
        | LPAREN FEATURE vars = separated_nonempty_list(COMA,var) RPAREN { ([],vars) }
        | LPAREN FEATURE vars = separated_nonempty_list(COMA,var) SEMIC files = separated_list(COMA, file) RPAREN { (files,vars) }
bguillaum's avatar
bguillaum committed
350

351 352
file:
        | FILE f=STRING {f}
bguillaum's avatar
bguillaum committed
353 354 355 356
var:
        | i = PAT {i}
        | i = CMD {i}

pj2m's avatar
pj2m committed
357
pos_item:
358
        | MATCH i = pn_item { i }
pj2m's avatar
pj2m committed
359 360

neg_item:
361 362
        | WITHOUT i = pn_item { i }
          
pj2m's avatar
pj2m committed
363
pn_item: 
bguillaum's avatar
bguillaum committed
364
        | l = delimited(LACC,separated_nonempty_list_final_opt(SEMIC,pat_item),RACC)
365 366
            {
             {
bguillaum's avatar
bguillaum committed
367 368 369
              Ast.pat_nodes = List_.opt_map (function Pat_node n -> Some n | _ -> None) l;
              Ast.pat_edges = List_.opt_map (function Pat_edge n -> Some n | _ -> None) l;
              Ast.pat_const = List_.opt_map (function Pat_const n -> Some n | _ -> None) l;
370 371 372
            }
           }
        
pj2m's avatar
pj2m committed
373
rule_id:
374
        | id = IDENT { (id,!Parser_global.current_line+1) }
pj2m's avatar
pj2m committed
375 376

rule_doc:
377 378
        | comment = COMMENT { comment } 
        
pj2m's avatar
pj2m committed
379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394
/*=============================================================================================*/
/*                                                                                             */
/* MATCH DEFINITION                                                                            */
/*                                                                                             */
/* match {                                                                                     */
/*      P [cat = prorel];                                                                      */
/*      N -> P;                                                                                */
/*                                                                                             */
/*      without { P -[ANT]-> * }                                                               */
/*      without { P -[ANT_TMP]-> * }                                                           */
/*    }                                                                                        */
/*                                                                                             */
/*=============================================================================================*/


pat_item:
395 396 397
        | n = pat_node { Pat_node n }
        | e = pat_edge { Pat_edge e }
        | c = pat_const { Pat_const c }
pj2m's avatar
pj2m committed
398

399
pat_node:
bguillaum's avatar
bguillaum committed
400
        | id = IDENT feats = delimited(LBRACKET,separated_list_final_opt(COMA,node_features),RBRACKET) 
bguillaum's avatar
bguillaum committed
401
            { localize ({Ast.node_id = id; position=None; fs= feats}) }
pj2m's avatar
pj2m committed
402 403

node_features:
404
        | name = IDENT EQUAL STAR 
bguillaum's avatar
bguillaum committed
405
            { localize {Ast.kind = Ast.Disequality []; name=name; } } 
406
        | name = IDENT EQUAL values = separated_nonempty_list(PIPE,value)
bguillaum's avatar
bguillaum committed
407
            { localize {Ast.kind = Ast.Equality values; name=name; } } 
408
        | name = IDENT DISEQUAL values = separated_nonempty_list(PIPE,value)
bguillaum's avatar
bguillaum committed
409 410 411
            { localize {Ast.kind = Ast.Disequality values; name=name; } } 
        | name = IDENT EQUAL p = PAT
            { localize {Ast.kind = Ast.Param p; name=name; } } 
pj2m's avatar
pj2m committed
412

413
pat_edge:
414
        (* "e: A -> B" OR "e: A -[*]-> B" *)
415
        | id = edge_id n1 = IDENT GOTO_NODE n2 = IDENT
bguillaum's avatar
bguillaum committed
416
        | id = edge_id n1 = IDENT LTR_EDGE_LEFT STAR LTR_EDGE_RIGHT n2 = label_ident
bguillaum's avatar
bguillaum committed
417
               { localize ({Ast.edge_id = Some id; src=n1; edge_labels=[]; tar=n2; negative=true}) }
418 419 420

        (* "A -> B" *)
        | n1 = IDENT GOTO_NODE n2 = IDENT
bguillaum's avatar
bguillaum committed
421
               { localize ({Ast.edge_id = None; src=n1; edge_labels=[]; tar=n2; negative=true}) }
422 423

        (* "e: A -[^X|Y]-> B" *)
bguillaum's avatar
bguillaum committed
424
        | id = edge_id n1 = IDENT labels = delimited(LTR_EDGE_LEFT_NEG,separated_nonempty_list(PIPE,label_ident),LTR_EDGE_RIGHT) n2 = IDENT
bguillaum's avatar
bguillaum committed
425
            { localize ({Ast.edge_id = Some id; src=n1; edge_labels=labels; tar=n2; negative=true}) }
426 427
            
        (* "A -[^X|Y]-> B"*)
bguillaum's avatar
bguillaum committed
428
        | n1 = IDENT labels = delimited(LTR_EDGE_LEFT_NEG,separated_nonempty_list(PIPE,label_ident),LTR_EDGE_RIGHT) n2 = IDENT
bguillaum's avatar
bguillaum committed
429
            { localize ({Ast.edge_id = None; src=n1; edge_labels=labels; tar=n2; negative=true}) }
pj2m's avatar
pj2m committed
430

431
        (* "e: A -[X|Y]-> B" *)
bguillaum's avatar
bguillaum committed
432
        | id = edge_id n1 = IDENT labels = delimited(LTR_EDGE_LEFT,separated_nonempty_list(PIPE,label_ident),LTR_EDGE_RIGHT) n2 = IDENT
bguillaum's avatar
bguillaum committed
433
            { localize ({Ast.edge_id = Some id; src=n1; edge_labels=labels; tar=n2; negative=false}) }       
pj2m's avatar
pj2m committed
434

435
        (* "A -[X|Y]-> B" *)
bguillaum's avatar
bguillaum committed
436
        | n1 = IDENT labels = delimited(LTR_EDGE_LEFT,separated_nonempty_list(PIPE,label_ident),LTR_EDGE_RIGHT) n2 = IDENT
bguillaum's avatar
bguillaum committed
437
            { localize ({Ast.edge_id = None; src=n1; edge_labels=labels; tar=n2; negative=false}) }
pj2m's avatar
pj2m committed
438 439 440


edge_id:
441
        | id = IDENT DDOT { id }
pj2m's avatar
pj2m committed
442

443
pat_const:
bguillaum's avatar
bguillaum committed
444
        (* "A -[X|Y]-> *" *)
bguillaum's avatar
bguillaum committed
445
        | n1 = IDENT labels = delimited(LTR_EDGE_LEFT,separated_nonempty_list(PIPE,label_ident),LTR_EDGE_RIGHT) STAR
bguillaum's avatar
bguillaum committed
446
            { localize (Ast.Start (n1,labels)) }
bguillaum's avatar
bguillaum committed
447 448 449

        (* "A -> *" *)
        | n1 = IDENT GOTO_NODE STAR
bguillaum's avatar
bguillaum committed
450
            { localize (Ast.Cst_out n1) }
bguillaum's avatar
bguillaum committed
451 452

        (* "* -[X|Y]-> A" *)
bguillaum's avatar
bguillaum committed
453
        | STAR labels = delimited(LTR_EDGE_LEFT,separated_nonempty_list(PIPE,label_ident),LTR_EDGE_RIGHT) n2 = IDENT
bguillaum's avatar
bguillaum committed
454
            { localize (Ast.End (n2,labels)) }
pj2m's avatar
pj2m committed
455

bguillaum's avatar
bguillaum committed
456 457
        (* "* -> A" *)
        | STAR GOTO_NODE n2 = IDENT
bguillaum's avatar
bguillaum committed
458
            { localize (Ast.Cst_in n2) }
pj2m's avatar
pj2m committed
459

bguillaum's avatar
bguillaum committed
460
        (* X.cat = Y.cat *)
461
        | qfn1 = QFN EQUAL qfn2 = QFN
bguillaum's avatar
bguillaum committed
462
            { localize (Ast.Feature_eq (qfn1, qfn2)) }
463

bguillaum's avatar
bguillaum committed
464
        (* X.position < Y.position *)
bguillaum's avatar
bguillaum committed
465 466 467
        | qfn1 = QFN LT qfn2 = QFN
            { localize (Ast.Feature_ineq (Ast.Lt, qfn1, qfn2)) }

bguillaum's avatar
bguillaum committed
468
        (* X.position > Y.position *)
bguillaum's avatar
bguillaum committed
469 470 471
        | qfn1 = QFN GT qfn2 = QFN
            { localize (Ast.Feature_ineq (Ast.Gt, qfn1, qfn2)) }

bguillaum's avatar
bguillaum committed
472
        (* X.position <= Y.position *)
bguillaum's avatar
bguillaum committed
473 474 475
        | qfn1 = QFN LE qfn2 = QFN
            { localize (Ast.Feature_ineq (Ast.Le, qfn1, qfn2)) }

bguillaum's avatar
bguillaum committed
476
        (* X.position >= Y.position *)
bguillaum's avatar
bguillaum committed
477 478 479
        | qfn1 = QFN GE qfn2 = QFN
            { localize (Ast.Feature_ineq (Ast.Ge, qfn1, qfn2)) }

pj2m's avatar
pj2m committed
480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506
/*=============================================================================================*/
/*                                                                                             */
/* COMMANDS DEFINITION                                                                         */
/*                                                                                             */
/* commands {                                                                                  */
/*      del_edge A -[OBJ]-> B;                                                                 */
/*      del_edge e;                                                                            */
/*                                                                                             */
/*      add_edge A -[ATS]-> B;                                                                 */
/*                                                                                             */
/*      shift A ==> B;                                                                         */
/*                                                                                             */
/*      del_node A;                                                                            */
/*                                                                                             */
/*      add_node D: <-[SUJ]- A;                                                                */
/*                                                                                             */
/*      A.mood = inf;                                                                          */
/*                                                                                             */
/*      B.tense = A.tense;                                                                     */
/*                                                                                             */
/*      del_feat A.tense;                                                                      */
/* }                                                                                           */
/*                                                                                             */
/*=============================================================================================*/


commands:
bguillaum's avatar
bguillaum committed
507
        | COMMANDS x = delimited(LACC,separated_nonempty_list_final_opt(SEMIC,command),RACC) { x }
pj2m's avatar
pj2m committed
508 509

command:
510
        | DEL_EDGE n = IDENT
bguillaum's avatar
bguillaum committed
511
            { localize (Ast.Del_edge_name n) }
bguillaum's avatar
bguillaum committed
512
        | DEL_EDGE n1 = IDENT label = delimited(LTR_EDGE_LEFT,label_ident,LTR_EDGE_RIGHT) n2 = IDENT
bguillaum's avatar
bguillaum committed
513
            { localize (Ast.Del_edge_expl (n1,n2,label)) }
bguillaum's avatar
bguillaum committed
514
        | ADD_EDGE n1 = IDENT label = delimited(LTR_EDGE_LEFT,label_ident,LTR_EDGE_RIGHT) n2 = IDENT
bguillaum's avatar
bguillaum committed
515
            { localize (Ast.Add_edge (n1,n2,label)) }
516
        | SHIFT_IN n1 = IDENT LONGARROW n2 = IDENT 
bguillaum's avatar
bguillaum committed
517
            { localize (Ast.Shift_in (n1,n2)) }
518
        | SHIFT_OUT n1 = IDENT LONGARROW n2 = IDENT 
bguillaum's avatar
bguillaum committed
519
            { localize (Ast.Shift_out (n1,n2)) }
520
        | SHIFT n1 = IDENT LONGARROW n2 = IDENT 
bguillaum's avatar
bguillaum committed
521
            { localize (Ast.Shift_edge (n1,n2)) }
bguillaum's avatar
bguillaum committed
522
        | MERGE n1 = IDENT LONGARROW n2 = IDENT
bguillaum's avatar
bguillaum committed
523
            { localize (Ast.Merge_node (n1,n2)) }
bguillaum's avatar
bguillaum committed
524
        | DEL_NODE n = IDENT
bguillaum's avatar
bguillaum committed
525
            { localize (Ast.Del_node n) }
bguillaum's avatar
bguillaum committed
526
        | ADD_NODE n1 = IDENT DDOT label = delimited(RTL_EDGE_LEFT,label_ident,RTL_EDGE_RIGHT) n2 = IDENT
bguillaum's avatar
bguillaum committed
527
            { localize (Ast.New_neighbour (n1,n2,label)) }
528
        | DEL_FEAT qfn = QFN 
bguillaum's avatar
bguillaum committed
529
            { localize (Ast.Del_feat qfn) }
530
        | qfn = QFN EQUAL items = separated_nonempty_list (PLUS, concat_item)
bguillaum's avatar
bguillaum committed
531
            { localize (Ast.Update_feat (qfn, items)) }
532 533

concat_item:
534 535
        | qfn = QFN    { Ast.Qfn_item qfn }
        | s = IDENT    { Ast.String_item s }
bguillaum's avatar
bguillaum committed
536
        | s = STRING   { Ast.String_item s }
537
        | p = CMD      { Ast.Param_item p }
bguillaum's avatar
bguillaum committed
538
        | p = PAT      { Ast.Param_item p }
pj2m's avatar
pj2m committed
539 540 541 542 543 544 545 546 547 548

/*=============================================================================================*/
/*                                                                                             */
/* SEQUENCE DEFINITION                                                                         */
/*                                                                                             */
/* sequence { ant; p7_to_p7p-mc}                                                               */
/*                                                                                             */
/*=============================================================================================*/

sequences:
549
        | SEQUENCES seq = delimited(LACC,list(sequence),RACC) { seq }
pj2m's avatar
pj2m committed
550 551

sequence:
bguillaum's avatar
bguillaum committed
552
        | doc = option(COMMENT) id = sequence_id mod_names = delimited(LACC,separated_list_final_opt(SEMIC,IDENT),RACC) 
553 554
            { 
              { Ast.seq_name = fst id; 
bguillaum's avatar
bguillaum committed
555
                seq_mod = mod_names ; 
bguillaum's avatar
bguillaum committed
556
                seq_doc = begin match doc with Some d -> d | None -> [] end; 
557 558 559
                seq_loc = (!Parser_global.current_file,snd id);
              } 
            }
pj2m's avatar
pj2m committed
560 561

sequence_id:
562
        | id = IDENT { (id,!Parser_global.current_line+1) }
pj2m's avatar
pj2m committed
563 564

%%