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