1 | grammar com.framsticks.framclipse.FramScript with org.eclipse.xtext.common.Terminals |
---|
2 | |
---|
3 | import "http://www.eclipse.org/emf/2002/Ecore" as ecore |
---|
4 | |
---|
5 | generate framScript "http://www.framsticks.com/framclipse/FramScript" |
---|
6 | |
---|
7 | Model : |
---|
8 | (Neuro|Expdef|Style|Show|Script|Include) ; |
---|
9 | |
---|
10 | FramclipseClass : |
---|
11 | (Neuro|Expdef|Style|Show|Script|Property|State) ; |
---|
12 | |
---|
13 | Neuro : |
---|
14 | 'class:' |
---|
15 | // 'name:' name=ID |
---|
16 | headers+=NeuroHeader+ |
---|
17 | code=CodeSection |
---|
18 | (propertyImports+=PropertyIncludeDeclaration | |
---|
19 | properties+=Property)* |
---|
20 | ; |
---|
21 | |
---|
22 | Expdef : |
---|
23 | 'expdef:' |
---|
24 | headers+=Header+ |
---|
25 | code=CodeSection |
---|
26 | (propertyImports+=PropertyIncludeDeclaration | |
---|
27 | properties+=Property | |
---|
28 | states+=State)* |
---|
29 | ; |
---|
30 | |
---|
31 | Style : |
---|
32 | 'style:' |
---|
33 | headers+=Header+ |
---|
34 | code=CodeSection |
---|
35 | (propertyImports+=PropertyIncludeDeclaration | |
---|
36 | properties+=Property)* |
---|
37 | ; |
---|
38 | |
---|
39 | Show : |
---|
40 | 'show:' |
---|
41 | headers+=ShowHeader+ |
---|
42 | code=CodeSection |
---|
43 | (propertyImports+=PropertyIncludeDeclaration | |
---|
44 | properties+=Property)* |
---|
45 | ; |
---|
46 | |
---|
47 | Script : |
---|
48 | 'script:' |
---|
49 | headers+=Header+ |
---|
50 | code=CodeSection |
---|
51 | ; |
---|
52 | |
---|
53 | Property : |
---|
54 | 'prop:' |
---|
55 | headers += PropertyHeader* |
---|
56 | 'id:' name=ID |
---|
57 | headers += PropertyHeader+ |
---|
58 | ; |
---|
59 | |
---|
60 | State : |
---|
61 | 'state:' |
---|
62 | headers += PropertyHeader* |
---|
63 | 'id:' name=ID |
---|
64 | headers += PropertyHeader+ |
---|
65 | ; |
---|
66 | |
---|
67 | Include : {Include} |
---|
68 | code=Code? |
---|
69 | (properties+=Property | |
---|
70 | states+=State)* |
---|
71 | ; |
---|
72 | |
---|
73 | Header : |
---|
74 | name=ID value=HEADER_VALUE ; |
---|
75 | |
---|
76 | NeuroHeader returns Header : |
---|
77 | {IntHeader} name=('prefinputs:' | 'prefoutput:' | 'preflocation:' | 'vhints:') intValue=IntValue | |
---|
78 | {IconHeader} name='icon:' icon=Icon | |
---|
79 | {IconHeader} name='icon:~' icon=Icon '~' | |
---|
80 | Header ; |
---|
81 | |
---|
82 | Icon : |
---|
83 | INT (',' INT)+ ; |
---|
84 | |
---|
85 | PropertyHeader returns Header : |
---|
86 | TypeHeader | |
---|
87 | FlagsHeader | |
---|
88 | Header ; |
---|
89 | |
---|
90 | ShowHeader returns Header : |
---|
91 | name='expdef:' value=ID | |
---|
92 | Header ; |
---|
93 | |
---|
94 | FlagsHeader returns Header : |
---|
95 | {IntHeader} name='flags:' intValue=INT ; |
---|
96 | |
---|
97 | TypeHeader : |
---|
98 | name='type:' type=PropertyType ; |
---|
99 | |
---|
100 | PropertyType : |
---|
101 | name=ID (min=Number (max=Number default=Number?)? enums+=ENUM_LITERAL* )? ; |
---|
102 | |
---|
103 | terminal ENUM_LITERAL : |
---|
104 | '~' !('~'|'\r'|'\n')+ ; |
---|
105 | |
---|
106 | Number : |
---|
107 | '-'? (INT | DOUBLE) ; |
---|
108 | |
---|
109 | CodeSection returns Code : |
---|
110 | 'code:~' Code '~' ; |
---|
111 | |
---|
112 | Code : |
---|
113 | (includes += IncludeDeclaration | |
---|
114 | globals += Global | |
---|
115 | functions += Function)+; |
---|
116 | |
---|
117 | Global returns VariableDeclarations : |
---|
118 | 'global' vars+=VariableDeclaration (',' vars+=VariableDeclaration)* ';' ; |
---|
119 | |
---|
120 | Function : |
---|
121 | 'function' name=ID (',' aliases+=ID)* '(' (params+=VariableDeclaration (',' params+=VariableDeclaration)*)? ')' code=Block ; |
---|
122 | |
---|
123 | IncludeDeclaration : |
---|
124 | '@include' importURI=STRING ; |
---|
125 | |
---|
126 | PropertyIncludeDeclaration : |
---|
127 | '#include' importURI=STRING ; |
---|
128 | |
---|
129 | Block : |
---|
130 | {Block} '{' statements+=Statement* '}' ; |
---|
131 | |
---|
132 | Statement : |
---|
133 | ( VariableDeclarationStatement | |
---|
134 | ExpressionStatement | |
---|
135 | DoStatement | |
---|
136 | ContinueStatement | |
---|
137 | BreakStatement | |
---|
138 | ReturnStatement | |
---|
139 | GotoStatment ) ';' | |
---|
140 | IncludeDeclaration | |
---|
141 | Block | |
---|
142 | SwitchStatement | |
---|
143 | LabeledStatement | |
---|
144 | IfStatement | |
---|
145 | WhileStatement | |
---|
146 | ForStatement | |
---|
147 | {EmptyStatement} ';' ; |
---|
148 | |
---|
149 | VariableDeclarationStatement returns VariableDeclarations : |
---|
150 | 'var' vars+=VariableDeclaration (',' vars+=VariableDeclaration)* ; |
---|
151 | |
---|
152 | VariableDeclaration : |
---|
153 | name=ID ('=' value=Expression)?; |
---|
154 | |
---|
155 | IfStatement : |
---|
156 | 'if' '(' condition=Expression ')' if=Statement ('else' else=Statement)? ; |
---|
157 | |
---|
158 | ForStatement : |
---|
159 | 'for' '(' init=Assignment? ';' condition=Expression? ';' step=Assignment? ')' body=Statement ; |
---|
160 | |
---|
161 | WhileStatement : |
---|
162 | 'while' '(' condition=Expression ')' body=Statement ; |
---|
163 | |
---|
164 | DoStatement : |
---|
165 | 'do' body=Statement 'while' condition=ParExpression ; |
---|
166 | |
---|
167 | LabeledStatement : |
---|
168 | name=ID ':' body=Statement ; |
---|
169 | |
---|
170 | GotoStatment : |
---|
171 | 'goto' dest=[LabeledStatement] ; |
---|
172 | |
---|
173 | ReturnStatement : |
---|
174 | {ReturnStatement} 'return' (expr=Expression)? ; |
---|
175 | |
---|
176 | ContinueStatement : |
---|
177 | {ContinueStatement} 'continue' (dest=[LabeledStatement])? ; |
---|
178 | |
---|
179 | BreakStatement : |
---|
180 | {BreakStatement} 'break' (dest=[LabeledStatement])? ; |
---|
181 | |
---|
182 | SwitchStatement : |
---|
183 | 'switch' condition=ParExpression '{' labels+=SwitchGroup* '}' ; |
---|
184 | |
---|
185 | SwitchGroup : |
---|
186 | label=SwitchLabel body=SwitchBlock ; |
---|
187 | |
---|
188 | SwitchBlock returns Block : |
---|
189 | {Block} statements+=Statement* ; |
---|
190 | |
---|
191 | SwitchLabel: |
---|
192 | 'case' expr = Expression ':' | |
---|
193 | {DefaultSwitchLabel} 'default' ':' ; |
---|
194 | |
---|
195 | ExpressionStatement : |
---|
196 | Assignment ; |
---|
197 | |
---|
198 | AssignmentOperator : |
---|
199 | '=' | '+=' | '-=' | '*=' | '/=' ; |
---|
200 | |
---|
201 | ParExpression returns Expression: |
---|
202 | '(' Expression ')' ; |
---|
203 | |
---|
204 | Assignment : |
---|
205 | Expression ( {Assignment.left=current} op=AssignmentOperator right=Assignment)? ; |
---|
206 | |
---|
207 | Expression : |
---|
208 | UnaryExpression ({Expression.left=current} op=Operator right=Expression)? | |
---|
209 | WildcardExpression ; |
---|
210 | |
---|
211 | UnaryExpression : |
---|
212 | QualifiedExpression2 ({UnaryExpression.arg=current} op = IncrementOperator)? | |
---|
213 | op = (IncrementOperator | UnaryOperator) arg = QualifiedExpression2 | |
---|
214 | Literal ; |
---|
215 | |
---|
216 | QualifiedExpression2 returns QualifiedExpression : |
---|
217 | QualifiedExpression | |
---|
218 | (PropertyAccess|StateAccess) ({QualifiedExpression.parent=current}'.' child=QualifiedExpression )? ; |
---|
219 | |
---|
220 | QualifiedExpression : |
---|
221 | ArrayElementExpression ({QualifiedExpression.parent=current}'.' child=QualifiedExpression )? ; |
---|
222 | |
---|
223 | ArrayElementExpression : |
---|
224 | TerminalExpression ({ArrayElementExpression.array=current} ('[' indexes+=Expression ']')+ )? ; |
---|
225 | |
---|
226 | TerminalExpression: |
---|
227 | Invocation | |
---|
228 | Array | |
---|
229 | Vector | |
---|
230 | {VariableRef} var=[VariableDeclaration]; |
---|
231 | |
---|
232 | Invocation : |
---|
233 | function=[Function] '(' (args+=Expression (',' args+=Expression)*)? ')' ; |
---|
234 | |
---|
235 | WildcardExpression : |
---|
236 | value=ID '.*' ; |
---|
237 | |
---|
238 | PropertyAccess returns QualifiedExpression : |
---|
239 | ('Fields.'|'ExpParams.'|'ShowParams.'|'VisParams.') property=[Property] ; |
---|
240 | |
---|
241 | StateAccess returns QualifiedExpression : |
---|
242 | 'ExpState.' state=[State] ; |
---|
243 | |
---|
244 | Literal: |
---|
245 | {IntLiteral} value=IntValue | |
---|
246 | {DoubleLiteral} value=DoubleValue | |
---|
247 | {StringLiteral} value=STRING | |
---|
248 | {HexLiteral} value=HEX | |
---|
249 | {NullLiteral} 'null' ; |
---|
250 | |
---|
251 | Array : |
---|
252 | '[' elements+=Expression (',' elements+=Expression)* ']' ; |
---|
253 | |
---|
254 | Vector : |
---|
255 | '(' elements+=Expression (',' elements+=Expression)* ')' ; |
---|
256 | |
---|
257 | Operator : |
---|
258 | '+' | '-' | '*'| '/' | |
---|
259 | '&'| '|' | '%' | |
---|
260 | '==' | '!=' | '>=' | '<=' | '<' | '>' | |
---|
261 | '&&' | '||' ; |
---|
262 | |
---|
263 | UnaryOperator : |
---|
264 | '!' | '+' | '-' | 'typeof'; |
---|
265 | |
---|
266 | IncrementOperator : |
---|
267 | '++' | '--' ; |
---|
268 | |
---|
269 | IntValue returns ecore::EInt hidden() : |
---|
270 | ('+'|'-')? INT ; |
---|
271 | |
---|
272 | DoubleValue hidden() : |
---|
273 | ('+'|'-')? DOUBLE ; |
---|
274 | |
---|
275 | terminal DOUBLE : |
---|
276 | ('0'..'9')*'.'('0'..'9')+ ('e' INT)? | |
---|
277 | INT 'e' INT ; |
---|
278 | |
---|
279 | terminal HEX : |
---|
280 | '0x' (('0'..'9')|('a'..'f')|('A'..'F'))+ ; |
---|
281 | |
---|
282 | terminal HEADER_VALUE : |
---|
283 | ':' !('~'|' '|'\t'|'\r'|'\n') !('\n'|'\r')* ('\r'? '\n') | |
---|
284 | ':~' -> '~'('\r'? '\n') |
---|
285 | ; |
---|
286 | |
---|
287 | terminal SL_COMMENT : ('//' | '# ') !('\n'|'\r')* ('\r'? '\n')?; |
---|
288 | |
---|