parser: new class AUnaryopExpr to factorize unary operations
[nit.git] / src / parser / nit.sablecc3xx
1
2 /* This file is part of NIT ( http://www.nitlanguage.org ).
3  *
4  * Copyright 2008-2009 Jean Privat <jean@pryen.org>
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  *     http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */
18
19 /* This grammar defines the NIT language. */
20 Package org.nitlanguage.gen;
21
22 /*****************************************************************************/
23 Helpers
24 /*****************************************************************************/
25
26 all = [0 .. 0xFF];
27 lowercase = ['a' .. 'z'];
28 uppercase = ['A' .. 'Z'];
29 digit = ['0' .. '9'];
30 hexdigit = ['0'..'9'] | ['a'..'f'] | ['A'..'F'];
31 letter = lowercase | uppercase | digit | '_';
32
33 tab = 9;
34 cr = 13;
35 lf = 10;
36 any = [all - [cr + lf]];
37 eol_helper = cr lf | cr | lf; // This takes care of different platforms
38
39 // characers inside strings and super-strings (atomaton powaa)
40 str_char
41         = [any - [['"' + '{'] + '\']] 
42         | '\' any 
43         ;
44 str_body = str_char*;
45
46 sstr_char
47         = [any - [''' + '\']]
48         | '\' any
49         ;
50
51 sstr_body = sstr_char*;
52
53 long_str_char = str_char | cr | lf;
54
55 // because no substraction in sablecc3, complex long strings are difficult to express
56 ls1 = '"' '"'? ;
57 ls2 = '{' '{'? ;
58 ls12 = ls1? (ls2 ls1)* ls2?;
59
60 long_str_part
61         = ls12 long_str_char
62         ;
63
64 long_str_body = long_str_part*;
65 lsend1 = ls2? (ls1 ls2)* '"""' '"'*;
66 lsend2 = ls1? (ls2 ls1)* '{{{' '{'*;
67
68 long_sstr_char = sstr_char | cr | lf;
69 long_sstr_part
70         = long_sstr_char
71         | ''' long_sstr_char
72         | ''' ''' long_sstr_char
73         ;
74
75 long_sstr_body = long_sstr_part*;
76
77
78 extern_code_char
79         = [all - ['`' + '\']]
80         | '\' all
81         | '`' [all - '}']
82         ;
83 extern_code_body = extern_code_char*;
84
85 /*****************************************************************************/
86 States
87 /*****************************************************************************/
88 initial;
89
90
91 /*****************************************************************************/
92 Tokens
93 /*****************************************************************************/
94
95 blank = (' ' | tab)+;
96
97 eol = eol_helper;
98 comment = '#' any* eol_helper?;
99
100 kwpackage = 'package';
101 kwmodule = 'module';
102 kwimport = 'import';
103 kwclass = 'class';
104 kwabstract = 'abstract';
105 kwinterface = 'interface';
106 kwenum = 'universal'|'enum';
107 kwend = 'end';
108 kwmeth = 'fun';
109 kwtype = 'type';
110 kwinit = 'init';
111 kwredef = 'redef';
112 kwis = 'is';
113 kwdo = 'do';
114 kwvar = 'var';
115 kwextern = 'extern';
116 kwpublic = 'public';
117 kwprotected = 'protected';
118 kwprivate = 'private';
119 kwintrude = 'intrude';
120 kwif = 'if';
121 kwthen = 'then';
122 kwelse = 'else';
123 kwwhile = 'while';
124 kwloop = 'loop';
125 kwfor = 'for';
126 kwin = 'in';
127 kwand = 'and';
128 kwor = 'or';
129 kwnot = 'not';
130 kwimplies = 'implies';
131 kwreturn = 'return';
132 kwcontinue = 'continue';
133 kwbreak = 'break';
134 kwabort = 'abort';
135 kwassert = 'assert';
136 kwnew = 'new';
137 kwisa = 'isa';
138 kwonce = 'once';
139 kwsuper = 'super';
140 kwself = 'self';
141 kwtrue = 'true';
142 kwfalse = 'false';
143 kwnull = 'null';
144 kwas = 'as';
145 kwnullable = 'nullable';
146 kwisset = 'isset';
147 kwlabel = 'label';
148 kwwith = 'with';
149 kwdebug = '__debug__';
150
151 opar = '(';
152 cpar = ')';
153 obra = '[';
154 cbra = ']';
155 comma = ',';
156 column = ':';
157 quad = '::';
158 assign = '=';
159 pluseq = '+=';
160 minuseq = '-=';
161 stareq = '*=';
162 slasheq = '/=';
163 percenteq = '%=';
164 starstareq = '**=';
165 lleq = '<<=';
166 ggeq = '>>=';
167 dotdotdot = '...';
168 dotdot = '..';
169 dot = '.';
170 plus = '+';
171 minus = '-';
172 star = '*';
173 starstar = '**';
174 slash = '/';
175 percent = '%';
176 eq = '==';
177 ne = '!=';
178 lt = '<';
179 le = '<=';
180 ll = '<<';
181 gt = '>';
182 ge = '>=';
183 gg = '>>';
184 starship = '<=>';
185 bang='!';
186 at='@';
187
188 classid = uppercase letter*;
189 id = lowercase letter*;
190 attrid = '_' lowercase letter*;
191
192 number = digit+;
193 hex_number = ('0x' | '0X') hexdigit+;
194 float = digit* '.' digit+;
195 string = '"' str_body '"' | '"' '"' '"' long_str_body lsend1 | ''' ''' ''' long_sstr_body ''' ''' ''';
196 start_string = '"' str_body '{' | '"' '"' '"' long_str_body lsend2;
197 mid_string = '}' str_body '{' | '}' '}' '}' long_str_body lsend2;
198 end_string = '}' str_body '"' | '}' '}' '}' long_str_body lsend1;
199 char = (''' [[any - '''] - '\'] ''') | (''' '\' any ''');
200 bad_string = ('"'|'}') str_body | '"' '"' '"' long_str_body | ''' ''' ''' long_sstr_body;
201 bad_char = ''' '\'? any;
202
203 extern_code_segment = '`' '{' extern_code_body '`' '}';
204
205 /*****************************************************************************/
206 Ignored Tokens
207 /*****************************************************************************/
208
209 blank;
210
211 /*****************************************************************************/
212 Productions
213 /*****************************************************************************/
214
215 /* MODULES *******************************************************************/
216 module
217         = moduledecl? [imports]:import* [extern_bodies]:extern_code_body* [classdefs]:topdef* implicit_main_class {-> New module(moduledecl, [imports.import], [extern_bodies.extern_code_block], [classdefs.classdef,implicit_main_class.classdef])};
218
219 moduledecl
220         = [doc]:no redef visibility kwmodule no module_name annotation_withend [n2]:n1 {-> New moduledecl(doc.doc, redef.kwredef, visibility, kwmodule, module_name, annotation_withend.annotations)};
221
222 import
223         = {std} [doc]:no redef visibility kwimport no module_name annotation_withend [n2]:n1 {-> New import.std(visibility, kwimport, module_name, annotation_withend.annotations)}
224         | {no} [doc]:no redef visibility kwimport no kwend [n2]:n1 {-> New import.no(visibility, kwimport, kwend)}
225         ;
226
227 topdef {-> classdef}
228         = {classdef} classdef {-> classdef}
229         | propdef_toplevel n1 {-> New classdef.top([propdef_toplevel.propdef])}
230         ;
231
232 implicit_main_class {-> classdef?}
233         = implicit_main_meth {-> New classdef.main([implicit_main_meth.propdef])}
234         | {null} n? {-> Null}
235         ;
236 implicit_main_meth {-> propdef}
237         = [doc]:no stmts {-> New propdef.main_meth(Null, stmts.expr)}
238         | {n} [doc]:no stmtsn {-> New propdef.main_meth(Null, stmtsn.expr)}
239         ;
240
241 /* CLASSES *******************************************************************/
242 classdef
243         = [doc]:no redef visibility classkind no qclassid formaldefs extern_code_block? propdefs kwend {-> New classdef.std(doc.doc, redef.kwredef, visibility, classkind, qclassid.classid, [formaldefs.formaldef], extern_code_block, [propdefs.propdef], kwend)};
244 redef {-> kwredef?}
245         = kwredef? {-> kwredef};
246 classkind
247         = {concrete} kwclass
248         | {abstract} kwabstract kwclass
249         | {interface} kwinterface
250         | {enum} kwenum
251         | {extern} kwextern kwclass
252         ;
253
254 formaldefs {-> formaldef*}
255         = obra no formaldef formaldefs_tail* [n2]:no cbra {-> [formaldef, formaldefs_tail.formaldef]}
256         | {null} {-> []}
257         ;
258 formaldefs_tail {-> formaldef}
259         = comma no formaldef {-> formaldef};
260 formaldef
261         = classid annotations? typing_o {-> New formaldef(classid, typing_o.type, annotations)};
262
263 superclass {-> propdef}
264         = {super} [doc]:no redef visibility kwsuper [n2]:no type annotation_withend {-> New propdef.super(doc.doc, redef.kwredef, visibility, kwsuper, type, annotation_withend.annotations)}
265         ;
266
267 propdefs {-> propdef*}
268         = propdefn+ no {-> [propdefn.propdef]}
269         | {super} superclass {-> [superclass.propdef]}
270         | {empty} no {-> []}
271         ;
272 propdefn {-> propdef}
273         = propdef n1 {-> propdef.propdef}
274         ;
275 propdef~toplevel {-> propdef}
276         = {meth} [doc]:no redef visibility kwmeth qmethid signature annotation_noend? kwdo stmtso kwend_o {-> New propdef.meth(doc.doc, redef.kwredef, visibility, kwmeth, Null, Null, qmethid.methid, signature, annotation_noend.annotations, Null, Null, stmtso.expr)}
277         | {nobody} [doc]:no redef visibility kwmeth qmethid signature annotation_withend_nonull {-> New propdef.meth(doc.doc, redef.kwredef, visibility, kwmeth, Null, Null, qmethid.methid, signature.signature, annotation_withend_nonull.annotations, Null, Null, Null)}
278 !toplevel| {intern_new} [doc]:no redef visibility kwnew qmethid? signature annotation_withend_nonull {-> New propdef.meth(doc.doc, redef.kwredef, visibility, Null, Null, kwnew, qmethid.methid, signature, annotation_withend_nonull.annotations, Null, Null, Null)}
279 !toplevel| {new} [doc]:no redef visibility kwnew qmethid? signature annotation_noend? kwdo stmtso kwend_o {-> New propdef.meth(doc.doc, redef.kwredef, visibility, Null, Null, kwnew, qmethid.methid, signature, annotation_noend.annotations, Null, Null, stmtso.expr)}
280         | {extern_implicit} [doc]:no redef visibility kwmeth qmethid signature annotation_noend? extern_calls extern_code_block {-> New propdef.meth(doc.doc, redef.kwredef, visibility, kwmeth, Null, Null, qmethid.methid, signature.signature, annotation_noend.annotations, extern_calls, extern_code_block, Null)}
281 !toplevel| {var3} [doc]:no redef visibility kwvar id typing_o annotation_withend {-> New propdef.attr(doc.doc, redef.kwredef, visibility, kwvar, id, typing_o.type, Null, annotation_withend.annotations, Null)}
282 !toplevel| {var4} [doc]:no redef visibility kwvar id typing_o assign [n2]:no expr annotation_withend {-> New propdef.attr(doc.doc, redef.kwredef, visibility, kwvar, id, typing_o.type, expr.expr, annotation_withend.annotations, Null)}
283 !toplevel| {var5} [doc]:no redef visibility kwvar id typing_o annotation_noend? kwdo stmtso kwend? {-> New propdef.attr(doc.doc, redef.kwredef, visibility, kwvar, id, typing_o.type, Null, annotation_noend.annotations, stmtso.expr)}
284 !toplevel| {init} [doc]:no redef visibility kwinit qmethid? signature annotation_noend? kwdo stmtso kwend_o {-> New propdef.meth(doc.doc, redef.kwredef, visibility, Null, kwinit, Null, qmethid.methid, signature, annotation_noend.annotations, Null, Null, stmtso.expr)}
285 !toplevel| {type} [doc]:no redef visibility kwtype classid typing annotation_withend {-> New propdef.type(doc.doc, redef.kwredef, visibility, kwtype, classid, typing.type, annotation_withend.annotations)}
286 !toplevel| {extern_init_implicit} [doc]:no redef visibility kwnew qmethid? signature annotation_noend? extern_calls extern_code_block {-> New propdef.meth(doc.doc, redef.kwredef, visibility, Null, Null, kwnew, qmethid.methid, signature, annotation_noend.annotations, extern_calls, extern_code_block, Null)}
287 !toplevel| {annot} line_annotation_forclass {-> line_annotation_forclass.propdef}
288 !toplevel| {super} superclass {-> superclass.propdef}
289         ;
290 annotation_withend~nonull {-> annotations?}
291         = {oneliner} kwis many_annotations {-> many_annotations.annotations}
292         | {more} kwis n1 line_annotations kwend {-> line_annotations.annotations}
293 !nonull | {null} {-> Null}
294         ;
295 annotation_noend {-> annotations}
296         = {oneliner} kwis many_annotations {-> many_annotations.annotations}
297         | {more} kwis n1 line_annotations {-> line_annotations.annotations}
298         ;
299
300 visibility
301         = {public} {-> New visibility.public(Null)}
302         | {public2} kwpublic no {-> New visibility.public(kwpublic)}
303         | {private} kwprivate no {-> New visibility.private(kwprivate)}
304         | {protected} kwprotected no {-> New visibility.protected(kwprotected)}
305         | {intrude} kwintrude no {-> New visibility.intrude(kwintrude)}
306         ;
307
308 methid~noid {-> methid}
309         = {plus} plus {-> New methid.plus(plus)}
310         | {minus} minus {-> New methid.minus(minus)}
311         | {star} star {-> New methid.star(star)}
312         | {starstar} starstar {-> New methid.starstar(starstar)}
313         | {slash} slash {-> New methid.slash(slash)}
314         | {percent} percent {-> New methid.percent(percent)}
315         | {eq} eq {-> New methid.eq(eq)}
316         | {ne} ne {-> New methid.ne(ne)}
317         | {le} le {-> New methid.le(le)}
318         | {ge} ge {-> New methid.ge(ge)}
319         | {lt} lt {-> New methid.lt(lt)}
320         | {gt} gt {-> New methid.gt(gt)}
321         | {ll} ll {-> New methid.ll(ll)}
322         | {gg} gg {-> New methid.gg(gg)}
323         | {bra} obra cbra {-> New methid.bra(obra, cbra)}
324         | {starship} starship {-> New methid.starship(starship)}
325         | {assign} id assign {-> New methid.assign(id, assign)}
326         | {braassign} obra cbra assign {-> New methid.braassign(obra, cbra, assign)}
327 !noid   | {id} id {-> New methid.id(id)}
328         ;
329
330 signature {-> signature}
331         = opar no params cpar typing [no2]:no {-> New signature(opar, [params.param], cpar, typing.type)}
332         | {noret} opar no params cpar [no2]:no {-> New signature(opar, [params.param], cpar, Null)}
333         | {nopar} typing no {-> New signature(Null, [], Null, typing.type)}
334         | {noparnoret} no {-> New signature(Null, [], Null, Null)}
335         ;
336
337 params {-> param*} 
338         = param params_tail* [n2]:no {-> [param, params_tail.param] }
339         | {null} {-> []}
340         ;
341 params_tail {-> param}
342         = comma no param {-> param};
343 param
344         = {untyped} id annotations_o {-> New param(id, Null, Null, annotations_o.annotations)}
345         | id annotations? typing dotdotdot? {-> New param(id, typing.type, dotdotdot, annotations)}
346         ;
347
348 extern_calls {-> extern_calls?}
349         = kwimport no extern_call extern_call_tail* {-> New extern_calls( kwimport, [extern_call, extern_call_tail.extern_call] )}
350         | {null} {-> Null}
351         ;
352 extern_call_tail {-> extern_call}
353         = comma no extern_call {-> extern_call};
354 extern_call {-> extern_call}
355         = {prop} extern_call_prop {-> extern_call_prop.extern_call}
356         | {cast} extern_call_cast {-> extern_call_cast.extern_call}
357         | {super} kwsuper {-> New extern_call.super( kwsuper )}
358         ;
359 extern_call_prop {-> extern_call}
360         = {local} qmethid {-> New extern_call.local_prop( qmethid.methid )}
361         | {full} type dot qmethid {-> New extern_call.full_prop( type, dot, qmethid.methid )}
362         | {init} type {-> New extern_call.init_prop( type )}
363         ;
364 extern_call_cast {-> extern_call}
365         = {as_cast} [from_type]:type dot kwas [n2]:no opar [n3]:no [to_type]:type [n4]:no cpar {-> New extern_call.cast_as(from_type, dot, kwas, to_type)}
366         | {as_cast2}[from_type]:type dot kwas [n2]:no [to_type]:type {-> New extern_call.cast_as(from_type, dot, kwas, to_type)}
367         | {as_nullable} type dot kwas [n2]:no opar [n3]:no kwnullable [n4]:no cpar {-> New extern_call.as_nullable( type, kwas, kwnullable)}
368         | {as_nullable2}type dot kwas [n2]:no kwnullable {-> New extern_call.as_nullable( type, kwas, kwnullable)}
369         | {as_not_nullable} type dot kwas [n2]:no opar [n3]:no kwnot [n4]:no kwnullable [n5]:no cpar {-> New extern_call.as_not_nullable( type, kwas, kwnot, kwnullable)}
370         | {as_not_nullable2}type dot kwas [n2]:no kwnot [n3]:no kwnullable {-> New extern_call.as_not_nullable( type, kwas, kwnot, kwnullable)}
371         ;
372
373 string_o {->string?} = string? {-> string};
374
375 in_language = kwin no string [n1]:no {-> New in_language(kwin, string)};
376 extern_code_block = in_language? extern_code_segment;
377 extern_code_block_o {-> extern_code_block?}
378         = extern_code_block {-> extern_code_block}
379         | {null} {-> Null}
380         ;
381 extern_code_body {-> extern_code_block} = no extern_code_block {-> extern_code_block};
382
383 /* TYPES *********************************************************************/
384 type~nobra~nopar {-> type}
385         = {simple} kwnullable? classid annotations_o~nopar {-> New type(kwnullable, classid, [], annotations_o~nopar.annotations)}
386 !nobra  | {generic} kwnullable? classid obra no types [n2]:no cbra annotations_o~nopar {-> New type(kwnullable, classid, [types.type], annotations_o~nopar.annotations)}
387         ;
388 types {-> type*} 
389         = type types_tail* {-> [type, types_tail.type]};
390 types_tail {-> type}
391         = comma no type {-> type};
392 typing {-> type}
393         = column no type {-> type};
394 typing_o {-> type?}
395         = column no type {-> type}
396         | {null} {-> Null}
397         ;
398
399 /* STATMENTS *****************************************************************/
400 stmtso~withelse~withend {-> expr?}
401         = {block} n stmtsnend {-> stmtsnend.expr}
402         | {emptyblock} n kwend {-> New expr.block([], kwend)}
403         | {emptyoneline} kwend {-> New expr.block([], kwend)}
404 !withend| {oneline} stmt~withelse {-> stmt~withelse.expr}
405         ;
406 stmts {-> expr}
407         = stmt stmts_tail* {-> New expr.block([stmt.expr, stmts_tail.expr], Null)};
408 stmtsn {-> expr}
409         = stmt stmts_tail* n {-> New expr.block([stmt.expr, stmts_tail.expr], Null)};
410 stmtsnend {-> expr}
411         = stmt stmts_tail* n kwend {-> New expr.block([stmt.expr, stmts_tail.expr], kwend)};
412 stmts_tail {-> expr}
413         = n stmt {-> stmt.expr};
414 stmt~withelse~noexpr~nopar {-> expr}
415         = {vardecl} vardecl {-> vardecl.expr}
416         | {assign} assignment~nopar {-> assignment~nopar.expr}
417         | {return} kwreturn expr? {-> New expr.return(kwreturn, expr)}
418         | {break} kwbreak label? {-> New expr.break(kwbreak, label)}
419         | {abort} kwabort {-> New expr.abort(kwabort)}
420         | {continue} kwcontinue label? {-> New expr.continue(kwcontinue, label)}
421         | {do} do~withelse {-> do~withelse.expr}
422 !noexpr | {if} if~withelse {-> if~withelse.expr}
423         | {while} while~withelse {-> while~withelse.expr}
424         | {loop} loop~withelse {-> loop~withelse.expr}
425         | {for} for~withelse {-> for~withelse.expr}
426         | {with} with~withelse {-> with~withelse.expr}
427         | {assert} assert~withelse {-> assert~withelse.expr}
428 !noexpr | {call} recv qid args_nopar {-> New expr.call(recv.expr, qid.id, args_nopar.exprs)}
429 !noexpr | {super} qualified_o kwsuper args_nopar {-> New expr.super(qualified_o.qualified, kwsuper, args_nopar.exprs)}
430 !noexpr | {init} recv qualified? kwinit args_nopar {-> New expr.init(recv.expr, kwinit, args_nopar.exprs)}
431         | {debug_type_is} kwdebug kwtype type column expr {-> New expr.debug_type(kwdebug, kwtype, expr.expr, type) }
432         ;
433
434 label= kwlabel id?;
435
436 vardecl{-> expr}
437         = kwvar id annotations? typing_o {-> New expr.vardecl(kwvar, id, typing_o.type, Null, Null, annotations)}
438         | {assign} kwvar id annotations? typing_o assign no expr {-> New expr.vardecl(kwvar, id, typing_o.type, assign, expr.expr, annotations)}
439         ;
440
441 assignment~nopar {-> expr}
442         = {attr} recv~nopar qualified_o attrid assign expr {-> New expr.attr_assign(recv~nopar.expr, attrid, assign, expr)}
443         | {call} recv~nopar qid args assign expr {-> New expr.call_assign(recv~nopar.expr, qid.id, args.exprs, assign,  expr)}
444         | {bra} expr_atom~nopar braargs assign expr {-> New expr.bra_assign(expr_atom~nopar.expr, braargs.exprs, assign,  expr)}
445         | {attr_re} recv~nopar qualified_o attrid assign_op expr {-> New expr.attr_reassign(recv~nopar.expr, attrid, assign_op,  expr)}
446         | {call_re} recv~nopar qid args assign_op expr {-> New expr.call_reassign(recv~nopar.expr, qid.id, args.exprs, assign_op,  expr)}
447         | {bra_re} expr_atom~nopar braargs assign_op expr {-> New expr.bra_reassign(expr_atom~nopar.expr, braargs.exprs, assign_op,  expr)}
448         ;
449 assign_op
450         = {plus} pluseq
451         | {minus} minuseq
452         | {star} stareq
453         | {slash} slasheq
454         | {percent} percenteq
455         | {starstar} starstareq
456         | {ll} lleq
457         | {gg} ggeq
458         ;
459
460 do~withelse {-> expr}
461         = kwdo stmtso_withend label {-> New expr.do(kwdo, stmtso_withend.expr, label)}
462         | {nolabel} kwdo stmtso~withelse {-> New expr.do(kwdo, stmtso~withelse.expr, Null)}
463         ;
464
465 if~withelse {-> expr}
466         = {onelineelse} kwif no expr [n2]:no kwthen stmt_withelse kwelse stmtso~withelse {-> New expr.if(kwif, expr, stmt_withelse.expr, stmtso~withelse.expr)}
467 !withelse       | {oneline} kwif no expr [n2]:no kwthen stmt {-> New expr.if(kwif, expr, stmt.expr, Null)}
468 !withelse       | {block} kwif no expr [n2]:no kwthen [n3]:n stmtsn elsepartblock {-> New expr.if(kwif, expr, stmtsn.expr, elsepartblock.expr)}
469 !withelse       | {emptyblock} kwif no expr [n2]:no kwthen [n3]:n? elsepartblock {-> New expr.if(kwif, expr, Null, elsepartblock.expr)}
470         ;
471 elsepartblock {-> expr?}
472         = {else} kwelse stmtso {-> stmtso.expr}
473         | {empty} kwend {-> New expr.block([], kwend)}
474         ;
475
476 loop~withelse {-> expr}
477         = kwloop stmtso_withend label {-> New expr.loop(kwloop, stmtso_withend.expr, label)}
478         | {nolabel} kwloop stmtso~withelse {-> New expr.loop(kwloop, stmtso~withelse.expr, Null)}
479         ;
480
481 while~withelse {-> expr}
482         = kwwhile no expr [n2]:no kwdo stmtso_withend label {-> New expr.while(kwwhile, expr, kwdo, stmtso_withend.expr, label)}
483         | {nolabel} kwwhile no expr [n2]:no kwdo stmtso~withelse {-> New expr.while(kwwhile, expr, kwdo, stmtso~withelse.expr, Null)}
484         ;
485
486 for~withelse {-> expr}
487         = kwfor no [ids]:idlist [n2]:no kwin [n3]:no expr [n4]:no kwdo stmtso_withend label {-> New expr.for(kwfor, [ids.id], expr, kwdo, stmtso_withend.expr, label)}
488         | {nolabel} kwfor no [ids]:idlist [n2]:no kwin [n3]:no expr [n4]:no kwdo stmtso~withelse {-> New expr.for(kwfor, [ids.id], expr, kwdo, stmtso~withelse.expr, Null)}
489         ;
490
491 with~withelse {-> expr}
492         = kwwith no withexpr [n4]:no kwdo stmtso_withend label {-> New expr.with(kwwith, withexpr.expr, kwdo, stmtso_withend.expr, label)}
493         | {nolabel} kwwith no withexpr [n4]:no kwdo stmtso~withelse {-> New expr.with(kwwith, withexpr.expr, kwdo, stmtso~withelse.expr, Null)}
494         ;
495
496 withexpr {-> expr}
497         = {assign} id annotations? typing_o assign no expr {-> New expr.vardecl(Null, id, typing_o.type, assign, expr.expr, annotations)}
498         | expr {-> expr}
499         ;
500
501 assert~withelse {-> expr}
502         = {else} kwassert assertid? expr kwelse stmtso~withelse {-> New expr.assert(kwassert, assertid.id, expr, stmtso~withelse.expr)}
503 !withelse| {noelse} kwassert assertid? expr {-> New expr.assert(kwassert, assertid.id, expr, Null)}
504         ;
505 assertid {-> id}
506         = id column {-> id};
507
508 /* EXPRESSIONS ***************************************************************/
509 expr~nopar~nobra {-> expr}
510         = expr_and~nopar~nobra {-> expr_and~nopar~nobra.expr}
511         | {ifexpr} kwif [n1]:no expr [n2]:no kwthen [n3]:no [then]:expr [n4]:no kwelse [n5]:no [else]:expr~nopar~nobra {-> New expr.ifexpr(kwif, expr, kwthen, then, kwelse, else.expr)}
512         ;
513
514 expr_and~nopar~nobra {-> expr}
515         = expr_not~nopar~nobra {-> expr_not~nopar~nobra.expr}
516         | {:or} expr_and~nopar~nobra kwor :no expr_not~nopar~nobra
517         | {:and} expr_and~nopar~nobra kwand :no expr_not~nopar~nobra
518         | {:or_else} expr_and~nopar~nobra kwor kwelse :no expr_not~nopar~nobra
519         | {:implies} expr_and~nopar~nobra kwimplies :no expr_not~nopar~nobra
520         ;
521
522 expr_not~nopar~nobra {-> expr}
523         = expr_eq~nopar~nobra {-> expr_eq~nopar~nobra.expr}
524         | {not} kwnot no expr_not~nopar~nobra {-> New expr.not(kwnot, expr_not~nopar~nobra.expr)}
525         ;
526
527 expr_eq~nopar~nobra {-> expr}
528         = expr_add~nopar~nobra {-> expr_add~nopar~nobra.expr}
529         | {:eq} expr_add~nopar~nobra eq :no [expr2]:expr_add~nopar~nobra
530         | {:ne} expr_add~nopar~nobra ne :no [expr2]:expr_add~nopar~nobra
531         | {:lt} expr_add~nopar~nobra lt :no [expr2]:expr_add~nopar~nobra
532         | {:le} expr_add~nopar~nobra le :no [expr2]:expr_add~nopar~nobra
533         | {:ll} expr_eq~nopar~nobra ll :no [expr2]:expr_add~nopar~nobra
534         | {:gt} expr_add~nopar~nobra gt :no [expr2]:expr_add~nopar~nobra
535         | {:ge} expr_add~nopar~nobra ge :no [expr2]:expr_add~nopar~nobra
536         | {:gg} expr_eq~nopar~nobra gg :no [expr2]:expr_add~nopar~nobra
537         | {:starship} expr_add~nopar~nobra starship :no [expr2]:expr_add~nopar~nobra
538         | {:isa} expr_add~nopar~nobra kwisa :no type~nobra
539         ;
540
541 expr_add~nopar~nobra {-> expr}
542         =  expr_mul~nopar~nobra {-> expr_mul~nopar~nobra.expr}
543         | {:plus} expr_add~nopar~nobra plus :no [expr2]:expr_mul~nopar~nobra
544         | {:minus} expr_add~nopar~nobra minus :no [expr2]:expr_mul~nopar~nobra
545         ;
546
547 expr_mul~nopar~nobra {-> expr}
548         = expr_pow~nopar~nobra {-> expr_pow~nopar~nobra.expr}
549         | {:star} expr_mul~nopar~nobra star :no [expr2]:expr_pow~nopar~nobra
550         | {:slash} expr_mul~nopar~nobra slash :no [expr2]:expr_pow~nopar~nobra
551         | {:percent} expr_mul~nopar~nobra percent :no [expr2]:expr_pow~nopar~nobra
552         ;
553
554 expr_pow~nopar~nobra {-> expr}
555         = expr_minus~nopar~nobra {-> expr_minus~nopar~nobra.expr}
556         | {:starstar} expr_minus~nopar~nobra starstar :no [expr2]:expr_pow~nopar~nobra
557         ;
558
559 expr_minus~nopar~nobra {-> expr}
560         = expr_new~nopar~nobra {-> expr_new~nopar~nobra.expr}
561         | {:uminus} minus expr_minus~nobra
562         | {:uplus} plus expr_minus~nobra
563         | {:once} kwonce :no expr_minus~nobra
564         ;
565
566 expr_new~nopar~nobra {-> expr}
567         = expr_atom~nopar~nobra {-> expr_atom~nopar~nobra.expr}
568         | {new} kwnew no type~nobra_nopar args {-> New expr.new(kwnew, type~nobra_nopar.type, Null, args.exprs)}
569         | {isset_attr} kwisset recv~nopar~nobra qualified_o attrid {-> New expr.isset_attr(kwisset, recv~nopar~nobra.expr, attrid)}
570         ;
571
572 expr_atom~nopar~nobra {-> expr}
573         = expr_single~nopar~nobra {-> expr_single~nopar~nobra.expr}
574         | {attr} recv~nopar~nobra qualified_o attrid {-> New expr.attr(recv~nopar~nobra.expr, attrid)}
575         | {call} recv~nopar~nobra qid args {-> New expr.call(recv~nopar~nobra.expr, qid.id, args.exprs)}
576         | {super} qualified_o kwsuper args {-> New expr.super(qualified_o.qualified, kwsuper, args.exprs)}
577         | {init} recv~nopar~nobra kwinit args {-> New expr.init(recv~nopar~nobra.expr, kwinit, args.exprs)}
578 !nobra  | {bra} expr_atom~nopar braargs {-> New expr.bra(expr_atom~nopar.expr, braargs.exprs)}
579         | {new} kwnew no type~nobra_nopar dot [n2]:no qid args {-> New expr.new(kwnew, type~nobra_nopar.type, qid.id, args.exprs)}
580         | {as_cast} expr_atom~nopar~nobra dot no kwas [n2]:no opar [n3]:no type [n4]:no cpar {-> New expr.as_cast(expr_atom~nopar~nobra.expr, kwas, opar, type, cpar)}
581         | {as_notnull} expr_atom~nopar~nobra dot no kwas [n2]:no opar [n3]:no kwnot [n4]:no kwnull [n5]:no cpar {-> New expr.as_notnull(expr_atom~nopar~nobra.expr, kwas, opar, kwnot, kwnull, cpar)}
582         | {as_notnull2}expr_atom~nopar~nobra dot no kwas [n2]:no kwnot [n4]:no kwnull {-> New expr.as_notnull(expr_atom~nopar~nobra.expr, kwas, Null, kwnot, kwnull, Null)}
583         | {vararg} [expr]:expr_atom~nopar~nobra dotdotdot {-> New expr.vararg(expr.expr, dotdotdot)}
584         ;
585
586 expr_single~nopar~nobra {-> expr}
587         = {self} kwself annotations_o {-> New expr.self(kwself, annotations_o.annotations)}
588         | {true} kwtrue annotations_o {-> New expr.true(kwtrue, annotations_o.annotations)}
589         | {false} kwfalse annotations_o {-> New expr.false(kwfalse, annotations_o.annotations)}
590         | {null} kwnull annotations_o {-> New expr.null(kwnull, annotations_o.annotations)}
591         | {int} number annotations_o {-> New expr.dec_int(number, annotations_o.annotations)}
592         | {hex_int} hex_number annotations_o {-> New expr.hex_int(hex_number, annotations_o.annotations)}
593         | {float} float annotations_o {-> New expr.float(float, annotations_o.annotations)}
594         | {char} char annotations_o {-> New expr.char(char, annotations_o.annotations)}
595         | {string} string annotations_o {-> New expr.string(string, annotations_o.annotations)}
596         | {superstring} superstring  {-> superstring.expr}
597 !nopar  | {par} expr_par {-> expr_par.expr}
598 // !nopar to unambiguise 'foo[5].bar' between '(foo[5]).bar' and 'foo([5].bar),
599 !nobra!nopar    | {range} obra no expr [n2]:no dotdot [n3]:no [expr2]:expr_nobra [n4]:no cbra annotations_o {-> New expr.crange(obra, expr, expr2.expr, cbra, annotations_o.annotations)}
600 !nobra!nopar    | {orange} obra no expr [n2]:no dotdot [n3]:no [expr2]:expr_nobra [n4]:no [cbra]:obra annotations_o {-> New expr.orange(obra, expr, expr2.expr, cbra, annotations_o.annotations)}
601 !nobra!nopar    | {array} obra no array_items typing_o cbra annotations_o {-> New expr.array(obra, [array_items.expr], typing_o.type, cbra, annotations_o.annotations)}
602         ;
603
604 expr_par {-> expr}
605         = {par} opar no any_expr [n2]:no cpar annotations_o {-> New expr.par(opar, any_expr.expr, cpar, annotations_o.annotations)}
606         | {tuple} opar no many_expr [n2]:no cpar annotations_o {-> New expr.par(opar, many_expr.expr, cpar, annotations_o.annotations)}
607         ;
608
609 many_expr {->expr}
610         = any_expr many_expr_tail+ {-> New expr.many([any_expr.expr, many_expr_tail.expr])}
611         ;
612
613 many_expr_tail {->expr}
614         = comma no any_expr {-> any_expr.expr}
615         ;
616
617 array_items {-> expr*}
618         = array_item array_items_tail* {-> [array_item.expr, array_items_tail.expr]}
619         ;
620 array_items_tail {-> expr}
621         = comma no array_item {-> array_item.expr}
622         ;
623 array_item {-> expr}
624         = expr no {-> expr}
625         | {for} kwfor no [ids]:idlist [n2]:no kwin [n3]:no expr [n4]:no kwdo [block]:array_item {-> New expr.for(kwfor, [ids.id], expr, kwdo, block.expr, Null)}
626         | {if} kwif [n1]:no expr [n2]:no kwthen [n3]:no [then]:array_item {-> New expr.if(kwif, expr, then.expr, Null)}
627         ;
628
629 superstring {-> expr} 
630         = superstring_start superstring_middle* superstring_end annotations_o {-> New expr.superstring([superstring_start.expr, superstring_middle.expr, superstring_end.expr], annotations_o.annotations)};
631 superstring_start {-> expr*}
632         = start_string_p no expr [n2]:no {-> [start_string_p.expr, expr]}
633         | {noexpr} start_string_p no {-> [start_string_p.expr]}
634         ;
635 start_string_p {-> expr}
636         = start_string {-> New expr.start_string(start_string)};
637 superstring_middle {-> expr*}
638         = mid_string_p no expr [n2]:no {-> [mid_string_p.expr, expr]}
639         | {noexpr} mid_string_p no {-> [mid_string_p.expr]}
640         ;
641 mid_string_p {-> expr}
642         = mid_string {-> New expr.mid_string(mid_string)};
643 superstring_end {-> expr}
644         = end_string {-> New expr.end_string(end_string)};
645
646 /* ANNOTATIONS *******************************************************************/
647
648 annotations~nopar {-> annotations}
649         = {one} at one_annotation~nopar {-> New annotations(at, Null, [one_annotation~nopar.annotation], Null)}
650         | {many} at opar no annotation_list [n2]:no cpar {-> New annotations(at, opar, [annotation_list.annotation], cpar)}
651         ;
652 annotations_o~nopar {-> annotations?}
653         = annotations~nopar {-> annotations~nopar.annotations}
654         | {null} {-> Null}
655         ;
656
657 one_annotation~nopar {-> annotation}
658         = {alone} redef visibility atid annotations_o~nopar {-> New annotation(Null, redef.kwredef, visibility, atid, Null, [], Null, annotations_o~nopar.annotations)}
659 // !nopar to unambiguise 'new T@foo(bar)' between 'new T@(foo(bar))' and 'new (T@foo)(bar)'
660 !nopar  | {args} redef visibility atid opar no at_args [n2]:no cpar annotations_o~nopar {-> New annotation(Null, redef.kwredef, visibility, atid, opar, [at_args.expr], cpar, annotations_o~nopar.annotations)}
661         ;
662
663 many_annotations {-> annotations}
664         = {many} annotation_list {-> New annotations(Null, Null, [annotation_list.annotation], Null)}
665         ;
666
667 annotation_list {-> annotation*}
668         = {many} one_annotation_list annotations_tail* {-> [one_annotation_list.annotation, annotations_tail.annotation] }
669         ;
670
671 one_annotation_list~nopar {-> annotation}
672         = {alone} redef visibility atid annotations_o~nopar {-> New annotation(Null, redef.kwredef, visibility, atid, Null, [], Null, annotations_o~nopar.annotations)}
673 // !nopar to unambiguise 'new T@foo(bar)' between 'new T@(foo(bar))' and 'new (T@foo)(bar)'
674 !nopar  | {args} redef visibility atid opar no at_args [n2]:no cpar annotations_o~nopar {-> New annotation(Null, redef.kwredef, visibility, atid, opar, [at_args.expr], cpar, annotations_o~nopar.annotations)}
675 !nopar  | {nopar} redef visibility atid at_arg_single {-> New annotation(Null, redef.kwredef, visibility, atid, Null, [at_arg_single.expr], Null, Null)}
676         ;
677 at_arg_single {-> expr}
678 // FIXME: why expr_single but not expr_atom is not clear :(
679         = {expr} [expr]:expr_single_nopar {-> expr.expr}
680         ;
681
682 annotations_tail {-> annotation}
683         = comma no one_annotation_list {-> one_annotation_list.annotation}
684         ;
685
686 line_annotations {-> annotations}
687         = line_annotation+ {-> New annotations(Null, Null, [line_annotation.annotation], Null) }
688         ;
689 line_annotation {-> annotation}
690         = [doc]:no redef visibility atid annotations? n1 {-> New annotation(doc.doc, redef.kwredef, visibility, atid.atid, Null, [], Null, annotations)}
691         | {args} [doc]:no redef visibility atid opar no at_args cpar annotations? n1 {-> New annotation(doc.doc, redef.kwredef, visibility, atid.atid, opar, [at_args.expr], cpar, annotations)}
692         | {nopar} [doc]:no redef visibility atid at_args_nopar n1 {-> New annotation(doc.doc, redef.kwredef, visibility, atid.atid, Null, [at_args_nopar.expr], Null, Null)}
693         ;
694 line_annotation_forclass {-> propdef}
695         = [doc]:no atid_forclass annotations? {-> New propdef.annot(doc.doc, Null, Null, atid_forclass.atid, Null, [], Null, annotations)}
696         | {args} [doc]:no atid_forclass opar no at_args cpar annotations? {-> New propdef.annot(doc.doc, Null, Null, atid_forclass.atid, opar, [at_args.expr], cpar, annotations)}
697         | {nopar} [doc]:no atid_forclass at_args_nopar {-> New propdef.annot(doc.doc, Null, Null, atid_forclass.atid, Null, [at_args_nopar.expr], Null, Null)}
698         ;
699
700 at_args~nopar {-> expr* }
701         = {many} any_expr~nopar at_args_tail* {-> [any_expr~nopar.expr, at_args_tail.expr]}
702         ;
703
704 at_args_tail {-> expr}
705         = comma no any_expr {-> any_expr.expr}
706         ;
707
708 any_expr~nopar {-> expr}
709         = {type} type {-> New expr.type(type)}
710         | {expr} expr~nopar {-> expr~nopar.expr}
711         | {stmt} stmt_noexpr~nopar {-> stmt_noexpr~nopar.expr}
712         | {methid} recv~nopar qmethid_noid {-> New expr.methid(recv~nopar.expr, qmethid_noid.methid)}
713 !nopar  | {at} annotations {-> New expr.at(annotations.annotations)}
714         ;
715
716 atid~forclass {-> atid}
717         = {id}  id {-> New atid.id(id)}
718 !forclass       | {kwextern} kwextern {-> New atid.kwextern(kwextern)}
719 //      | {kwimport} kwimport {-> New atid.kwimport(kwimport)}
720         | {kwabstract} kwabstract {-> New atid.kwabstract(kwabstract)}
721         ;
722
723 /* MISC **********************************************************************/
724
725 recv~nopar~nobra {-> expr}
726         = expr_atom~nopar~nobra dot no {-> expr_atom~nopar~nobra.expr}
727         | {implicit} {-> New expr.implicit_self()}
728         ;
729
730 args {-> exprs}
731         = args_n {-> args_n.exprs}
732         | {empty} {-> New exprs.list([])}
733         ;
734 args_n {-> exprs}
735         = opar no expr_list cpar {-> New exprs.par(opar, [expr_list.expr], cpar) }
736         | {emptypar} opar no cpar {-> New exprs.par(opar, [], cpar) }
737         ;
738 args_nopar {-> exprs}
739         = opar no expr_list cpar {-> New exprs.par(opar, [expr_list.expr], cpar) }
740         | {onearg} expr_nopar {-> New exprs.list([expr_nopar.expr])}
741         | {emptypar} opar no cpar {-> New exprs.par(opar, [], cpar) }
742         | {empty} {-> New exprs.list([])}
743         ;
744 braargs {-> exprs}
745         = obra no expr_list cbra {-> New exprs.bra(obra, [expr_list.expr], cbra)};
746 args_list {-> exprs}
747         = expr_list {-> New exprs.list([expr_list.expr])};
748 expr_list {-> expr*}
749         = expr [n2]:no expr_tail* {-> [expr, expr_tail.expr]};
750 expr_tail {-> expr} 
751         = comma no expr [n2]:no {-> expr};
752 idlist {-> id*}
753         = opar no idlist_nopar [n2]:no cpar {-> [idlist_nopar.id]}
754         | {nopar} idlist_nopar {-> [idlist_nopar.id]}
755         ;
756 idlist_nopar {-> id*}
757         = {single} id {-> [id]}
758         | {more} idlist_nopar comma [n2]:no id {-> [idlist_nopar.id, id]}
759         ;
760
761 module_name {-> module_name}
762         = {mod} modquad* id {-> New module_name(Null, [modquad.id], id)}
763         | {root} quad no modquad* id {-> New module_name(quad, [modquad.id], id)}
764         ;
765
766 qualified 
767         = {cla} modquad* classquad {-> New qualified([modquad.id], classquad.classid)}
768         | {mod} modquad+ {-> New qualified([modquad.id], Null)}
769         ; 
770 qualified_o {-> qualified?}
771         = qualified {-> qualified}
772         | {null} {-> Null}
773         ;
774 qid {-> id}
775         = qualified? id {-> id}
776         ;
777 qclassid {-> classid}
778         = qualified? classid {-> classid}
779         ;
780 qmethid~noid {-> methid}
781         = qualified? methid~noid {-> methid~noid.methid}
782         ;
783 modquad {-> id}
784         = id quad no {-> id};
785 classquad {-> classid} 
786         = classid quad no {-> classid};
787
788 kwend_o {-> kwend?}
789         = kwend? {-> kwend}
790         ;
791
792 n1      = {a} comment | {b} eol;
793 n {-> doc?}
794         = {a} n2? comment+ {-> New doc([comment])}
795         | {b} n2 {-> Null}
796         ;
797 no {-> doc?}
798         = {empty} {-> Null}
799         | n {-> n.doc}
800         ;
801
802 n2
803         = {a} n2? comment+ eol+
804         | {b} eol+
805         ;
806
807 /*****************************************************************************/
808 Abstract Syntax Tree
809 /*****************************************************************************/
810
811 module  = moduledecl? [imports]:import* [extern_code_blocks]:extern_code_block* [classdefs]:classdef*;
812
813 moduledecl
814         = doc? kwredef? visibility kwmodule [name]:module_name annotations?;
815
816 import  = {std} visibility kwimport [name]:module_name annotations?
817         | {no} visibility kwimport kwend
818         ;
819
820 visibility
821         = {public} kwpublic?
822         | {private} kwprivate
823         | {protected} kwprotected
824         | {intrude} kwintrude
825         ;
826
827 classdef= {std} doc? kwredef? visibility classkind [id]:classid? [formaldefs]:formaldef* extern_code_block? [propdefs]:propdef* kwend
828         | {top} [propdefs]:propdef*
829         | {main} [propdefs]:propdef*
830         ;
831 classkind
832         = {concrete} kwclass
833         | {abstract} kwabstract kwclass
834         | {interface} kwinterface
835         | {enum} kwenum
836         | {extern} kwextern kwclass?
837         ;
838 formaldef = [id]:classid type? annotations?;
839
840
841 propdef = {attr} doc? kwredef? visibility kwvar [id2]:id type? expr? annotations? [block]:expr?
842         | {main_meth} kwredef? [block]:expr?
843         | {type} doc? kwredef? visibility kwtype [id]:classid type annotations?
844         | {meth} doc? kwredef? visibility kwmeth? kwinit? kwnew? methid? signature annotations? extern_calls? extern_code_block? [block]:expr?
845         | {super} doc? kwredef? visibility kwsuper type annotations?
846         | {annot} doc? kwredef? visibility? atid opar? [args]:expr* cpar? annotations?
847         ;
848
849 methid
850         = {id} id
851         | {plus} [op]:plus
852         | {minus} [op]:minus
853         | {star} [op]:star
854         | {starstar} [op]:starstar
855         | {slash} [op]:slash
856         | {percent} [op]:percent
857         | {eq} [op]:eq
858         | {ne} [op]:ne
859         | {le} [op]:le
860         | {ge} [op]:ge
861         | {lt} [op]:lt
862         | {gt} [op]:gt
863         | {ll} [op]:ll
864         | {gg} [op]:gg
865         | {starship} [op]:starship
866         | {bra} obra cbra
867         | {assign} id assign
868         | {braassign} obra cbra assign
869         ;
870
871 signature = opar? [params]:param* cpar? type?;
872
873 param   = id type? dotdotdot? annotations?
874         ;
875
876 type    = kwnullable? [id]:classid [types]:type* annotations?;
877
878 label = kwlabel id?;
879
880 expr    = {block} expr* kwend? 
881         | {vardecl} kwvar? id type? assign? expr? annotations?
882         | {return} kwreturn? expr?
883         | {break} kwbreak label?
884         | {abort} kwabort
885         | {continue} kwcontinue? label?
886         | {do} kwdo [block]:expr? label?
887         | {if} kwif expr [then]:expr? [else]:expr? 
888         | {ifexpr} kwif expr kwthen [then]:expr kwelse [else]:expr
889         | {while} kwwhile expr kwdo [block]:expr? label?
890         | {loop} kwloop [block]:expr? label?
891         | {for} kwfor [ids]:id* expr kwdo [block]:expr? label?
892         | {with} kwwith expr kwdo [block]:expr? label?
893         | {assert} kwassert id? expr [else]:expr?
894         | {once} kwonce expr 
895         | {send} expr 
896         | {binop} expr [expr2]:expr 
897         | {or} expr [op]:kwor [expr2]:expr
898         | {and} expr [op]:kwand [expr2]:expr
899         | {or_else} expr [op]:kwor kwelse [expr2]:expr
900         | {implies} expr [op]:kwimplies [expr2]:expr
901         | {not} kwnot expr
902         | {eq} expr [op]:eq [expr2]:expr
903         | {ne} expr [op]:ne [expr2]:expr
904         | {lt} expr [op]:lt [expr2]:expr
905         | {le} expr [op]:le [expr2]:expr
906         | {ll} expr [op]:ll [expr2]:expr
907         | {gt} expr [op]:gt [expr2]:expr
908         | {ge} expr [op]:ge [expr2]:expr
909         | {gg} expr [op]:gg [expr2]:expr
910         | {isa} expr kwisa type
911         | {plus} expr [op]:plus [expr2]:expr
912         | {minus} expr [op]:minus [expr2]:expr
913         | {starship} expr [op]:starship [expr2]:expr
914         | {star} expr [op]:star [expr2]:expr
915         | {starstar} expr [op]:starstar [expr2]:expr
916         | {slash} expr [op]:slash [expr2]:expr
917         | {percent} expr [op]:percent [expr2]:expr
918         | {uminus} [op]:minus expr
919         | {uplus} [op]:plus expr
920         | {new} kwnew type id? [args]:exprs
921         | {attr} expr [id]:attrid 
922         | {attr_assign} expr [id]:attrid assign [value]:expr 
923         | {attr_reassign} expr [id]:attrid assign_op [value]:expr 
924         | {call} expr id [args]:exprs
925         | {call_assign} expr id [args]:exprs assign [value]:expr
926         | {call_reassign} expr id [args]:exprs assign_op [value]:expr 
927         | {super} qualified? kwsuper [args]:exprs
928         | {init} expr kwinit [args]:exprs 
929         | {bra} expr [args]:exprs
930         | {bra_assign} expr [args]:exprs assign [value]:expr 
931         | {bra_reassign} expr [args]:exprs assign_op [value]:expr 
932         | {var} id
933         | {var_assign} id assign [value]:expr 
934         | {var_reassign} id assign_op [value]:expr 
935         | {range} expr [expr2]:expr annotations?
936         | {crange} obra expr [expr2]:expr cbra annotations?
937         | {orange} obra expr [expr2]:expr [cbra]:obra annotations?
938         | {array} obra [exprs]:expr* type? cbra annotations?
939         | {self} kwself annotations?
940         | {implicit_self} 
941         | {true} kwtrue annotations?
942         | {false} kwfalse annotations?
943         | {null} kwnull annotations?
944         | {dec_int} number annotations?
945         | {hex_int} hex_number annotations?
946         | {float} float annotations?
947         | {char} char annotations?
948         | {string} string annotations?
949         | {start_string} [string]:start_string 
950         | {mid_string} [string]:mid_string 
951         | {end_string} [string]:end_string 
952         | {superstring} [exprs]:expr* annotations?
953         | {par} opar expr cpar annotations?
954         | {as_cast} expr kwas opar? type cpar?
955         | {as_notnull} expr kwas opar? kwnot kwnull cpar?
956         | {isset_attr} kwisset expr [id]:attrid
957         | {debug_type} kwdebug kwtype expr type
958         | {vararg} expr dotdotdot
959         | {type} type
960         | {methid} expr [id]:methid
961         | {at} annotations
962         | {many} [exprs]:expr*
963         ;
964 exprs
965         = {list} [exprs]:expr*
966         | {par} opar [exprs]:expr* cpar
967         | {bra} obra [exprs]:expr* cbra
968         ;
969 assign_op
970         = {plus} [op]:pluseq
971         | {minus}[op]:minuseq
972         | {star} [op]:stareq
973         | {slash} [op]:slasheq
974         | {percent} [op]:percenteq
975         | {starstar} [op]:starstareq
976         | {ll} [op]:lleq
977         | {gg} [op]:ggeq
978         ;
979
980 module_name = quad? [path]:id* id;
981 extern_calls = kwimport [extern_calls]:extern_call*
982         ;
983 extern_call =
984         | {super} kwsuper
985         | {local_prop} methid
986         | {full_prop} type dot? methid
987         | {init_prop} type
988         | {cast_as} [from_type]:type dot? kwas [to_type]:type
989         | {as_nullable} type kwas kwnullable
990         | {as_not_nullable} type kwas kwnot kwnullable
991         ;
992 in_language = kwin string;
993 extern_code_block = in_language? extern_code_segment;
994
995 qualified = id* classid? ;
996
997 doc = comment+;
998
999 annotations = at? opar? [items]:annotation* cpar?;
1000
1001 annotation = doc? kwredef? visibility? atid opar? [args]:expr* cpar? annotations?;
1002
1003 atid = {id} id | {kwextern} [id]:kwextern | {kwabstract} [id]:kwabstract | {kwimport} [id]:kwimport;
1004
1005 /*****************************************************************************/
1006