-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExpression.g4
More file actions
131 lines (109 loc) · 2.37 KB
/
Expression.g4
File metadata and controls
131 lines (109 loc) · 2.37 KB
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
// Expression.g4: ANTLR4 grammar for computed boolean expressions in state chart diagrams
grammar Expression;
// Parser rules
assignment
: variableReference ASSIGN valueReference
;
expression
: orExpr
;
orExpr
: andExpr (OR andExpr)*
;
andExpr
: notExpr (AND notExpr)*
;
notExpr
: NOT notExpr
| atom
;
atom
: comparison
| '(' expression ')'
| quantifierExpression
| timeoutExpression
;
timeoutExpression
: NOW GTE variableReference (PLUS valueReference)?
;
quantifierExpression
: ('Any' | 'All') '(' quantifierVariableName 'in' propertyName '|' variableReference compOp valueReference ')'
;
comparison
: variableReference compOp valueReference
;
compOp
: EQUAL
| NOTEQUAL
;
propertyName
: AT (NAME_LOWER_SNAKE_CASE | NAME_ALL_LOWERCASE)
;
graphOrInterfaceName
: (NAME_PASCAL_CASE | NAME_ALL_UPPERCASE)
;
variableName
: (NAME_PASCAL_CASE | NAME_ALL_UPPERCASE)
;
quantifierVariableName
: (NAME_CAMEL_CASE | NAME_ALL_LOWERCASE)
;
// Graph or interface variable reference: NAME optionally followed by [NAME], then dot, then variable NAME
// e.g. SCI_TDS.occupancy_status or Zone[@underlying_zone].State
variableReference
: graphOrInterfaceName (LBRACK (propertyName | quantifierVariableName) RBRACK)? DOT variableName
| variableName
;
valueReference
: qualifiedName
| durationLiteral
| propertyName
| booleanLiteral
| noneLiteral
;
// Qualified name (e.g., OccupancyStatus::OCCUPIED)
qualifiedName
: enumerationTypeName DCOLON enumerationLiteralName
;
durationLiteral
: NUMBER MILLISECONDS
| NOW
;
booleanLiteral
: 'true'
| 'false'
;
noneLiteral
: 'None'
;
enumerationTypeName
: (NAME_PASCAL_CASE | NAME_ALL_UPPERCASE)
;
enumerationLiteralName
: (NAME_UPPER_SNAKE_CASE | NAME_ALL_UPPERCASE)
;
// Lexer rules
AND: '&&';
OR: '||';
NOT: '!';
EQUAL: '==';
NOTEQUAL: '!=';
LBRACK: '[';
RBRACK: ']';
DOT: '.';
DCOLON: '::';
AT: '@';
NOW: 'now';
MILLISECONDS: 'ms';
GTE: '>=';
PLUS: '+';
NAME_ALL_LOWERCASE: [a-z][a-z0-9]*;
NAME_ALL_UPPERCASE: [A-Z][A-Z0-9]*;
NAME_LOWER_SNAKE_CASE: [a-z][a-z0-9_]*;
NAME_CAMEL_CASE: [a-z][A-Za-z0-9]*;
NAME_UPPER_SNAKE_CASE: [A-Z][A-Z0-9_]*;
NAME_PASCAL_CASE: [A-Z][A-Za-z0-9]*;
NUMBER: [0-9]+;
ASSIGN: '=';
PUMLNEWLINE: ('\\n') -> skip;
WS: [ \t\r\n]+ -> skip;