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