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