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