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