gr_grs_parser.mly 24.7 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*)
137
        | n1 = IDENT labels = delimited(LTR_EDGE_LEFT,separated_nonempty_list(PIPE,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
145
146
147
148
149
150
151
152
153
154
155
156










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


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

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

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

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

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

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

feature_name:
215
        | word = IDENT { word }
pj2m's avatar
pj2m committed
216
217

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


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

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

ddot_color:
238
        | DDOT color = IDENT { color }
pj2m's avatar
pj2m committed
239
240

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


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

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

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

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

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

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



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


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

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

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

lp:
        | lp = LP  {lp}

bguillaum's avatar
bguillaum committed
346
param:
347
348
        | 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
349

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

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

neg_item:
360
361
        | WITHOUT i = pn_item { i }
          
pj2m's avatar
pj2m committed
362
pn_item: 
bguillaum's avatar
bguillaum committed
363
        | l = delimited(LACC,separated_nonempty_list_final_opt(SEMIC,pat_item),RACC)
364
365
            {
             {
bguillaum's avatar
bguillaum committed
366
367
368
              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;
369
370
371
            }
           }
        
pj2m's avatar
pj2m committed
372
rule_id:
373
        | id = IDENT { (id,!Parser_global.current_line+1) }
pj2m's avatar
pj2m committed
374
375

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


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

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

node_features:
403
        | name = IDENT EQUAL STAR 
bguillaum's avatar
bguillaum committed
404
            { localize {Ast.kind = Ast.Disequality []; name=name; } } 
405
        | name = IDENT EQUAL values = separated_nonempty_list(PIPE,value)
bguillaum's avatar
bguillaum committed
406
            { localize {Ast.kind = Ast.Equality values; name=name; } } 
407
        | name = IDENT DISEQUAL values = separated_nonempty_list(PIPE,value)
bguillaum's avatar
bguillaum committed
408
409
410
            { 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
411

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

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

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

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

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


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

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

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

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

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

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

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

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

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

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

pj2m's avatar
pj2m committed
479
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
/*=============================================================================================*/
/*                                                                                             */
/* 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
506
        | COMMANDS x = delimited(LACC,separated_nonempty_list_final_opt(SEMIC,command),RACC) { x }
pj2m's avatar
pj2m committed
507
508

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

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

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

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

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

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

%%