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