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