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;
54 // because no substraction in sablecc3, complex long strings are difficult to express
57 ls12 = ls1? (ls2 ls1)* ls2?;
63 long_str_body = long_str_part*;
64 lsend1 = ls2? (ls1 ls2)* '"""' '"'*;
65 lsend2 = ls1? (ls2 ls1)* '{{{' '{'*;
67 long_sstr_char = sstr_char | cr | lf;
71 | ''' ''' long_sstr_char
74 long_sstr_body = long_sstr_part*;
81 extern_code_body = extern_code_char*;
83 /*****************************************************************************/
85 /*****************************************************************************/
89 /*****************************************************************************/
91 /*****************************************************************************/
96 comment = '#' any* eol_helper?;
98 kwpackage = 'package';
102 kwabstract = 'abstract';
103 kwinterface = 'interface';
104 kwenum = 'universal'|'enum';
112 kwreadable = 'readable';
113 kwwritable = 'writable';
117 kwprotected = 'protected';
118 kwprivate = 'private';
119 kwintrude = 'intrude';
130 kwimplies = 'implies';
132 kwcontinue = 'continue';
145 kwnullable = 'nullable';
148 kwdebug = '__debug__';
180 classid = uppercase letter*;
181 id = lowercase letter*;
182 attrid = '_' lowercase letter*;
185 float = digit* '.' digit+;
186 string = '"' str_body '"' | '"' '"' '"' long_str_body lsend1 | ''' ''' ''' long_sstr_body ''' ''' ''';
187 start_string = '"' str_body '{' | '"' '"' '"' long_str_body lsend2;
188 mid_string = '}' str_body '{' | '}' '}' '}' long_str_body lsend2;
189 end_string = '}' str_body '"' | '}' '}' '}' long_str_body lsend1;
190 char = (''' [[any - '''] - '\'] ''') | (''' '\' any ''');
191 bad_string = ('"'|'}') str_body | '"' '"' '"' long_str_body | ''' ''' ''' long_sstr_body;
192 bad_char = ''' '\'? any;
194 extern_code_segment = '`' '{' extern_code_body '`' '}';
196 /*****************************************************************************/
198 /*****************************************************************************/
202 /*****************************************************************************/
204 /*****************************************************************************/
206 /* MODULES *******************************************************************/
208 = 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])};
211 = [doc]:no kwmodule no module_name annotation_withend [n2]:n1 {-> New moduledecl(doc.doc, kwmodule, module_name, annotation_withend.annotations)};
214 = {std} [doc]:no redef visibility kwimport no module_name annotation_withend [n2]:n1 {-> New import.std(visibility, kwimport, module_name, annotation_withend.annotations)}
215 | {no} [doc]:no redef visibility kwimport no kwend [n2]:n1 {-> New import.no(visibility, kwimport, kwend)}
218 implicit_top_class {-> classdef}
219 = propdefs_toplevel+ {-> New classdef.top([propdefs_toplevel.propdef])};
221 implicit_main_class {-> classdef?}
222 = implicit_main_meth {-> New classdef.main([implicit_main_meth.propdef])}
223 | {null} n? {-> Null}
225 implicit_main_meth {-> propdef}
226 = [doc]:no stmts {-> New propdef.main_meth(Null, stmts.expr)}
227 | {n} [doc]:no stmtsn {-> New propdef.main_meth(Null, stmtsn.expr)}
230 /* CLASSES *******************************************************************/
232 = [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)};
234 = kwredef? {-> kwredef};
237 | {abstract} kwabstract kwclass
238 | {interface} kwinterface
240 | {extern} kwextern kwclass?
243 formaldefs {-> formaldef*}
244 = obra no formaldef formaldefs_tail* [n2]:no cbra {-> [formaldef, formaldefs_tail.formaldef]}
247 formaldefs_tail {-> formaldef}
248 = comma no formaldef {-> formaldef};
250 = classid annotations? typing_o {-> New formaldef(classid, typing_o.type, annotations)};
252 superclass {-> superclass}
253 = {super} no kwsuper [n2]:no type annotation_withend {-> New superclass(kwsuper, type, annotation_withend.annotations)}
256 propdefs~toplevel {-> propdef}
257 = propdef~toplevel n1 {-> propdef~toplevel.propdef}
259 propdef~toplevel {-> propdef}
260 = {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)}
261 | {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)}
262 | {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)}
263 !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)}
264 !toplevel| {intern} [doc]:no redef visibility kwmeth methid signature kwis kwintern {-> New propdef.intern_meth(doc.doc, redef.kwredef, visibility, kwmeth, methid, signature.signature)}
265 | {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, string_o.string, extern_calls, extern_code_block_o.extern_code_block)}
266 | {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)}
267 !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)}
268 !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)}
269 !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)}
270 !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)}
271 !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)}
272 !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)}
273 !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, string_o.string, extern_calls, extern_code_block_o.extern_code_block)}
274 !toplevel| {extern_init_implicit} [doc]:no redef visibility kwnew methid? signature string_o extern_calls extern_code_block {-> New propdef.extern_init(doc.doc, redef.kwredef, visibility, kwnew, methid, signature, string_o.string, extern_calls, extern_code_block)}
276 annotation_withend~nonull {-> annotations?}
277 = {oneliner} kwis many_annotations {-> many_annotations.annotations}
278 | {more} kwis n1 line_annotations kwend {-> line_annotations.annotations}
279 !nonull | {null} {-> Null}
281 annotation_noend {-> annotations}
282 = {oneliner} kwis many_annotations {-> many_annotations.annotations}
283 | {more} kwis n1 line_annotations {-> line_annotations.annotations}
286 = redef visibility kwreadable {-> New able.read(redef.kwredef, kwreadable)}
289 = redef visibility kwwritable {-> New able.write(redef.kwredef, visibility, kwwritable)}
293 = {public} {-> New visibility.public()}
294 | {private} kwprivate no {-> New visibility.private(kwprivate)}
295 | {protected} kwprotected no {-> New visibility.protected(kwprotected)}
296 | {intrude} kwintrude no {-> New visibility.intrude(kwintrude)}
300 = {id} id {-> New methid.id(id)}
301 | {plus} plus {-> New methid.plus(plus)}
302 | {minus} minus {-> New methid.minus(minus)}
303 | {star} star {-> New methid.star(star)}
304 | {slash} slash {-> New methid.slash(slash)}
305 | {percent} percent {-> New methid.percent(percent)}
306 | {eq} eq {-> New methid.eq(eq)}
307 | {ne} ne {-> New methid.ne(ne)}
308 | {le} le {-> New methid.le(le)}
309 | {ge} ge {-> New methid.ge(ge)}
310 | {lt} lt {-> New methid.lt(lt)}
311 | {gt} gt {-> New methid.gt(gt)}
312 | {ll} ll {-> New methid.ll(ll)}
313 | {gg} gg {-> New methid.gg(gg)}
314 | {bra} obra cbra {-> New methid.bra(obra, cbra)}
315 | {starship} starship {-> New methid.starship(starship)}
316 | {assign} id assign {-> New methid.assign(id, assign)}
317 | {braassign} obra cbra assign {-> New methid.braassign(obra, cbra, assign)}
320 signature~withret {-> signature}
321 = opar no params cpar typing [no2]:no {-> New signature(opar, [params.param], cpar, typing.type)}
322 !withret| {noret} opar no params cpar [no2]:no {-> New signature(opar, [params.param], cpar, Null)}
323 | {nopar} typing no {-> New signature(Null, [], Null, typing.type)}
324 !withret| {noparnoret} no {-> New signature(Null, [], Null, Null)}
328 = param params_tail* [n2]:no {-> [param, params_tail.param] }
331 params_tail {-> param}
332 = comma no param {-> param};
334 = {untyped} id annotations_o {-> New param(id, Null, Null, annotations_o.annotations)}
335 | id annotations? typing dotdotdot? {-> New param(id, typing.type, dotdotdot, annotations)}
338 assign_return{-> expr}
339 = expr_final {-> New expr.return(Null, expr_final.expr)}
342 extern_calls {-> extern_calls?}
343 = kwimport no extern_call extern_call_tail* {-> New extern_calls( kwimport, [extern_call, extern_call_tail.extern_call] )}
346 extern_call_tail {-> extern_call}
347 = comma no extern_call {-> extern_call};
348 extern_call {-> extern_call}
349 = {prop} extern_call_prop {-> extern_call_prop.extern_call}
350 | {cast} extern_call_cast {-> extern_call_cast.extern_call}
351 | {super} kwsuper {-> New extern_call.super( kwsuper )}
353 extern_call_prop {-> extern_call}
354 = {local} methid {-> New extern_call.local_prop( methid )}
355 | {full} type quad methid {-> New extern_call.full_prop( type, Null, methid )}
356 | {full2} type dot methid {-> New extern_call.full_prop( type, dot, methid )}
357 | {init} type {-> New extern_call.init_prop( type )}
359 extern_call_cast {-> extern_call}
360 = {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)}
361 | {as_nullable} type dot? kwas [n2]:no kwnullable {-> New extern_call.as_nullable( type, kwas, kwnullable)}
362 | {as_not_nullable} type dot? kwas [n2]:no kwnot [n3]:no kwnullable {-> New extern_call.as_not_nullable( type, kwas, kwnot, kwnullable)}
365 string_o {->string?} = string? {-> string};
367 in_language = kwin string;
368 extern_code_block = in_language? extern_code_segment;
369 extern_code_block_o {-> extern_code_block?}
370 = extern_code_block {-> extern_code_block}
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_o~nopar {-> New type(kwnullable, classid, [], annotations_o~nopar.annotations)}
378 !nobra | {generic} kwnullable? classid obra no types [n2]:no cbra annotations_o~nopar {-> New type(kwnullable, classid, [types.type], annotations_o~nopar.annotations)}
381 = type types_tail* {-> [type, types_tail.type]};
383 = comma no type {-> type};
385 = column no type {-> type};
387 = column no type {-> type}
391 /* STATMENTS *****************************************************************/
392 stmtso~withelse~withend {-> expr?}
393 = {block} n stmtsnend {-> stmtsnend.expr}
394 | {emptyblock} n kwend {-> New expr.block([], kwend)}
395 | {emptyoneline} kwend {-> New expr.block([], kwend)}
396 !withend| {oneline} stmt~withelse {-> stmt~withelse.expr}
399 = stmt stmts_tail* {-> New expr.block([stmt.expr, stmts_tail.expr], Null)};
401 = stmt stmts_tail* n {-> New expr.block([stmt.expr, stmts_tail.expr], Null)};
403 = stmt stmts_tail* n kwend {-> New expr.block([stmt.expr, stmts_tail.expr], kwend)};
405 = n stmt {-> stmt.expr};
406 stmt~withelse~noexpr~nopar {-> expr}
407 = {vardecl} vardecl~withelse {-> vardecl~withelse.expr}
408 | {assign} assignment~withelse~nopar {-> assignment~withelse~nopar.expr}
409 | {return} kwreturn expr_final~withelse? {-> New expr.return(kwreturn, expr_final~withelse.expr)}
410 | {break} kwbreak label? expr_final~withelse? {-> New expr.break(kwbreak, label, expr_final~withelse.expr)}
411 | {abort} kwabort {-> New expr.abort(kwabort)}
412 | {continue} kwcontinue label? expr_final~withelse? {-> New expr.continue(kwcontinue, label, expr_final~withelse.expr)}
413 | {do} do~withelse {-> do~withelse.expr}
414 !noexpr | {if} if~withelse {-> if~withelse.expr}
415 | {while} while~withelse {-> while~withelse.expr}
416 | {loop} loop~withelse {-> loop~withelse.expr}
417 | {for} for~withelse {-> for~withelse.expr}
418 | {assert} assert~withelse {-> assert~withelse.expr}
419 !noexpr | {call} recv qid args_nopar {-> New expr.call(recv.expr, qid.id, args_nopar.exprs)}
420 !noexpr | {super} qualified_o kwsuper args_nopar {-> New expr.super(qualified_o.qualified, kwsuper, args_nopar.exprs)}
421 !noexpr | {init} recv qualified? kwinit args_nopar {-> New expr.init(recv.expr, kwinit, args_nopar.exprs)}
422 | {debug_type_is} kwdebug kwtype type column expr_final~withelse {-> New expr.debug_type(kwdebug, kwtype, expr_final~withelse.expr, type) }
427 assign_continue~withelse{-> expr}
428 = expr_final~withelse {-> New expr.continue(Null, Null, expr_final~withelse.expr)}
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)}
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)}
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)}
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)}
460 elsepartblock {-> expr?}
461 = {else} kwelse stmtso {-> stmtso.expr}
462 | {empty} kwend {-> New expr.block([], kwend)}
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)}
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)}
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)}
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)}
487 /* EXPRESSIONS ***************************************************************/
488 expr_final~nopar~withelse~nobra {-> expr}
489 = expr~nopar~nobra {-> expr~nopar~nobra.expr}
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)}
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
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)}
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
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
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
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
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)}
549 expr_atom~nopar~nobra {-> expr}
550 = {attr} recv~nopar~nobra qualified_o attrid {-> New expr.attr(recv~nopar~nobra.expr, attrid)}
551 | {call} recv~nopar~nobra qid args {-> New expr.call(recv~nopar~nobra.expr, qid.id, args.exprs)}
552 | {super} qualified_o kwsuper args {-> New expr.super(qualified_o.qualified, kwsuper, args.exprs)}
553 | {init} recv~nopar~nobra kwinit args {-> New expr.init(recv~nopar~nobra.expr, kwinit, args.exprs)}
554 !nobra | {bra} expr_atom~nopar braargs {-> New expr.bra(expr_atom~nopar.expr, braargs.exprs)}
555 | {new} kwnew no type~nobra_nopar dot [n2]:no qid args {-> New expr.new(kwnew, type~nobra_nopar.type, qid.id, args.exprs)}
556 // !nopar to unambiguise 'foo[5].bar' between '(foo[5]).bar' and 'foo([5].bar),
557 !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)}
558 !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)}
559 !nobra!nopar | {array} braargs annotations_o {-> New expr.array(braargs.exprs, annotations_o.annotations)}
560 | {self} kwself annotations_o {-> New expr.self(kwself, annotations_o.annotations)}
561 | {true} kwtrue annotations_o {-> New expr.true(kwtrue, annotations_o.annotations)}
562 | {false} kwfalse annotations_o {-> New expr.false(kwfalse, annotations_o.annotations)}
563 | {null} kwnull annotations_o {-> New expr.null(kwnull, annotations_o.annotations)}
564 | {int} number annotations_o {-> New expr.int(number, annotations_o.annotations)}
565 | {float} float annotations_o {-> New expr.float(float, annotations_o.annotations)}
566 | {char} char annotations_o {-> New expr.char(char, annotations_o.annotations)}
567 | {string} string annotations_o {-> New expr.string(string, annotations_o.annotations)}
568 | {superstring} superstring {-> superstring.expr}
569 !nopar | {par} opar no expr [n2]:no cpar annotations_o {-> New expr.par(opar, expr, cpar, annotations_o.annotations)}
570 | {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)}
571 | {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)}
574 superstring {-> expr}
575 = superstring_start superstring_middle* superstring_end annotations_o {-> New expr.superstring([superstring_start.expr, superstring_middle.expr, superstring_end.expr], annotations_o.annotations)};
576 superstring_start {-> expr*}
577 = start_string_p no expr [n2]:no {-> [start_string_p.expr, expr]}
578 | {noexpr} start_string_p no {-> [start_string_p.expr]}
580 start_string_p {-> expr}
581 = start_string {-> New expr.start_string(start_string)};
582 superstring_middle {-> expr*}
583 = mid_string_p no expr [n2]:no {-> [mid_string_p.expr, expr]}
584 | {noexpr} mid_string_p no {-> [mid_string_p.expr]}
586 mid_string_p {-> expr}
587 = mid_string {-> New expr.mid_string(mid_string)};
588 superstring_end {-> expr}
589 = end_string {-> New expr.end_string(end_string)};
591 /* ANNOTATIONS *******************************************************************/
593 annotations~nopar {-> annotations}
594 = {one} at one_annotation~nopar {-> New annotations(at, Null, [one_annotation~nopar.annotation], Null)}
595 | {many} at opar no annotation_list [n2]:no cpar {-> New annotations(at, opar, [annotation_list.annotation], cpar)}
597 annotations_o~nopar {-> annotations?}
598 = annotations~nopar {-> annotations~nopar.annotations}
602 one_annotation~nopar {-> annotation}
603 = {alone} atid annotations_o~nopar {-> New annotation(atid, Null, [], Null, annotations_o~nopar.annotations)}
604 // !nopar to unambiguise 'new T@foo(bar)' between 'new T@(foo(bar))' and 'new (T@foo)(bar)'
605 !nopar | {args} atid opar no at_args [n2]:no cpar annotations_o~nopar {-> New annotation(atid, opar, [at_args.at_arg], cpar, annotations_o~nopar.annotations)}
608 many_annotations {-> annotations}
609 = {many} annotation_list {-> New annotations(Null, Null, [annotation_list.annotation], Null)}
612 annotation_list {-> annotation*}
613 = {many} one_annotation annotations_tail* {-> [one_annotation.annotation, annotations_tail.annotation] }
616 line_annotations~forclass {-> annotations}
617 = line_annotation~forclass+ {-> New annotations(Null, Null, [line_annotation~forclass.annotation], Null) }
619 line_annotation~forclass {-> annotation}
620 = [doc]:no atid~forclass annotations? n1 {-> New annotation(atid~forclass.atid, Null, [], Null, annotations)}
621 | {args} [doc]:no atid~forclass opar no at_args cpar annotations? n1 {-> New annotation(atid~forclass.atid, opar, [at_args.at_arg], cpar, annotations)}
622 | {nopar} [doc]:no atid~forclass at_args_nopar n1 {-> New annotation(atid~forclass.atid, Null, [at_args_nopar.at_arg], Null, Null)}
625 annotations_tail {-> annotation}
626 = comma no one_annotation {-> one_annotation.annotation}
629 at_args~nopar {-> at_arg* }
630 = {many} at_arg~nopar at_args_tail* {-> [at_arg~nopar.at_arg, at_args_tail.at_arg]}
633 at_args_tail {-> at_arg}
634 = comma no at_arg {-> at_arg}
637 at_arg~nopar {-> at_arg}
638 = {type} type {-> New at_arg.type(type)}
639 | {expr} expr~nopar {-> New at_arg.expr(expr~nopar.expr)}
640 | {stmt} stmt_noexpr~nopar {-> New at_arg.expr(stmt_noexpr~nopar.expr)}
641 !nopar | {at} annotations {-> New at_arg.at(annotations.annotations)}
644 atid~forclass {-> atid}
645 = {id} id {-> New atid.id(id)}
646 //!forclass | {kwextern} kwextern {-> New atid.kwextern(kwextern)}
647 //!forclass | {kwintern} kwintern {-> New atid.kwintern(kwintern)}
648 !forclass | {kwreadable} kwreadable {-> New atid.kwreadable(kwreadable)}
649 !forclass | {kwwritable} kwwritable {-> New atid.kwwritable(kwwritable)}
650 | {kwimport} kwimport {-> New atid.kwimport(kwimport)}
653 /* MISC **********************************************************************/
655 recv~nopar~nobra {-> expr}
656 = expr_atom~nopar~nobra dot no {-> expr_atom~nopar~nobra.expr}
657 | {implicit} {-> New expr.implicit_self()}
661 = opar no expr_list cpar {-> New exprs.par(opar, [expr_list.expr], cpar) }
662 | {emptypar} opar no cpar {-> New exprs.par(opar, [], cpar) }
663 | {empty} {-> New exprs.list([])}
665 args_nopar {-> exprs}
666 = opar no expr_list cpar {-> New exprs.par(opar, [expr_list.expr], cpar) }
667 | {onearg} expr_nopar {-> New exprs.list([expr_nopar.expr])}
668 | {emptypar} opar no cpar {-> New exprs.par(opar, [], cpar) }
669 | {empty} {-> New exprs.list([])}
672 = obra no expr_list cbra {-> New exprs.bra(obra, [expr_list.expr], cbra)};
674 = expr [n2]:no expr_tail* {-> [expr, expr_tail.expr]};
676 = comma no expr [n2]:no {-> expr};
678 = opar no idlist_nopar [n2]:no cpar {-> [idlist_nopar.id]}
679 | {nopar} idlist_nopar {-> [idlist_nopar.id]}
681 idlist_nopar {-> id*}
682 = {single} id {-> [id]}
683 | {more} idlist_nopar no comma [n2]:no id {-> [idlist_nopar.id, id]}
686 module_name {-> module_name}
687 = {mod} modquad* id {-> New module_name(Null, [modquad.id], id)}
688 | {root} quad no modquad* id {-> New module_name(quad, [modquad.id], id)}
692 = {cla} modquad* classquad {-> New qualified([modquad.id], classquad.classid)}
693 | {mod} modquad+ {-> New qualified([modquad.id], Null)}
695 qualified_o {-> qualified?}
696 = qualified {-> qualified}
700 = qualified? id {-> id}
702 qclassid {-> classid}
703 = qualified? classid {-> classid}
706 = id quad no {-> id};
707 classquad {-> classid}
708 = classid quad no {-> classid};
714 n1 = {a} comment | {b} eol;
716 = {a} n2? comment+ {-> New doc([comment])}
725 = {a} n2? comment+ eol+
729 /*****************************************************************************/
731 /*****************************************************************************/
733 module = moduledecl? [imports]:import* [extern_code_blocks]:extern_code_block* [classdefs]:classdef*;
736 = doc? kwmodule [name]:module_name annotations?;
738 import = {std} visibility kwimport [name]:module_name annotations?
739 | {no} visibility kwimport kwend
744 | {private} kwprivate
745 | {protected} kwprotected
746 | {intrude} kwintrude
749 classdef= {std} doc? kwredef? visibility classkind [id]:classid? [formaldefs]:formaldef* annotations? extern_code_block? [superclasses]:superclass* [propdefs]:propdef* kwend
750 | {top} [propdefs]:propdef*
751 | {main} [propdefs]:propdef*
755 | {abstract} kwabstract kwclass
756 | {interface} kwinterface
758 | {extern} kwextern kwclass?
760 formaldef = [id]:classid type? annotations?;
761 superclass = kwsuper type annotations?;
764 propdef = {attr} doc? [readable]:able? [writable]:able? kwredef? visibility kwvar [id]:attrid? [id2]:id? type? annotations? expr?
765 | {meth} doc? kwredef? visibility methid signature
766 | {deferred_meth} doc? kwredef? visibility kwmeth methid signature annotations?
767 | {intern_meth} doc? kwredef? visibility kwmeth methid signature
768 | {extern_meth} doc? kwredef? visibility kwmeth methid signature [extern]:string? extern_calls? extern_code_block?
769 | {concrete_meth} doc? kwredef? visibility kwmeth methid signature annotations? [block]:expr?
770 | {concrete_init} doc? kwredef? visibility kwinit methid? signature annotations? [block]:expr?
771 //| {concrete_new} doc? kwredef? visibility kwnew methid? signature [block]:expr?
772 | {extern_init} doc? kwredef? visibility kwnew methid? signature [extern]:string? extern_calls? extern_code_block?
773 | {main_meth} kwredef? [block]:expr?
774 | {type} doc? kwredef? visibility kwtype [id]:classid type annotations?
777 able = {read} kwredef? kwreadable
778 | {write} kwredef? visibility? kwwritable
781 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;
783 signature = opar? [params]:param* cpar? type?;
785 param = id type? dotdotdot? annotations?
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 | {ne} expr [expr2]:expr
815 | {lt} expr [expr2]:expr
816 | {le} expr [expr2]:expr
817 | {ll} expr [expr2]:expr
818 | {gt} expr [expr2]:expr
819 | {ge} expr [expr2]:expr
820 | {gg} expr [expr2]:expr
822 | {plus} expr [expr2]:expr
823 | {minus} expr [expr2]:expr
824 | {starship} expr [expr2]:expr
825 | {star} expr [expr2]:expr
826 | {slash} expr [expr2]:expr
827 | {percent} expr [expr2]:expr
828 | {uminus} minus expr
829 | {new} kwnew type id? [args]:exprs
830 | {attr} expr [id]:attrid
831 | {attr_assign} expr [id]:attrid assign [value]:expr
832 | {attr_reassign} expr [id]:attrid assign_op [value]:expr
833 | {call} expr id [args]:exprs
834 | {call_assign} expr id [args]:exprs assign [value]:expr
835 | {call_reassign} expr id [args]:exprs assign_op [value]:expr
836 | {super} qualified? kwsuper [args]:exprs
837 | {init} expr kwinit [args]:exprs
838 | {bra} expr [args]:exprs
839 | {bra_assign} expr [args]:exprs assign [value]:expr
840 | {bra_reassign} expr [args]:exprs assign_op [value]:expr
842 | {var_assign} id assign [value]:expr
843 | {var_reassign} id assign_op [value]:expr
844 | {range} expr [expr2]:expr annotations?
845 | {crange} obra expr [expr2]:expr cbra annotations?
846 | {orange} obra expr [expr2]:expr [cbra]:obra annotations?
847 | {array} [exprs]:exprs annotations?
848 | {self} kwself annotations?
850 | {true} kwtrue annotations?
851 | {false} kwfalse annotations?
852 | {null} kwnull annotations?
853 | {int} number annotations?
854 | {float} float annotations?
855 | {char} char annotations?
856 | {string} string annotations?
857 | {start_string} [string]:start_string
858 | {mid_string} [string]:mid_string
859 | {end_string} [string]:end_string
860 | {superstring} [exprs]:expr* annotations?
861 | {par} opar expr cpar annotations?
862 | {as_cast} expr kwas opar type cpar
863 | {as_notnull} expr kwas opar kwnot kwnull cpar
864 | {isset_attr} kwisset expr [id]:attrid
865 | {debug_type} kwdebug kwtype expr type
868 = {list} [exprs]:expr*
869 | {par} opar [exprs]:expr* cpar
870 | {bra} obra [exprs]:expr* cbra
877 module_name = quad? [path]:id* id;
878 extern_calls = kwimport [extern_calls]:extern_call*
882 | {local_prop} methid
883 | {full_prop} type dot? methid
885 | {cast_as} [from_type]:type dot? kwas [to_type]:type
886 | {as_nullable} type kwas kwnullable
887 | {as_not_nullable} type kwas kwnot kwnullable
889 in_language = kwin string;
890 extern_code_block = in_language? extern_code_segment;
892 qualified = id* classid? ;
896 annotations = at? opar? [items]:annotation* cpar?;
898 annotation = atid opar? [args]:at_arg* cpar? annotations?;
905 atid = {id} id | {kwextern} [id]:kwextern | {kwintern} [id]:kwintern | {kwreadable} [id]:kwreadable | {kwwritable} [id]:kwwritable | {kwimport} [id]:kwimport;
907 /*****************************************************************************/