forked from hflicka/ardensyntax-eclipse-plugin
-
Notifications
You must be signed in to change notification settings - Fork 1
/
ArdenSyntax.xtext
761 lines (630 loc) · 21.1 KB
/
ArdenSyntax.xtext
1
2
3
4
5
6
7
8
9
10
11
12
13
14
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
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
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
grammar arden.plugin.editor.ArdenSyntax hidden(WHITESPACE, ML_COMMENT, SL_COMMENT, THE)
generate ardenSyntax "http://www.plugin.arden/editor/ArdenSyntax"
import "http://www.eclipse.org/emf/2002/Ecore" as ecore
/*
This xText Grammar is based on the EGADSS Arden Compiler Grammar
which is licensed under the Terms of the GNU General Public License
Version 2 or above.
Copyright (C) 2004 University of British Columbia
Copyright (C) 2011 Hannes Flicka
This program is distributed in the hope that it will
be useful, but WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU General Public
License for more details.
You should have received a copy of the GNU General
Public License along with this program; if not,
write to the Free Software Foundation, Inc.,
59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/***** starting rule: file of individual MLMs *****/
mlms: (mlms+=mlm)+;
/************ terminals ************/
// helper fragments as terminals are case sensitive (keywords are not)
terminal fragment A: 'a'|'A';
terminal fragment B: 'b'|'B';
terminal fragment C: 'c'|'C';
terminal fragment D: 'd'|'D';
terminal fragment E: 'e'|'E';
terminal fragment F: 'f'|'F';
terminal fragment G: 'g'|'G';
terminal fragment H: 'h'|'H';
terminal fragment I: 'i'|'I';
terminal fragment J: 'j'|'J';
terminal fragment K: 'k'|'K';
terminal fragment L: 'l'|'L';
terminal fragment M: 'm'|'M';
terminal fragment N: 'n'|'N';
terminal fragment O: 'o'|'O';
terminal fragment P: 'p'|'P';
terminal fragment Q: 'q'|'Q';
terminal fragment R: 'r'|'R';
terminal fragment S: 's'|'S';
terminal fragment T: 't'|'T';
terminal fragment U: 'u'|'U';
terminal fragment V: 'v'|'V';
terminal fragment W: 'w'|'W';
terminal fragment X: 'x'|'X';
terminal fragment Y: 'y'|'Y';
terminal fragment Z: 'z'|'Z';
// ignored (hidden) terminals
terminal THE: T H E;
terminal WHITESPACE: (' '|'\t'|'\r'|'\n')+;
terminal ML_COMMENT: '/*' -> '*/';
terminal SL_COMMENT: '//' !('\n'|'\r')* ('\r'? '\n')?;
terminal STRING_LITERAL: '"' (!'"'| '""')* '"';
// identifier
terminal fragment DIGIT: '0'..'9';
terminal fragment LETTER: 'a'..'z' | 'A'..'Z';
terminal fragment UNDERSCORE: '_';
terminal ID: LETTER (LETTER | UNDERSCORE | DIGIT)*;
identifier: name=ID; // rule used for cross references
attribute: name=ID;
/*
* A catch all terminal for the <text>, <format_text> or <mlmname_text> rule would override most
* other terminals. This is solved in SableCC by using parser states, but Xtext doesn't have
* these. To fix this the terminals are matched via the keywords in their surrounding rules and
* later their content is extracted via the ArdenSyntaxValueConverter.
*
* Example:
* title_slot: value=TITLE_SLOT_TERMINAL;
* terminal TITLE_SLOT_TERMINAL: T I T L E ':' -> ';;';
*/
// iso date/datetime
terminal fragment FRACTIONAL_SECONDS: '.' DIGITS;
terminal fragment TIME_ZONE: Z | SIGN DIGIT DIGIT ':' DIGIT DIGIT;
terminal ISO_DATE: DIGIT DIGIT DIGIT DIGIT '-' DIGIT DIGIT '-' DIGIT DIGIT;
terminal ISO_DATE_TIME: ISO_DATE T DIGIT DIGIT ':' DIGIT DIGIT ':' DIGIT DIGIT FRACTIONAL_SECONDS? TIME_ZONE?;
// number
terminal fragment DIGITS: DIGIT+;
terminal fragment SIGN: '+' | '-';
terminal fragment EXPONENT: E SIGN? DIGITS;
terminal NUMBER_LITERAL:
DIGITS '.'? DIGITS? EXPONENT?
| '.' DIGITS EXPONENT?
/*
* The lexer is greedy and tries to invoke the ISO_DATE terminal rule as soon as it sees four digits and a "-".
* This leads to an error when the subsequent characters don't fit the ISO_DATE terminal rule and
* the lexer can't fall back to an alternative terminal rule.
* This is a simple fix, which offers an alternative terminal rule to fall back to.
*
* Examples:
* t := 2000-10-10; // a datetime
* t := 2000-10-100; // two subtractions
* t := 2000-10-1; // two subtractions
* t := 2000-1; // a subtraction
*/
| DIGIT DIGIT DIGIT DIGIT '-' DIGIT+
| DIGIT DIGIT DIGIT DIGIT '-' DIGIT DIGIT '-' DIGIT
| DIGIT DIGIT DIGIT DIGIT '-' DIGIT DIGIT '-' DIGIT DIGIT DIGIT+;
terminal TERM: "'" !(';;'|"'")* "'";
// replaces <mapping_factor>
terminal DATA_MAPPING: '{' !(';;'|'}')* '}';
/******** categories ***********/
mlm:
maintainance_category=maintenance_category
library_category=library_category
knowledge_category=knowledge_category
'end:';
maintenance_category:
'maintenance:' maintainance_body=maintenance_body;
maintenance_body:
title_slot=title_slot
mlmname_slot=mlmname_slot
arden_version_slot=arden_version_slot?
version_slot=version_slot
institution_slot=institution_slot
author_slot=author_slot
specialist_slot=specialist_slot
date_slot=date_slot
validation_slot=validation_slot;
library_category:
'library:' library_body=library_body;
library_body:
purpose_slot=purpose_slot
explanation_slot=explanation_slot
keywords_slot=keywords_slot
citations_slot=citations_slot?
links_slot=links_slot?;
knowledge_category:
'knowledge:' knowledge_body=knowledge_body;
knowledge_body:
type_slot=type_slot
data_slot=data_slot
priority_slot=priority_slot?
evoke_slot=evoke_slot
logic_slot=logic_slot
action_slot=action_slot
urgency_slot=urgency_slot?;
/****** maintenance slots ******/
terminal TITLE_TERMINAL: T I T L E ':' -> ';;';
title_slot: title=TITLE_TERMINAL;
// can't use the following as it would either collide with ID or attributes (containing a dot):
// terminal MLMNAME_TEXT: LETTER (LETTER | DIGIT | '_' | '-' | '.')*;
terminal MLMNAME_TERMINAL: M L M N A M E ':' -> ';;';
terminal FILENAME_TERMINAL: F I L E N A M E ':' -> ';;';
mlmname_slot: mlmname=MLMNAME_TERMINAL | filename=FILENAME_TERMINAL;
// TODO check version while parsing or with validator?
arden_version_slot: 'arden:' 'version' version=NUMBER_LITERAL ';;';
version_slot: {version_slot} 'version:' version=NUMBER_LITERAL? ';;';
terminal INSTITUTION_TERMINAL: I N S T I T U T I O N ':'->';;';
institution_slot: institution=INSTITUTION_TERMINAL;
terminal AUTHOR_TERMINAL: A U T H O R ':' -> ';;';
author_slot: author=AUTHOR_TERMINAL;
terminal SPECIALIST_TERMINAL: S P E C I A L I S T ':' -> ';;';
specialist_slot: specialist=SPECIALIST_TERMINAL;
date_slot: 'date:' date=mlm_date ';;';
mlm_date: ISO_DATE | ISO_DATE_TIME;
validation_slot: 'validation:' validation=validation_code ';;';
validation_code:
'production'
| 'research'
| 'testing'
| 'expired';
/****** library slots ******/
terminal PURPOSE_TERMINAL: P U R P O S E ':' -> ';;';
purpose_slot: purpose=PURPOSE_TERMINAL;
terminal EXPLANATION_TERMINAL: E X P L A N A T I O N ':' -> ';;';
explanation_slot: explanation=EXPLANATION_TERMINAL;
terminal KEYWORDS_TERMINAL: K E Y W O R D S':' -> ';;';
keywords_slot: keywords=KEYWORDS_TERMINAL;
// TODO formated citations
terminal CITATIONS_TERMINAL: C I T A T I O N S ':' -> ';;';
citations_slot: citations=CITATIONS_TERMINAL;
// TODO formated links
terminal LINKS_TERMINAL: L I N K S ':' -> ';;';
links_slot: links=LINKS_TERMINAL;
/****** knowledge: slots ******/
type_slot: 'type:' type=type_code ';;';
type_code:'data_driven' | 'data-driven';
data_slot: 'data:' data_block=data_block ';;';
priority_slot: 'priority:' priority=NUMBER_LITERAL ';;';
evoke_slot: 'evoke:' evoke_block=evoke_block ';;';
logic_slot: 'logic:' logic_block=logic_block ';;';
action_slot: 'action:' action_block=action_block ';;';
urgency_slot: 'urgency:' urgency=urgency_val ';;';
urgency_val:
{urgency_val} value=NUMBER_LITERAL
| id=[identifier];
/****** logic block ******/
logic_block:
statements+=logic_statement (';' statements+=logic_statement)*;
logic_statement:
{logic_statement_empty}
| logic_assignment
| 'IF' logic_if_then_else2
| {logic_for} 'FOR' loop_var=identifier 'IN' iterable=expr 'DO' block=logic_block ';' 'ENDDO'
| {logic_while} 'WHILE' condition=expr 'DO' block=logic_block ';' 'ENDDO'
| {conclude} 'CONCLUDE' condition=expr;
logic_if_then_else2:
condition=expr 'THEN' block=logic_block ';' elseif=logic_elseif;
logic_elseif:
{endif} 'ENDIF'
| {logic_else} 'ELSE' block=logic_block ';' 'ENDIF'
| 'ELSEIF' logic_if_then_else2;
logic_assignment:
{logic_identifier_assignment} id_becomes=identifier_becomes (expr=expr | call=call_phrase | new_object=new_object_phrase)
| {logic_time_assignment} time_becomes=time_becomes expr=expr
| {logic_list_assignment} '(' id_list=data_var_list ')' ':=' call=call_phrase
| {logic_list_assignment} 'LET' '(' id_list=data_var_list ')' 'BE' call=call_phrase;
identifier_becomes:
id=identifier_or_object_ref ':='
| 'LET' id=identifier 'BE'
| now?='NOW' ':=';
// requires at least on attribute or it would shadow the identifier rule
identifier_or_object_ref:
id=identifier
| base_id=[identifier] ('.' attr+=[attribute])+;
time_becomes:
'TIME' 'OF'? time_id=[identifier] ':='
| 'LET' 'TIME' 'OF'? time_id=[identifier] 'BE';
call_phrase:
'CALL' id=[identifier] ('WITH' args=expr)?;
/****** expressions ******/
expr:
expr_sort (',' expr_list+=expr_sort)*
| ',' expr_list+=expr_sort (',' expr_list+=expr_sort)*;
// from specs: >"sort time x" should be parsed as "sort the list x by time" rather than
// as "extract the primary times from the list x and sort the list of times."<
expr_sort:
expr_where ({expr_merge.left=current} 'MERGE' right=expr_sort)?
| 'SORT' => option=sort_option? right=expr_sort;
sort_option:
'TIME'
| 'DATA';
expr_where:
expr_range ({expr_where.left=current} 'WHERE' right=expr_range)?;
expr_range:
expr_or ({expr_range.left=current} 'SEQTO' right=expr_or)?;
expr_or:
expr_and ({expr_or.left=current} 'OR' right=expr_or)?;
expr_and:
expr_not ({expr_and.left=current} 'AND' right=expr_and)?;
expr_not:
expr_comparison
| 'NOT' right=expr_comparison;
expr_comparison:
expr_find_string
| expr_string (
{expr_simple_comp.left=current} op=simple_comp_op right=expr_string
| {expr_is.left=current} is not?='NOT'? op=main_comp_op
| {expr_in.left=current} not?='NOT'? right=in_comp_op
| {expr_occur.left=current} occur not?='NOT'? op=temporal_comp_op // contains <range_comp_op>
| {expr_matches.left=current} 'MATCHES' 'PATTERN' right=expr_string
)?;
expr_find_string:
'FIND' substring=expr_string 'IN'? 'STRING' fullstring=expr_string start=string_search_start?;
string_search_start:
'STARTING' 'AT' expr_plus;
// string literal instead of <format_string>.
// TODO check with validator
expr_string:
(
expr_plus
| {expr_trim} 'TRIM' option=trim_option? right=expr_string
| {expr_substring} 'SUBSTRING' charcount=expr_plus 'CHARACTERS' start=string_search_start? 'FROM' right=expr_string
)(
=>'||' concat_expr_list+=expr_plus
| =>'FORMATTED' 'WITH' format_string_list+=STRING_LITERAL
)*;
trim_option:
'LEFT'
| 'RIGHT';
expr_plus:
expr_addition
| {expr_pos} '+' right=expr_addition
| {expr_neg} '-' right=expr_addition;
// helper to solve left recursion
expr_addition:
expr_times (
{expr_addition.left=current} '+' right=expr_addition
| {expr_subtraction.left=current} '-' right=expr_addition
)?;
expr_times:
expr_power (
{expr_times.left=current} '*' right=expr_times
| {expr_div.left=current} '/' right=expr_times
)?;
// contains a merge of <expr_before>, <expr_ago> and <expr_duration> to solve ambiguity
expr_power:
expr_function (
{expr_power.left=current} '**' right=expr_function
| {expr_duration.left=current} unit=duration_op ( // solve ambiguity with 'FROM' in <expr_string>
(=>(option='FROM'|option='BEFORE'|option='AFTER') right=expr_function) unit_right=duration_op? ago?='AGO'?
| ago?='AGO'?
)
)?;
expr_function:
expr_factor ({expr_as.left=current} 'AS' op=as_func_op)?
| op=of_func_op {expr_of.left=current} 'OF'? right=expr_function
| (
op=from_of_func_op {expr_function.left=current}
| op=index_from_of_func_op {expr_index_function.left=current}
)(
/*
* The LL-parser doesn't know whether to invoke the <expr_factor> or <expr_function> rule.
* Preferring a single rule via predicates (=>) leads to the other being being impossible.
* This is solved by enabling backtracking, as left factoring is not feasible for this rule.
* Examples matched by the rules: "MAXIMUM (1,2,3)" and "MAXIMUM 2 FROM (1,2,3)"
*/
(=>limit=expr_factor 'FROM' | 'OF')?
) right=expr_function
| (
op=from_func_op {expr_function.left=current}
| op=index_from_func_op {expr_index_function.left=current}
) limit=expr_factor 'FROM' right=expr_function
| expr_attribute_from;
expr_attribute_from:
'ATTRIBUTE' attr=expr_factor 'FROM' right=expr_factor;
expr_factor:
expr_array_access ({expr_attr_access.left=current} =>'.' attribute_list+=[attribute])*;
// helper for better AST elements
expr_array_access:
expr_factor_atom ({expr_array_access.left=current} => '[' index=expr ']')?;
expr_factor_atom:
{identifier_use} id=[identifier]
| {number_literal} value=NUMBER_LITERAL
| {string_literal} value=STRING_LITERAL
| {time_constant} value=time_value
| {bool} value=boolean_value
| {null_}'NULL'
| {it} it
/* Value is NULL outside of a where */
/* clause and may be flagged as an */
/* error in some implementations. */
| {brackets} '(' right=expr? ')';
/****** synonyms ******/
it:
'IT'
| 'THEY';
is:
'IS'
| 'ARE'
| 'WAS'
| 'WERE';
occur:
'OCCUR'
| 'OCCURS'
| 'OCCURRED';
/****** operators ******/
simple_comp_op:
'='
| 'EQ'
| '<'
| 'LT'
| '>'
| 'GT'
| '<='
| 'LE'
| '>='
| 'GE'
| '<>'
| 'NE';
main_comp_op:
temporal_comp_op
| unary_comp_op
| binary_comp_op right=expr_string;
// contains <range_comp_op>
temporal_comp_op:
{within} 'WITHIN' (
op='PAST'
| 'SAME' op='DAY' 'AS'
| time_range=expr_string op=('PRECEDING'|'FOLLOWING'|'SURROUNDING'|'TO')
) right=expr_string
| {before} 'BEFORE' right=expr_string
| {after} 'AFTER' right=expr_string
| {time_eq} 'EQUAL' right=expr_string
| {at} 'AT' right=expr_string;
unary_comp_op:
{unary_comp_op} op=(
'PRESENT'
| 'NULL'
| 'BOOLEAN'
| 'NUMBER'
| 'TIME'
| 'DURATION'
| 'STRING'
| 'LIST'
| 'OBJECT'
)
| id=[identifier];
binary_comp_op:
{binary_comp_op} (
'LESS' 'THAN'
| 'GREATER' 'THAN'
| 'GREATER' 'THAN' 'OR' 'EQUAL'
| 'LESS' 'THAN' 'OR' 'EQUAL'
| 'IN'
);
in_comp_op:
'IN' expr_string;
of_func_op:
of_read_func_op
| of_noread_func_op;
of_read_func_op:
'AVERAGE'
| 'AVG'
| 'COUNT'
| 'EXIST'
| 'EXISTS'
| 'SUM'
| 'MEDIAN';
of_noread_func_op:
'ANY'
| 'ALL'
| 'NO'
| 'SLOPE'
| 'STDDEV'
| 'VARIANCE'
| 'INCREASE'
| 'PERCENT' 'INCREASE'
| '%' 'INCREASE'
| 'DECREASE'
| 'PERCENT' 'DECREASE'
| '%' 'DECREASE'
| 'INTERVAL'
| 'TIME'
| 'ARCCOS'
| 'ARCSIN'
| 'ARCTAN'
| 'COSINE'
| 'COS'
| 'SINE'
| 'SIN'
| 'TANGENT'
| 'TAN'
| 'EXP'
| 'FLOOR'
| 'INT'
| 'ROUND'
| 'CEILING'
| 'TRUNCATE'
| 'LOG'
| 'LOG10'
| 'ABS'
| 'SQRT'
| 'EXTRACT' 'YEAR'
| 'EXTRACT' 'MONTH'
| 'EXTRACT' 'DAY'
| 'EXTRACT' 'HOUR'
| 'EXTRACT' 'MINUTE'
| 'EXTRACT' 'SECOND'
| 'STRING'
| 'EXTRACT' 'CHARACTERS'
| 'REVERSE'
| 'LENGTH'
| 'UPPERCASE'
| 'LOWERCASE'
| 'CLONE'
| 'EXTRACT' 'ATTRIBUTE' 'NAMES';
from_func_op:
'NEAREST';
index_from_func_op:
'INDEX' 'NEAREST';
from_of_func_op:
'MINIMUM'
| 'MIN'
| 'MAXIMUM'
| 'MAX'
| 'LAST'
| 'FIRST'
| 'EARLIEST'
| 'LATEST';
index_from_of_func_op:
'INDEX' (
'MINIMUM'
| 'MIN'
| 'MAXIMUM'
| 'MAX'
| 'EARLIEST'
| 'LATEST'
);
as_func_op:
'NUMBER';
duration_op:
'YEAR'
| 'YEARS'
| 'MONTH'
| 'MONTHS'
| 'WEEK'
| 'WEEKS'
| 'DAY'
| 'DAYS'
| 'HOUR'
| 'HOURS'
| 'MINUTE'
| 'MINUTES'
| 'SECOND'
| 'SECONDS';
/****** factors ******/
boolean_value:
'TRUE'
| 'FALSE';
time_value:
'NOW'
| ISO_DATE_TIME
| ISO_DATE
| 'EVENTTIME'
| 'TRIGGERTIME'
| 'CURRENTTIME';
/****** data block ******/
data_block:
statements+=data_statement (';' statements+=data_statement)*;
data_statement:
{data_statement_empty}
| data_assignment
| 'IF' data_if_then_else2
| {data_for} 'FOR' loop_var=identifier 'IN' iterable=expr 'DO' block=data_block ';' 'ENDDO'
| {data_while} 'WHILE' condition=expr 'DO' block=data_block ';' 'ENDDO'
| {include} 'INCLUDE' id=[identifier];
data_if_then_else2:
condition=expr 'THEN' block=data_block ';' elseif=data_elseif;
data_elseif:
{endif} 'ENDIF'
| {data_else} 'ELSE' block=data_block ';' 'ENDIF'
| 'ELSEIF' data_if_then_else2;
data_assignment:
{data_identifier_assignment} id_becomes=identifier_becomes (
phrase=data_assign_phrase
// missing in specs, but required for "read as" statement
| 'READ' ('AS' object_type=[identifier])? phrase=read_phrase
)
| {data_time_assignment} time_becomes=time_becomes expr=expr
| {data_list_assignment} (
'(' id_list=data_var_list ')' ':='
| 'LET' '(' id_list=data_var_list ')' 'BE'
)(
'READ' ('AS' object_type=[identifier])? phrase=read_phrase
| argument?='ARGUMENT'
);
data_var_list:
id_list+=identifier (',' id_list+=identifier)*;
data_assign_phrase:
// see <data_assignment> for "read as"
{mlm_phrase} 'MLM' (
term=TERM ('FROM' 'INSTITUTION' institution=STRING_LITERAL)?
| 'MLM_SELF'
)
| {interface_phrase} 'INTERFACE' mapping=DATA_MAPPING
| {event_phrase} 'EVENT' mapping=DATA_MAPPING
| {message_phrase} 'MESSAGE' (
mapping=DATA_MAPPING
| 'AS' object_type=[identifier] mapping=DATA_MAPPING?
)
| {destination_phrase} 'DESTINATION' (
mapping=DATA_MAPPING
| 'AS' object_type=[identifier] mapping=DATA_MAPPING?
)
| {argument_phrase} 'ARGUMENT'
| 'OBJECT' object_definition
| call_phrase
| new_object_phrase
| {expr_phrase} expr=expr;
read_phrase:
(op=of_read_func_op 'OF'?)? read_where=read_where
| => op=from_of_func_op (
=> ('OF'? read_where=read_where)
| expr_factor=expr_factor 'FROM' read_where=read_where
);
read_where:
{read_mapping} mapping=DATA_MAPPING
| {read_where} mapping=DATA_MAPPING 'WHERE' it occur not?='NOT'? op=temporal_comp_op
| '(' read_where ')';
object_definition:
'[' attrs=object_attribute_list ']';
object_attribute_list:
attr_list+=attribute (',' attr_list+=attribute)*;
new_object_phrase:
'NEW' id=[identifier] ('WITH' fields=expr)?;
/****** evoke block ******/
evoke_block:
statements+=evoke_statement (';' statements+=evoke_statement)*;
evoke_statement:
{evoke_statement_empty}
| {evoke_event} event=event_or
| evoke_time
| qualified_evoke_cycle
| {evoke_call} 'CALL'; /* deprecated -- kept for backward compatibility */
event_list:
events+=event_or (',' events+=event_or)*;
event_or:
event_any ('OR' event_list+=event_any)*;
event_any:
'ANY' 'OF'? (
'(' list=event_list ')'
| event_id=[identifier]
)
| event_factor;
event_factor:
'(' bracket_event=event_or ')'
| event_id=[identifier];
evoke_time:
{evoke_after} duration=evoke_duration 'AFTER' time=evoke_time
| {evoke_time_of} 'TIME' 'OF'? event=event_any
| datetime=ISO_DATE_TIME
| date=ISO_DATE;
qualified_evoke_cycle:
simple_evoke_cycle ('UNTIL' until=expr)?;
simple_evoke_cycle:
'EVERY' cycle_duration=evoke_duration 'FOR' duration=evoke_duration 'STARTING' start=evoke_time;
evoke_duration:
count=NUMBER_LITERAL unit=duration_op;
/****** action block ******/
action_block:
statements+=action_statement (';' statements+=action_statement)*;
action_statement:
{action_statement_empty}
| 'IF' action_if_then_else2
| {action_for} 'FOR' loop_var=identifier 'IN' iterable=expr 'DO' block=action_block ';' 'ENDDO'
| {action_while} 'WHILE' condition=expr 'DO' block=action_block ';' 'ENDDO'
| {action_call} phrase=call_phrase ('DELAY' delay=expr)?
| {action_write} 'WRITE' message=expr ('AT' target=[identifier])?
| {action_return} 'RETURN' return_value=expr
| time_becomes expr=expr
| {action_assignment} id_becomes=identifier_becomes (expr=expr | new_object=new_object_phrase);
action_if_then_else2:
condition=expr 'THEN' block=action_block ';' elseif=action_elseif;
action_elseif:
{endif} 'ENDIF'
| {action_else} 'ELSE' block=action_block ';' 'ENDIF'
| 'ELSEIF' action_if_then_else2;