2 /* This file is part of NIT ( http://www.nitlanguage.org ).
4 * Copyright 2008-2009 Jean Privat <jean@pryen.org>
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
10 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 /* This grammar defines the NIT language. */
20 Package org.nitlanguage.gen;
22 /*****************************************************************************/
24 /*****************************************************************************/
27 lowercase = ['a' .. 'z'];
28 uppercase = ['A' .. 'Z'];
30 letter = lowercase | uppercase | digit | '_';
35 any = [all - [cr + lf]];
36 eol_helper = cr lf | cr | lf; // This takes care of different platforms
38 // characers inside strings and super-strings (atomaton powaa)
40 = [any - [['"' + '{'] + '\']]
50 sstr_body = sstr_char*;
52 long_str_char = str_char | cr | lf;
57 | '"' '"' long_str_char
59 | '{' '{' long_str_char
62 long_str_body = long_str_part*;
64 long_sstr_char = sstr_char | cr | lf;
68 | ''' ''' long_sstr_char
71 long_sstr_body = long_sstr_part*;
78 extern_code_body = extern_code_char*;
80 /*****************************************************************************/
82 /*****************************************************************************/
86 /*****************************************************************************/
88 /*****************************************************************************/
93 comment = '#' any* eol_helper?;
95 kwmodule = 'package'|'module';
98 kwabstract = 'abstract';
99 kwinterface = 'interface';
100 kwenum = 'universal'|'enum';
108 kwreadable = 'readable';
109 kwwritable = 'writable';
113 kwprotected = 'protected';
114 kwprivate = 'private';
115 kwintrude = 'intrude';
126 kwimplies = 'implies';
128 kwcontinue = 'continue';
141 kwnullable = 'nullable';
144 kwdebug = '__debug__';
176 classid = uppercase letter*;
177 id = lowercase letter*;
178 attrid = '_' lowercase letter*;
181 float = digit* '.' digit+;
182 string = '"' str_body '"' | '"' '"' '"' long_str_body '"' '"' '"' | ''' ''' ''' long_sstr_body ''' ''' ''';
183 start_string = '"' str_body '{' | '"' '"' '"' long_str_body '{' '{' '{';
184 mid_string = '}' str_body '{' | '}' '}' '}' long_str_body '{' '{' '{';
185 end_string = '}' str_body '"' | '}' '}' '}' long_str_body '"' '"' '"';
186 char = (''' [[any - '''] - '\'] ''') | (''' '\' any ''');
187 bad_string = ('"'|'}') str_body | '"' '"' '"' long_str_body | ''' ''' ''' long_sstr_body;
188 bad_char = ''' '\'? any;
190 extern_code_segment = '`' '{' extern_code_body '`' '}';
192 /*****************************************************************************/
194 /*****************************************************************************/
198 /*****************************************************************************/
200 /*****************************************************************************/
202 /* MODULES *******************************************************************/
204 = moduledecl? [imports]:import* [extern_bodies]:extern_code_body* [classdefs]:classdef* implicit_top_class? implicit_main_class? {-> New module(moduledecl, [imports.import], [extern_bodies.extern_code_block], [classdefs.classdef,implicit_top_class.classdef,implicit_main_class.classdef])};
207 = [doc]:no kwmodule no module_name annotation_withend? [n2]:n1 {-> New moduledecl(doc.doc, kwmodule, module_name, annotation_withend.annotations)};
210 = {std} [doc]:no visibility kwimport no module_name annotation_withend? [n2]:n1 {-> New import.std(visibility, kwimport, module_name, annotation_withend.annotations)}
211 | {no} [doc]:no visibility kwimport no kwend [n2]:n1 {-> New import.no(visibility, kwimport, kwend)}
214 implicit_top_class {-> classdef}
215 = propdefs_toplevel+ {-> New classdef.top([propdefs_toplevel.propdef])};
217 implicit_main_class {-> classdef?}
218 = implicit_main_meth {-> New classdef.main([implicit_main_meth.propdef])}
221 implicit_main_meth {-> propdef}
222 = [doc]:no stmts {-> New propdef.main_meth(Null, stmts.expr)}
223 | {n} [doc]:no stmtsn {-> New propdef.main_meth(Null, stmtsn.expr)}
226 /* CLASSES *******************************************************************/
228 = [doc]:no redef visibility classkind no qualified? classid formaldefs? line_annotations_forclass? extern_code_block? [superclasses]:superclass* propdefs* [n2]:no kwend {-> New classdef.std(doc.doc, redef.kwredef, visibility, classkind, classid, [formaldefs.formaldef], line_annotations_forclass.annotations, extern_code_block, [superclasses.superclass], [propdefs.propdef], kwend)};
230 = kwredef? {-> kwredef};
233 | {abstract} kwabstract kwclass
234 | {interface} kwinterface
236 | {extern} kwextern kwclass?
239 formaldefs {-> formaldef*}
240 = obra no formaldef formaldefs_tail* [n2]:no cbra {-> [formaldef, formaldefs_tail.formaldef]};
241 formaldefs_tail {-> formaldef}
242 = comma no formaldef {-> formaldef};
244 = classid annotations? typing? {-> New formaldef(classid, typing.type, annotations)};
246 superclass {-> superclass}
247 = {super} no kwsuper [n2]:no type annotation_withend? {-> New superclass(kwsuper, type, annotation_withend.annotations)}
250 propdefs~toplevel {-> propdef}
251 = propdef~toplevel n1 {-> propdef~toplevel.propdef}
253 propdef~toplevel {-> propdef}
254 = {meth} [doc]:no redef visibility kwmeth methid signature annotation_noend? kwdo stmtso kwend? {-> New propdef.concrete_meth(doc.doc, redef.kwredef, visibility, kwmeth, methid, signature, annotation_noend.annotations, stmtso.expr)}
255 | {assign_return} [doc]:no redef visibility kwmeth methid signature_withret assign no assign_return {-> New propdef.concrete_meth(doc.doc, redef.kwredef, visibility, kwmeth, methid, signature_withret.signature, Null, assign_return.expr)}
256 | {nobody} [doc]:no redef visibility kwmeth methid signature annotation_withend {-> New propdef.deferred_meth(doc.doc, redef.kwredef, visibility, kwmeth, methid, signature.signature, annotation_withend.annotations)}
257 !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)}
258 !toplevel| {intern} [doc]:no redef visibility kwmeth methid signature kwis kwintern {-> New propdef.intern_meth(doc.doc, redef.kwredef, visibility, kwmeth, methid, signature.signature)}
259 | {extern} [doc]:no redef visibility kwmeth methid signature kwis kwextern string? extern_calls? extern_code_block? {-> New propdef.extern_meth(doc.doc, redef.kwredef, visibility, kwmeth, methid, signature.signature, string, extern_calls, extern_code_block)}
260 | {extern_implicit} [doc]:no redef visibility kwmeth methid signature extern_calls? extern_code_block {-> New propdef.extern_meth(doc.doc, redef.kwredef, visibility, kwmeth, methid, signature.signature, Null, extern_calls, extern_code_block)}
261 !toplevel| {var} [doc]:no readable? writable? redef visibility kwvar attrid typing? {-> New propdef.attr(doc.doc, readable.able, writable.able, redef.kwredef, visibility, kwvar, attrid, Null, typing.type, Null, Null)}
262 !toplevel| {var2} [doc]:no readable? writable? redef visibility kwvar attrid typing? assign [n2]:no expr {-> New propdef.attr(doc.doc, readable.able, writable.able, redef.kwredef, visibility, kwvar, attrid, Null, typing.type, Null, expr)}
263 !toplevel| {var3} [doc]:no redef visibility kwvar id typing? writable2? annotation_withend? {-> New propdef.attr(doc.doc, Null, writable2.able, redef.kwredef, visibility, kwvar, Null, id, typing.type, annotation_withend.annotations, Null)}
264 !toplevel| {var4} [doc]:no redef visibility kwvar id typing? writable2? assign [n2]:no expr_nois annotation_withend? {-> New propdef.attr(doc.doc, Null, writable2.able, redef.kwredef, visibility, kwvar, Null, id, typing.type, annotation_withend.annotations, expr_nois.expr)}
265 !toplevel| {init} [doc]:no redef visibility kwinit methid? signature annotation_noend? kwdo stmtso kwend? {-> New propdef.concrete_init(doc.doc, redef.kwredef, visibility, kwinit, methid, signature, annotation_noend.annotations, stmtso.expr)}
266 !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)}
267 !toplevel| {extern_init} [doc]:no redef visibility kwnew methid? signature kwis kwextern string? extern_calls? extern_code_block? {-> New propdef.extern_init(doc.doc, redef.kwredef, visibility, kwnew, methid, signature, string, extern_calls, extern_code_block)}
268 !toplevel| {extern_init_implicit} [doc]:no redef visibility kwnew methid? signature string? extern_calls? extern_code_block {-> New propdef.extern_init(doc.doc, redef.kwredef, visibility, kwnew, methid, signature, string, extern_calls, extern_code_block)}
270 annotation_withend {-> annotations}
271 = {oneliner} kwis many_annotations {-> many_annotations.annotations}
272 | {more} kwis n1 line_annotations kwend {-> line_annotations.annotations}
274 annotation_noend {-> annotations}
275 = {oneliner} kwis many_annotations {-> many_annotations.annotations}
276 | {more} kwis n1 line_annotations {-> line_annotations.annotations}
279 = redef kwreadable {-> New able.read(redef.kwredef, kwreadable)}
282 = redef kwwritable {-> New able.write(redef.kwredef, Null, kwwritable)}
285 = redef visibility kwwritable {-> New able.write(redef.kwredef, visibility, kwwritable)}
289 = {public} {-> New visibility.public()}
290 | {private} kwprivate no {-> New visibility.private(kwprivate)}
291 | {protected} kwprotected no {-> New visibility.protected(kwprotected)}
292 | {intrude} kwintrude no {-> New visibility.intrude(kwintrude)}
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)}
316 signature~withret {-> signature}
317 = opar no params? cpar typing [no2]:no closure_decls? {-> New signature(opar, [params.param], cpar, typing.type, [closure_decls.closure_decl])}
318 !withret| {noret} opar no params? cpar [no2]:no closure_decls? {-> New signature(opar, [params.param], cpar, Null, [closure_decls.closure_decl])}
319 | {nopar} typing no closure_decls? {-> New signature(Null, [], Null, typing.type, [closure_decls.closure_decl])}
320 !withret| {noparnoret} no closure_decls? {-> New signature(Null, [], Null, Null, [closure_decls.closure_decl])}
323 signature_noclosures {-> signature}
324 = opar no params? cpar typing? {-> New signature(opar, [params.param], cpar, typing.type, [])}
325 | {nopar} typing? {-> New signature(Null, [], Null, typing.type, [])}
329 = param params_tail* [n2]:no {-> [param, params_tail.param] }
331 params_tail {-> param}
332 = comma no param {-> param};
334 = {untyped} id annotations? {-> New param(id, Null, Null, annotations)}
335 | id annotations? typing dotdotdot? {-> New param(id, typing.type, dotdotdot, annotations)}
338 closure_decls {->closure_decl*}
339 = closure_decl+ {-> [closure_decl]};
341 = kwbreak? bang id signature_noclosures n {-> New closure_decl(kwbreak, bang, id, signature_noclosures.signature, Null)}
342 | {optionnal} kwbreak? bang id signature_noclosures kwdo stmtso n {-> New closure_decl(kwbreak, bang, id, signature_noclosures.signature, stmtso.expr)}
343 | {assign} kwbreak? bang id signature_noclosures assign no assign_continue n {-> New closure_decl(kwbreak, bang, id, signature_noclosures.signature, assign_continue.expr)}
346 assign_return{-> expr}
347 = expr_final {-> New expr.return(Null, expr_final.expr)}
350 extern_calls {-> extern_calls}
351 = kwimport no extern_call extern_call_tail* {-> New extern_calls( kwimport, [extern_call, extern_call_tail.extern_call] )}
353 extern_call_tail {-> extern_call}
354 = comma no extern_call {-> extern_call};
355 extern_call {-> extern_call}
356 = {prop} extern_call_prop {-> extern_call_prop.extern_call}
357 | {cast} extern_call_cast {-> extern_call_cast.extern_call}
358 | {super} kwsuper {-> New extern_call.super( kwsuper )}
360 extern_call_prop {-> extern_call}
361 = {local} methid {-> New extern_call.local_prop( methid )}
362 | {full} classid quad methid {-> New extern_call.full_prop( classid, quad, methid )}
363 | {init} classid {-> New extern_call.init_prop( classid )}
365 extern_call_cast {-> extern_call}
366 = {as_cast} [from_type]:type kwas [n2]:no opar [n3]:no [to_type]:type [n4]:no cpar {-> New extern_call.cast_as(from_type, kwas, to_type)}
367 | {as_nullable} type kwas [n2]:no kwnullable {-> New extern_call.as_nullable( type, kwas, kwnullable)}
368 | {as_not_nullable} type kwas [n2]:no kwnot [n3]:no kwnullable {-> New extern_call.as_not_nullable( type, kwas, kwnot, kwnullable)}
371 in_language = kwin string;
372 extern_code_block = in_language? extern_code_segment;
373 extern_code_body {-> extern_code_block} = no extern_code_block {-> extern_code_block};
375 /* TYPES *********************************************************************/
376 type~nobra~nopar {-> type}
377 = {simple} kwnullable? classid annotations~nopar? {-> New type(kwnullable, classid, [], annotations~nopar.annotations)}
378 !nobra | {generic} kwnullable? classid obra no types [n2]:no cbra annotations~nopar? {-> New type(kwnullable, classid, [types.type], annotations~nopar.annotations)}
381 = type types_tail* {-> [type, types_tail.type]};
383 = comma no type {-> type};
385 = column no type {-> type};
387 /* STATMENTS *****************************************************************/
388 stmtso~withelse~withend {-> expr?}
389 = {block} n stmtsnend {-> stmtsnend.expr}
390 | {emptyblock} n kwend {-> New expr.block([], kwend)}
391 | {emptyoneline} kwend {-> New expr.block([], kwend)}
392 !withend| {oneline} stmt~withelse {-> stmt~withelse.expr}
395 = stmt stmts_tail* {-> New expr.block([stmt.expr, stmts_tail.expr], Null)};
397 = stmt stmts_tail* n {-> New expr.block([stmt.expr, stmts_tail.expr], Null)};
399 = stmt stmts_tail* n kwend {-> New expr.block([stmt.expr, stmts_tail.expr], kwend)};
401 = n stmt {-> stmt.expr};
402 stmt~withelse~noexpr~nopar {-> expr}
403 = {vardecl} vardecl~withelse {-> vardecl~withelse.expr}
404 | {assign} assignment~withelse~nopar {-> assignment~withelse~nopar.expr}
405 | {return} kwreturn expr_final~withelse? {-> New expr.return(kwreturn, expr_final~withelse.expr)}
406 | {break} kwbreak label? expr_final~withelse? {-> New expr.break(kwbreak, label, expr_final~withelse.expr)}
407 | {abort} kwabort {-> New expr.abort(kwabort)}
408 | {continue} kwcontinue label? expr_final~withelse? {-> New expr.continue(kwcontinue, label, expr_final~withelse.expr)}
409 | {do} do~withelse {-> do~withelse.expr}
410 !noexpr | {if} if~withelse {-> if~withelse.expr}
411 | {while} while~withelse {-> while~withelse.expr}
412 | {loop} loop~withelse {-> loop~withelse.expr}
413 | {for} for~withelse {-> for~withelse.expr}
414 | {assert} assert~withelse {-> assert~withelse.expr}
415 !noexpr | {call} recv qualified? id args_nopar closure_defs~withelse? {-> New expr.call(recv.expr, id, args_nopar.exprs, [closure_defs~withelse.closure_def])}
416 !noexpr | {super} qualified? kwsuper args_nopar {-> New expr.super(qualified, kwsuper, args_nopar.exprs)}
417 !noexpr | {init} recv qualified? kwinit args_nopar {-> New expr.init(recv.expr, kwinit, args_nopar.exprs)}
418 | {debug_type_is} kwdebug kwtype type column expr_final~withelse {-> New expr.debug_type(kwdebug, kwtype, expr_final~withelse.expr, type) }
423 closure_defs~withelse {-> closure_def*}
424 = {one} closure_def_last~withelse {-> [closure_def_last~withelse.closure_def]}
425 | closure_def closure_defs~withelse {-> [closure_def, closure_defs~withelse.closure_def]}
428 closure_def_last~withelse {-> closure_def}
429 = bang [id]:closure_id idlist? kwdo stmtso_withend label {-> New closure_def(bang, id, [idlist.id], kwdo, stmtso_withend.expr, label)}
430 | {nolabel} bang [id]:closure_id idlist? kwdo stmtso~withelse {-> New closure_def(bang, id, [idlist.id], kwdo, stmtso~withelse.expr, Null)}
431 | {assign} bang [id]:closure_id idlist? assign no assign_continue~withelse {-> New closure_def(bang, id, [idlist.id], Null, assign_continue~withelse.expr, Null)}
434 closure_def {-> closure_def}
435 = bang [id]:closure_id idlist? kwdo n stmtsn {-> New closure_def(bang, id, [idlist.id], kwdo, stmtsn.expr, Null)}
436 | {empty} bang [id]:closure_id idlist? kwdo n {-> New closure_def(bang, id, [idlist.id], kwdo, Null, Null)}
443 assign_continue~withelse{-> expr}
444 = expr_final~withelse {-> New expr.continue(Null, Null, expr_final~withelse.expr)}
447 vardecl~withelse{-> expr}
448 = kwvar id annotations? typing? {-> New expr.vardecl(kwvar, id, typing.type, Null, Null, annotations)}
449 | {assign} kwvar id annotations? typing? assign no expr_final~withelse {-> New expr.vardecl(kwvar, id, typing.type, assign, expr_final~withelse.expr, annotations)}
452 assignment~withelse~nopar {-> expr}
453 = {attr} recv~nopar qualified? attrid assign expr_final~withelse {-> New expr.attr_assign(recv~nopar.expr, attrid, assign, expr_final~withelse.expr)}
454 | {call} recv~nopar qualified? id args assign expr_final~withelse {-> New expr.call_assign(recv~nopar.expr, id, args.exprs, assign, expr_final~withelse.expr)}
455 | {bra} expr_atom~nopar braargs assign expr_final~withelse {-> New expr.bra_assign(expr_atom~nopar.expr, braargs.exprs, assign, expr_final~withelse.expr)}
456 | {attr_re} recv~nopar qualified? attrid assign_op expr_final~withelse {-> New expr.attr_reassign(recv~nopar.expr, attrid, assign_op, expr_final~withelse.expr)}
457 | {call_re} recv~nopar qualified? id args assign_op expr_final~withelse {-> New expr.call_reassign(recv~nopar.expr, id, args.exprs, assign_op, expr_final~withelse.expr)}
458 | {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)}
465 do~withelse {-> expr}
466 = kwdo stmtso_withend label {-> New expr.do(kwdo, stmtso_withend.expr, label)}
467 | {nolabel} kwdo stmtso~withelse {-> New expr.do(kwdo, stmtso~withelse.expr, Null)}
470 if~withelse {-> expr}
471 = {onelineelse} kwif no expr [n2]:no kwthen stmt_withelse kwelse stmtso~withelse {-> New expr.if(kwif, expr, stmt_withelse.expr, stmtso~withelse.expr)}
472 !withelse | {oneline} kwif no expr [n2]:no kwthen stmt {-> New expr.if(kwif, expr, stmt.expr, Null)}
473 !withelse | {block} kwif no expr [n2]:no kwthen [n3]:n stmtsn elsepartblock {-> New expr.if(kwif, expr, stmtsn.expr, elsepartblock.expr)}
474 !withelse | {emptyblock} kwif no expr [n2]:no kwthen [n3]:n? elsepartblock {-> New expr.if(kwif, expr, Null, elsepartblock.expr)}
476 elsepartblock {-> expr?}
477 = {else} kwelse stmtso {-> stmtso.expr}
478 | {empty} kwend {-> New expr.block([], kwend)}
481 loop~withelse {-> expr}
482 = kwloop stmtso_withend label {-> New expr.loop(kwloop, stmtso_withend.expr, label)}
483 | {nolabel} kwloop stmtso~withelse {-> New expr.loop(kwloop, stmtso~withelse.expr, Null)}
486 while~withelse {-> expr}
487 = kwwhile no expr [n2]:no kwdo stmtso_withend label {-> New expr.while(kwwhile, expr, kwdo, stmtso_withend.expr, label)}
488 | {nolabel} kwwhile no expr [n2]:no kwdo stmtso~withelse {-> New expr.while(kwwhile, expr, kwdo, stmtso~withelse.expr, Null)}
491 for~withelse {-> expr}
492 = 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)}
493 | {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)}
496 assert~withelse {-> expr}
497 = {else} kwassert assertid? expr_final_withelse kwelse stmtso~withelse {-> New expr.assert(kwassert, assertid.id, expr_final_withelse.expr, stmtso~withelse.expr)}
498 !withelse| {noelse} kwassert assertid? expr_final {-> New expr.assert(kwassert, assertid.id, expr_final.expr, Null)}
503 /* EXPRESSIONS ***************************************************************/
504 expr_final~nopar~withelse~nobra {-> expr}
505 = expr~nopar~nobra {-> expr~nopar~nobra.expr}
506 | {closure_call} recv~nobra qualified? id args closure_defs~withelse {-> New expr.call(recv~nobra.expr, id, args.exprs, [closure_defs~withelse.closure_def])}
507 !nobra!nopar | {closure_bra} expr_atom braargs closure_defs~withelse {-> New expr.bra(expr_atom.expr, braargs.exprs, [closure_defs~withelse.closure_def])}
510 expr~nopar~nobra~nois {-> expr}
511 = expr_and~nopar~nobra~nois {-> expr_and~nopar~nobra~nois.expr}
512 | {ifexpr} kwif [n1]:no expr [n2]:no kwthen [n3]:no [then]:expr [n4]:no kwelse [n5]:no [else]:expr~nopar~nobra~nois {-> New expr.ifexpr(kwif, expr, kwthen, then, kwelse, else.expr)}
515 expr_and~nopar~nobra~nois {-> expr}
516 = expr_not~nopar~nobra~nois {-> expr_not~nopar~nobra~nois.expr}
517 | {:or} expr_and~nopar~nobra~nois :kwor :no expr_not~nopar~nobra~nois
518 | {:and} expr_and~nopar~nobra~nois :kwand :no expr_not~nopar~nobra~nois
519 | {:or_else} expr_and~nopar~nobra~nois :kwor :kwelse :no expr_not~nopar~nobra~nois
520 | {:implies} expr_and~nopar~nobra~nois :kwimplies :no expr_not~nopar~nobra~nois
523 expr_not~nopar~nobra~nois {-> expr}
524 = expr_eq~nopar~nobra~nois {-> expr_eq~nopar~nobra~nois.expr}
525 | {not} kwnot no expr_not~nopar~nobra~nois {-> New expr.not(kwnot, expr_not~nopar~nobra~nois.expr)}
528 expr_eq~nopar~nobra~nois {-> expr}
529 = expr_add~nopar~nobra {-> expr_add~nopar~nobra.expr}
530 | {:eq} expr_add~nopar~nobra :eq :no [expr2]:expr_add~nopar~nobra
531 !nois | {ee} [expr]:expr_add~nopar~nobra kwis no [expr2]:expr_add~nopar~nobra {-> New expr.ee(expr.expr, expr2.expr)}
532 | {:ne} expr_add~nopar~nobra :ne :no [expr2]:expr_add~nopar~nobra
533 | {:lt} expr_add~nopar~nobra :lt :no [expr2]:expr_add~nopar~nobra
534 | {:le} expr_add~nopar~nobra :le :no [expr2]:expr_add~nopar~nobra
535 | {:ll} expr_eq~nopar~nobra~nois :ll :no [expr2]:expr_add~nopar~nobra
536 | {:gt} expr_add~nopar~nobra :gt :no [expr2]:expr_add~nopar~nobra
537 | {:ge} expr_add~nopar~nobra :ge :no [expr2]:expr_add~nopar~nobra
538 | {:gg} expr_eq~nopar~nobra~nois :gg :no [expr2]:expr_add~nopar~nobra
539 | {:starship} expr_add~nopar~nobra :starship :no [expr2]:expr_add~nopar~nobra
540 | {:isa} expr_add~nopar~nobra :kwisa :no type~nobra
543 expr_add~nopar~nobra {-> expr}
544 = expr_mul~nopar~nobra {-> expr_mul~nopar~nobra.expr}
545 | {:plus} expr_add~nopar~nobra :plus :no [expr2]:expr_mul~nopar~nobra
546 | {:minus} expr_add~nopar~nobra :minus :no [expr2]:expr_mul~nopar~nobra
549 expr_mul~nopar~nobra {-> expr}
550 = expr_minus~nopar~nobra {-> expr_minus~nopar~nobra.expr}
551 | {:star} expr_mul~nopar~nobra :star :no [expr2]:expr_minus~nopar~nobra
552 | {:slash} expr_mul~nopar~nobra :slash :no [expr2]:expr_minus~nopar~nobra
553 | {:percent} expr_mul~nopar~nobra :percent :no [expr2]:expr_minus~nopar~nobra
556 expr_minus~nopar~nobra {-> expr}
557 = expr_new~nopar~nobra {-> expr_new~nopar~nobra.expr}
558 | {:uminus} minus :no expr_minus~nopar~nobra
559 | {:once} kwonce :no expr_minus~nopar~nobra
562 expr_new~nopar~nobra {-> expr}
563 = expr_atom~nopar~nobra {-> expr_atom~nopar~nobra.expr}
564 | {new} kwnew no type~nobra_nopar args {-> New expr.new(kwnew, type~nobra_nopar.type, Null, args.exprs)}
565 | {isset_attr} kwisset recv~nopar~nobra qualified? attrid {-> New expr.isset_attr(kwisset, recv~nopar~nobra.expr, attrid)}
568 expr_atom~nopar~nobra {-> expr}
569 = {attr} recv~nopar~nobra qualified? attrid {-> New expr.attr(recv~nopar~nobra.expr, attrid)}
570 | {call} recv~nopar~nobra qualified? id args {-> New expr.call(recv~nopar~nobra.expr, id, args.exprs, [])}
571 | {super} qualified? kwsuper args {-> New expr.super(qualified, kwsuper, args.exprs)}
572 | {init} recv~nopar~nobra kwinit args {-> New expr.init(recv~nopar~nobra.expr, kwinit, args.exprs)}
573 !nobra | {bra} expr_atom~nopar braargs {-> New expr.bra(expr_atom~nopar.expr, braargs.exprs, [])}
574 | {new} kwnew no type~nobra_nopar dot [n2]:no qualified? id args {-> New expr.new(kwnew, type~nobra_nopar.type, id, args.exprs)}
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? {-> New expr.crange(obra, expr, expr2.expr, cbra, annotations)}
577 !nobra!nopar | {orange} obra no expr [n2]:no dotdot [n3]:no [expr2]:expr_nobra [n4]:no [cbra]:obra annotations? {-> New expr.orange(obra, expr, expr2.expr, cbra, annotations)}
578 !nobra!nopar | {array} braargs annotations? {-> New expr.array(braargs.exprs, annotations)}
579 | {self} kwself annotations? {-> New expr.self(kwself, annotations)}
580 | {true} kwtrue annotations? {-> New expr.true(kwtrue, annotations)}
581 | {false} kwfalse annotations? {-> New expr.false(kwfalse, annotations)}
582 | {null} kwnull annotations? {-> New expr.null(kwnull, annotations)}
583 | {int} number annotations? {-> New expr.int(number, annotations)}
584 | {float} float annotations? {-> New expr.float(float, annotations)}
585 | {char} char annotations? {-> New expr.char(char, annotations)}
586 | {string} string annotations? {-> New expr.string(string, annotations)}
587 | {superstring} superstring {-> superstring.expr}
588 !nopar | {par} opar no expr [n2]:no cpar annotations? {-> New expr.par(opar, expr, cpar, annotations)}
589 | {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)}
590 | {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)}
593 superstring {-> expr}
594 = superstring_start superstring_middle* superstring_end annotations? {-> New expr.superstring([superstring_start.expr, superstring_middle.expr, superstring_end.expr], annotations)};
595 superstring_start {-> expr*}
596 = start_string_p no expr [n2]:no {-> [start_string_p.expr, expr]};
597 start_string_p {-> expr}
598 = start_string {-> New expr.start_string(start_string)};
599 superstring_middle {-> expr*}
600 = mid_string_p no expr [n2]:no {-> [mid_string_p.expr, expr]};
601 mid_string_p {-> expr}
602 = mid_string {-> New expr.mid_string(mid_string)};
603 superstring_end {-> expr}
604 = end_string {-> New expr.end_string(end_string)};
606 /* ANNOTATIONS *******************************************************************/
608 annotations~nopar {-> annotations}
609 = {one} at one_annotation~nopar {-> New annotations(at, Null, [one_annotation~nopar.annotation], Null)}
610 | {many} at opar no annotation_list [n2]:no cpar {-> New annotations(at, opar, [annotation_list.annotation], cpar)}
613 one_annotation~nopar {-> annotation}
614 = {alone} atid annotations~nopar? {-> New annotation(atid, Null, [], Null, annotations~nopar.annotations)}
615 // !nopar to unambiguise 'new T@foo(bar)' between 'new T@(foo(bar))' and 'new (T@foo)(bar)'
616 !nopar | {args} atid opar no at_args [n2]:no cpar annotations~nopar? {-> New annotation(atid, opar, [at_args.at_arg], cpar, annotations~nopar.annotations)}
619 many_annotations {-> annotations}
620 = {many} annotation_list {-> New annotations(Null, Null, [annotation_list.annotation], Null)}
623 annotation_list {-> annotation*}
624 = {many} one_annotation annotations_tail* {-> [one_annotation.annotation, annotations_tail.annotation] }
627 line_annotations~forclass {-> annotations}
628 = line_annotation~forclass+ {-> New annotations(Null, Null, [line_annotation~forclass.annotation], Null) }
630 line_annotation~forclass {-> annotation}
631 = [doc]:no atid~forclass annotations? n1 {-> New annotation(atid~forclass.atid, Null, [], Null, annotations)}
632 | {args} [doc]:no atid~forclass opar no at_args cpar annotations? n1 {-> New annotation(atid~forclass.atid, opar, [at_args.at_arg], cpar, annotations)}
633 | {nopar} [doc]:no atid~forclass at_args_nopar n1 {-> New annotation(atid~forclass.atid, Null, [at_args_nopar.at_arg], Null, Null)}
636 annotations_tail {-> annotation}
637 = comma no one_annotation {-> one_annotation.annotation}
640 at_args~nopar {-> at_arg* }
641 = {many} at_arg~nopar at_args_tail* {-> [at_arg~nopar.at_arg, at_args_tail.at_arg]}
644 at_args_tail {-> at_arg}
645 = comma no at_arg {-> at_arg}
648 at_arg~nopar {-> at_arg}
649 = {type} type {-> New at_arg.type(type)}
650 | {expr} expr~nopar {-> New at_arg.expr(expr~nopar.expr)}
651 | {stmt} stmt_noexpr~nopar {-> New at_arg.expr(stmt_noexpr~nopar.expr)}
652 !nopar | {at} annotations {-> New at_arg.at(annotations.annotations)}
655 atid~forclass {-> atid}
656 = {id} qualified? id {-> New atid.id(id)}
657 //!forclass | {kwextern} qualified? kwextern {-> New atid.kwextern(kwextern)}
658 //!forclass | {kwintern} qualified? kwintern {-> New atid.kwintern(kwintern)}
659 !forclass | {kwreadable} qualified? kwreadable {-> New atid.kwreadable(kwreadable)}
660 !forclass | {kwwritable} qualified? kwwritable {-> New atid.kwwritable(kwwritable)}
661 | {kwimport} qualified? kwimport {-> New atid.kwimport(kwimport)}
664 /* MISC **********************************************************************/
666 recv~nopar~nobra {-> expr}
667 = expr_atom~nopar~nobra dot no {-> expr_atom~nopar~nobra.expr}
668 | {implicit} {-> New expr.implicit_self()}
672 = opar no expr_list cpar {-> New exprs.par(opar, [expr_list.expr], cpar) }
673 | {emptypar} opar no cpar {-> New exprs.par(opar, [], cpar) }
674 | {empty} {-> New exprs.list([])}
676 args_nopar {-> exprs}
677 = opar no expr_list cpar {-> New exprs.par(opar, [expr_list.expr], cpar) }
678 | {onearg} expr_nopar {-> New exprs.list([expr_nopar.expr])}
679 | {emptypar} opar no cpar {-> New exprs.par(opar, [], cpar) }
680 | {empty} {-> New exprs.list([])}
683 = obra no expr_list cbra {-> New exprs.bra(obra, [expr_list.expr], cbra)};
685 = expr [n2]:no expr_tail* {-> [expr, expr_tail.expr]};
687 = comma no expr [n2]:no {-> expr};
689 = opar no idlist_nopar [n2]:no cpar {-> [idlist_nopar.id]}
690 | {nopar} idlist_nopar {-> [idlist_nopar.id]}
692 idlist_nopar {-> id*}
693 = {single} id {-> [id]}
694 | {more} idlist_nopar no comma [n2]:no id {-> [idlist_nopar.id, id]}
697 module_name {-> module_name}
698 = {mod} modquad* id {-> New module_name(Null, [modquad.id], id)}
699 | {root} quad no modquad* id {-> New module_name(quad, [modquad.id], id)}
703 = {cla} modquad* classquad {-> New qualified([modquad.id], classquad.classid)}
704 | {mod} modquad+ {-> New qualified([modquad.id], Null)}
707 = id quad no {-> id};
708 classquad {-> classid}
709 = classid quad no {-> classid};
711 n1 = {a} comment | {b} eol;
713 = {a} n2? comment+ {-> New doc([comment])}
722 = {a} n2? comment+ eol+
726 /*****************************************************************************/
728 /*****************************************************************************/
730 module = moduledecl? [imports]:import* [extern_code_blocks]:extern_code_block* [classdefs]:classdef*;
733 = doc? kwmodule [name]:module_name annotations?;
735 import = {std} visibility kwimport [name]:module_name annotations?
736 | {no} visibility kwimport kwend
741 | {private} kwprivate
742 | {protected} kwprotected
743 | {intrude} kwintrude
746 classdef= {std} doc? kwredef? visibility classkind [id]:classid? [formaldefs]:formaldef* annotations? extern_code_block? [superclasses]:superclass* [propdefs]:propdef* kwend
747 | {top} [propdefs]:propdef*
748 | {main} [propdefs]:propdef*
752 | {abstract} kwabstract kwclass
753 | {interface} kwinterface
755 | {extern} kwextern kwclass?
757 formaldef = [id]:classid type? annotations?;
758 superclass = kwsuper type annotations?;
761 propdef = {attr} doc? [readable]:able? [writable]:able? kwredef? visibility kwvar [id]:attrid? [id2]:id? type? annotations? expr?
762 | {meth} doc? kwredef? visibility methid signature
763 | {deferred_meth} doc? kwredef? visibility kwmeth methid signature annotations?
764 | {intern_meth} doc? kwredef? visibility kwmeth methid signature
765 | {extern_meth} doc? kwredef? visibility kwmeth methid signature [extern]:string? extern_calls? extern_code_block?
766 | {concrete_meth} doc? kwredef? visibility kwmeth methid signature annotations? [block]:expr?
767 | {concrete_init} doc? kwredef? visibility kwinit methid? signature annotations? [block]:expr?
768 //| {concrete_new} doc? kwredef? visibility kwnew methid? signature [block]:expr?
769 | {extern_init} doc? kwredef? visibility kwnew methid? signature [extern]:string? extern_calls? extern_code_block?
770 | {main_meth} kwredef? [block]:expr?
771 | {type} doc? kwredef? visibility kwtype [id]:classid type annotations?
774 able = {read} kwredef? kwreadable
775 | {write} kwredef? visibility? kwwritable
778 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;
780 signature = opar? [params]:param* cpar? type? [closure_decls]:closure_decl*;
782 param = id type? dotdotdot? annotations?
785 closure_decl = kwbreak? bang id signature expr?
788 type = kwnullable? [id]:classid [types]:type* annotations?;
792 expr = {block} expr* kwend?
793 | {vardecl} kwvar id type? assign? expr? annotations?
794 | {return} kwreturn? expr?
795 | {break} kwbreak label? expr?
797 | {continue} kwcontinue? label? expr?
798 | {do} kwdo [block]:expr? label?
799 | {if} kwif expr [then]:expr? [else]:expr?
800 | {ifexpr} kwif expr kwthen [then]:expr kwelse [else]:expr
801 | {while} kwwhile expr kwdo [block]:expr? label?
802 | {loop} kwloop [block]:expr? label?
803 | {for} kwfor [ids]:id* expr kwdo [block]:expr? label?
804 | {assert} kwassert id? expr [else]:expr?
807 | {binop} expr [expr2]:expr
808 | {or} expr [expr2]:expr
809 | {and} expr [expr2]:expr
810 | {or_else} expr [expr2]:expr
811 | {implies} expr [expr2]:expr
813 | {eq} expr [expr2]:expr
814 | {ee} expr [expr2]:expr
815 | {ne} expr [expr2]:expr
816 | {lt} expr [expr2]:expr
817 | {le} expr [expr2]:expr
818 | {ll} expr [expr2]:expr
819 | {gt} expr [expr2]:expr
820 | {ge} expr [expr2]:expr
821 | {gg} expr [expr2]:expr
823 | {plus} expr [expr2]:expr
824 | {minus} expr [expr2]:expr
825 | {starship} expr [expr2]:expr
826 | {star} expr [expr2]:expr
827 | {slash} expr [expr2]:expr
828 | {percent} expr [expr2]:expr
829 | {uminus} minus expr
830 | {new} kwnew type id? [args]:exprs
831 | {attr} expr [id]:attrid
832 | {attr_assign} expr [id]:attrid assign [value]:expr
833 | {attr_reassign} expr [id]:attrid assign_op [value]:expr
834 | {call} expr id [args]:exprs [closure_defs]:closure_def*
835 | {call_assign} expr id [args]:exprs assign [value]:expr
836 | {call_reassign} expr id [args]:exprs assign_op [value]:expr
837 | {super} qualified? kwsuper [args]:exprs
838 | {init} expr kwinit [args]:exprs
839 | {bra} expr [args]:exprs [closure_defs]:closure_def*
840 | {bra_assign} expr [args]:exprs assign [value]:expr
841 | {bra_reassign} expr [args]:exprs assign_op [value]:expr
842 | {closure_call} id [args]:exprs [closure_defs]:closure_def*
844 | {var_assign} id assign [value]:expr
845 | {var_reassign} id assign_op [value]:expr
846 | {range} expr [expr2]:expr annotations?
847 | {crange} obra expr [expr2]:expr cbra annotations?
848 | {orange} obra expr [expr2]:expr [cbra]:obra annotations?
849 | {array} [exprs]:exprs annotations?
850 | {self} kwself annotations?
852 | {true} kwtrue annotations?
853 | {false} kwfalse annotations?
854 | {null} kwnull annotations?
855 | {int} number annotations?
856 | {float} float annotations?
857 | {char} char annotations?
858 | {string} string annotations?
859 | {start_string} [string]:start_string
860 | {mid_string} [string]:mid_string
861 | {end_string} [string]:end_string
862 | {superstring} [exprs]:expr* annotations?
863 | {par} opar expr cpar annotations?
864 | {as_cast} expr kwas opar type cpar
865 | {as_notnull} expr kwas opar kwnot kwnull cpar
866 | {isset_attr} kwisset expr [id]:attrid
867 | {debug_type} kwdebug kwtype expr type
870 = {list} [exprs]:expr*
871 | {par} opar [exprs]:expr* cpar
872 | {bra} obra [exprs]:expr* cbra
880 = bang [id]:closure_id [ids]:id* kwdo? expr? label?
887 module_name = quad? [path]:id* id;
888 extern_calls = kwimport [extern_calls]:extern_call*
892 | {local_prop} methid
893 | {full_prop} classid quad? methid
894 | {init_prop} classid
895 | {cast_as} [from_type]:type kwas [to_type]:type
896 | {as_nullable} type kwas kwnullable
897 | {as_not_nullable} type kwas kwnot kwnullable
899 in_language = kwin string;
900 extern_code_block = in_language? extern_code_segment;
902 qualified = id* classid? ;
906 annotations = at? opar? [items]:annotation* cpar?;
908 annotation = atid opar? [args]:at_arg* cpar? annotations?;
915 atid = {id} id | {kwextern} [id]:kwextern | {kwintern} [id]:kwintern | {kwreadable} [id]:kwreadable | {kwwritable} [id]:kwwritable | {kwimport} [id]:kwimport;
917 /*****************************************************************************/