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 hexdigit = ['0'..'9'] | ['a'..'f'] | ['A'..'F'];
31 letter = lowercase | uppercase | digit | '_';
36 any = [all - [cr + lf]];
37 eol_helper = cr lf | cr | lf; // This takes care of different platforms
39 // characers inside strings and super-strings (atomaton powaa)
41 = [any - [['"' + '{'] + '\']]
51 sstr_body = sstr_char*;
53 long_str_char = str_char | cr | lf;
55 // because no substraction in sablecc3, complex long strings are difficult to express
58 ls12 = ls1? (ls2 ls1)* ls2?;
64 long_str_body = long_str_part*;
65 lsend1 = ls2? (ls1 ls2)* '"""' '"'*;
66 lsend2 = ls1? (ls2 ls1)* '{{{' '{'*;
68 long_sstr_char = sstr_char | cr | lf;
72 | ''' ''' long_sstr_char
75 long_sstr_body = long_sstr_part*;
83 extern_code_body = extern_code_char*;
85 /*****************************************************************************/
87 /*****************************************************************************/
91 /*****************************************************************************/
93 /*****************************************************************************/
98 comment = '#' any* eol_helper?;
100 kwpackage = 'package';
104 kwabstract = 'abstract';
105 kwinterface = 'interface';
106 kwenum = 'universal'|'enum';
117 kwprotected = 'protected';
118 kwprivate = 'private';
119 kwintrude = 'intrude';
130 kwimplies = 'implies';
132 kwcontinue = 'continue';
145 kwnullable = 'nullable';
149 kwdebug = '__debug__';
195 classid = uppercase letter*;
196 id = lowercase letter*;
197 attrid = '_' lowercase letter*;
200 hex_number = ('0x' | '0X') hexdigit+;
201 float = digit* '.' digit+;
202 string = '"' str_body '"' | '"' '"' '"' long_str_body lsend1 | ''' ''' ''' long_sstr_body ''' ''' ''';
203 start_string = '"' str_body '{' | '"' '"' '"' long_str_body lsend2;
204 mid_string = '}' str_body '{' | '}' '}' '}' long_str_body lsend2;
205 end_string = '}' str_body '"' | '}' '}' '}' long_str_body lsend1;
206 char = (''' [[any - '''] - '\'] ''') | (''' '\' any ''');
207 bad_string = ('"'|'}') str_body | '"' '"' '"' long_str_body | ''' ''' ''' long_sstr_body;
208 bad_char = ''' '\'? any;
210 extern_code_segment = '`' '{' extern_code_body '`' '}';
212 /*****************************************************************************/
214 /*****************************************************************************/
218 /*****************************************************************************/
220 /*****************************************************************************/
222 /* MODULES *******************************************************************/
224 = 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])};
227 = [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)};
230 = {std} [doc]:no redef visibility kwimport no module_name annotation_withend [n2]:n1 {-> New import.std(visibility, kwimport, module_name, annotation_withend.annotations)}
231 | {no} [doc]:no redef visibility kwimport no kwend [n2]:n1 {-> New import.no(visibility, kwimport, kwend)}
235 = {classdef} classdef {-> classdef}
236 | propdef_toplevel n1 {-> New classdef.top([propdef_toplevel.propdef])}
239 implicit_main_class {-> classdef?}
240 = implicit_main_meth {-> New classdef.main([implicit_main_meth.propdef])}
241 | {null} n? {-> Null}
243 implicit_main_meth {-> propdef}
244 = [doc]:no stmts {-> New propdef.main_meth(Null, stmts.expr)}
245 | {n} [doc]:no stmtsn {-> New propdef.main_meth(Null, stmtsn.expr)}
248 /* CLASSES *******************************************************************/
250 = [doc]:no redef visibility classkind no qclassid formaldefs extern_code_block? propdefs kwend {-> New classdef.std(doc.doc, redef.kwredef, visibility, classkind, qclassid.classid, [formaldefs.formaldef], extern_code_block, [propdefs.propdef], kwend)};
252 = kwredef? {-> kwredef};
255 | {abstract} kwabstract kwclass
256 | {interface} kwinterface
258 | {extern} kwextern kwclass
261 formaldefs {-> formaldef*}
262 = obra no formaldef formaldefs_tail* [n2]:no cbra {-> [formaldef, formaldefs_tail.formaldef]}
265 formaldefs_tail {-> formaldef}
266 = comma no formaldef {-> formaldef};
268 = classid annotations? typing_o {-> New formaldef(classid, typing_o.type, annotations)};
270 superclass {-> propdef}
271 = {super} [doc]:no redef visibility kwsuper [n2]:no type annotation_withend {-> New propdef.super(doc.doc, redef.kwredef, visibility, kwsuper, type, annotation_withend.annotations)}
274 propdefs {-> propdef*}
275 = propdefn+ no {-> [propdefn.propdef]}
276 | {super} superclass {-> [superclass.propdef]}
279 propdefn {-> propdef}
280 = propdef n1 {-> propdef.propdef}
282 propdef~toplevel {-> propdef}
283 = {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)}
284 | {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)}
285 !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)}
286 !toplevel| {new} [doc]:no redef visibility kwnew qmethid? signature annotation_noend? kwdo stmtso kwend_o {-> New propdef.meth(doc.doc, redef.kwredef, visibility, Null, Null, kwnew, qmethid.methid, signature, annotation_noend.annotations, Null, Null, stmtso.expr)}
287 | {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)}
288 !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, Null)}
289 !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, Null)}
290 !toplevel| {var5} [doc]:no redef visibility kwvar id typing_o annotation_noend? kwdo stmtso kwend? {-> New propdef.attr(doc.doc, redef.kwredef, visibility, kwvar, id, typing_o.type, Null, annotation_noend.annotations, stmtso.expr)}
291 !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)}
292 !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)}
293 !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)}
294 !toplevel| {annot} line_annotation_forclass {-> line_annotation_forclass.propdef}
295 !toplevel| {super} superclass {-> superclass.propdef}
297 annotation_withend~nonull {-> annotations?}
298 = {oneliner} kwis many_annotations {-> many_annotations.annotations}
299 | {more} kwis n1 line_annotations kwend {-> line_annotations.annotations}
300 !nonull | {null} {-> Null}
302 annotation_noend {-> annotations}
303 = {oneliner} kwis many_annotations {-> many_annotations.annotations}
304 | {more} kwis n1 line_annotations {-> line_annotations.annotations}
308 = {public} {-> New visibility.public(Null)}
309 | {public2} kwpublic no {-> New visibility.public(kwpublic)}
310 | {private} kwprivate no {-> New visibility.private(kwprivate)}
311 | {protected} kwprotected no {-> New visibility.protected(kwprotected)}
312 | {intrude} kwintrude no {-> New visibility.intrude(kwintrude)}
315 methid~noid {-> methid}
316 = {plus} plus {-> New methid.plus(plus)}
317 | {minus} minus {-> New methid.minus(minus)}
318 | {star} star {-> New methid.star(star)}
319 | {starstar} starstar {-> New methid.starstar(starstar)}
320 | {slash} slash {-> New methid.slash(slash)}
321 | {percent} percent {-> New methid.percent(percent)}
322 | {pipe} pipe {-> New methid.pipe(pipe)}
323 | {caret} caret {-> New methid.caret(caret)}
324 | {amp} amp {-> New methid.amp(amp)}
325 | {tilde} tilde {-> New methid.tilde(tilde)}
326 | {eq} eq {-> New methid.eq(eq)}
327 | {ne} ne {-> New methid.ne(ne)}
328 | {le} le {-> New methid.le(le)}
329 | {ge} ge {-> New methid.ge(ge)}
330 | {lt} lt {-> New methid.lt(lt)}
331 | {gt} gt {-> New methid.gt(gt)}
332 | {ll} ll {-> New methid.ll(ll)}
333 | {gg} gg {-> New methid.gg(gg)}
334 | {bra} obra cbra {-> New methid.bra(obra, cbra)}
335 | {starship} starship {-> New methid.starship(starship)}
336 | {assign} id assign {-> New methid.assign(id, assign)}
337 | {braassign} obra cbra assign {-> New methid.braassign(obra, cbra, assign)}
338 !noid | {id} id {-> New methid.id(id)}
341 signature {-> signature}
342 = opar no params cpar typing [no2]:no {-> New signature(opar, [params.param], cpar, typing.type)}
343 | {noret} opar no params cpar [no2]:no {-> New signature(opar, [params.param], cpar, Null)}
344 | {nopar} typing no {-> New signature(Null, [], Null, typing.type)}
345 | {noparnoret} no {-> New signature(Null, [], Null, Null)}
349 = param params_tail* [n2]:no {-> [param, params_tail.param] }
352 params_tail {-> param}
353 = comma no param {-> param};
355 = {untyped} id annotations_o {-> New param(id, Null, Null, annotations_o.annotations)}
356 | id annotations? typing dotdotdot? {-> New param(id, typing.type, dotdotdot, annotations)}
359 extern_calls {-> extern_calls?}
360 = kwimport no extern_call extern_call_tail* {-> New extern_calls( kwimport, [extern_call, extern_call_tail.extern_call] )}
363 extern_call_tail {-> extern_call}
364 = comma no extern_call {-> extern_call};
365 extern_call {-> extern_call}
366 = {prop} extern_call_prop {-> extern_call_prop.extern_call}
367 | {cast} extern_call_cast {-> extern_call_cast.extern_call}
368 | {super} kwsuper {-> New extern_call.super( kwsuper )}
370 extern_call_prop {-> extern_call}
371 = {local} qmethid {-> New extern_call.local_prop( qmethid.methid )}
372 | {full} type dot qmethid {-> New extern_call.full_prop( type, dot, qmethid.methid )}
373 | {init} type {-> New extern_call.init_prop( type )}
375 extern_call_cast {-> extern_call}
376 = {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)}
377 | {as_cast2}[from_type]:type dot kwas [n2]:no [to_type]:type {-> New extern_call.cast_as(from_type, dot, kwas, to_type)}
378 | {as_nullable} type dot kwas [n2]:no opar [n3]:no kwnullable [n4]:no cpar {-> New extern_call.as_nullable( type, kwas, kwnullable)}
379 | {as_nullable2}type dot kwas [n2]:no kwnullable {-> New extern_call.as_nullable( type, kwas, kwnullable)}
380 | {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)}
381 | {as_not_nullable2}type dot kwas [n2]:no kwnot [n3]:no kwnullable {-> New extern_call.as_not_nullable( type, kwas, kwnot, kwnullable)}
384 string_o {->string?} = string? {-> string};
386 in_language = kwin no string [n1]:no {-> New in_language(kwin, string)};
387 extern_code_block = in_language? extern_code_segment;
388 extern_code_block_o {-> extern_code_block?}
389 = extern_code_block {-> extern_code_block}
392 extern_code_body {-> extern_code_block} = no extern_code_block {-> extern_code_block};
394 /* TYPES *********************************************************************/
395 type~nobra~nopar {-> type}
396 = {simple} kwnullable? classid annotations_o~nopar {-> New type(kwnullable, classid, [], annotations_o~nopar.annotations)}
397 !nobra | {generic} kwnullable? classid obra no types [n2]:no cbra annotations_o~nopar {-> New type(kwnullable, classid, [types.type], annotations_o~nopar.annotations)}
400 = type types_tail* {-> [type, types_tail.type]};
402 = comma no type {-> type};
404 = column no type {-> type};
406 = column no type {-> type}
410 /* STATMENTS *****************************************************************/
411 stmtso~withelse~withend {-> expr?}
412 = {block} n stmtsnend {-> stmtsnend.expr}
413 | {emptyblock} n kwend {-> New expr.block([], kwend)}
414 | {emptyoneline} kwend {-> New expr.block([], kwend)}
415 !withend| {oneline} stmt~withelse {-> stmt~withelse.expr}
418 = stmt stmts_tail* {-> New expr.block([stmt.expr, stmts_tail.expr], Null)};
420 = stmt stmts_tail* n {-> New expr.block([stmt.expr, stmts_tail.expr], Null)};
422 = stmt stmts_tail* n kwend {-> New expr.block([stmt.expr, stmts_tail.expr], kwend)};
424 = n stmt {-> stmt.expr};
425 stmt~withelse~noexpr~nopar {-> expr}
426 = {vardecl} vardecl {-> vardecl.expr}
427 | {assign} assignment~nopar {-> assignment~nopar.expr}
428 | {return} kwreturn expr? {-> New expr.return(kwreturn, expr)}
429 | {break} kwbreak label? {-> New expr.break(kwbreak, label)}
430 | {abort} kwabort {-> New expr.abort(kwabort)}
431 | {continue} kwcontinue label? {-> New expr.continue(kwcontinue, label)}
432 | {do} do~withelse {-> do~withelse.expr}
433 !noexpr | {if} if~withelse {-> if~withelse.expr}
434 | {while} while~withelse {-> while~withelse.expr}
435 | {loop} loop~withelse {-> loop~withelse.expr}
436 | {for} for~withelse {-> for~withelse.expr}
437 | {with} with~withelse {-> with~withelse.expr}
438 | {assert} assert~withelse {-> assert~withelse.expr}
439 !noexpr | {call} recv qid args_nopar {-> New expr.call(recv.expr, qid.id, args_nopar.exprs)}
440 !noexpr | {super} qualified_o kwsuper args_nopar {-> New expr.super(qualified_o.qualified, kwsuper, args_nopar.exprs)}
441 !noexpr | {init} recv qualified? kwinit args_nopar {-> New expr.init(recv.expr, kwinit, args_nopar.exprs)}
442 | {debug_type_is} kwdebug kwtype type column expr {-> New expr.debug_type(kwdebug, kwtype, expr.expr, type) }
448 = kwvar id annotations? typing_o {-> New expr.vardecl(kwvar, id, typing_o.type, Null, Null, annotations)}
449 | {assign} kwvar id annotations? typing_o assign no expr {-> New expr.vardecl(kwvar, id, typing_o.type, assign, expr.expr, annotations)}
452 assignment~nopar {-> expr}
453 = {attr} recv~nopar qualified_o attrid assign expr {-> New expr.attr_assign(recv~nopar.expr, attrid, assign, expr)}
454 | {call} recv~nopar qid args assign expr {-> New expr.call_assign(recv~nopar.expr, qid.id, args.exprs, assign, expr)}
455 | {bra} expr_atom~nopar braargs assign expr {-> New expr.bra_assign(expr_atom~nopar.expr, braargs.exprs, assign, expr)}
456 | {attr_re} recv~nopar qualified_o attrid assign_op expr {-> New expr.attr_reassign(recv~nopar.expr, attrid, assign_op, expr)}
457 | {call_re} recv~nopar qid args assign_op expr {-> New expr.call_reassign(recv~nopar.expr, qid.id, args.exprs, assign_op, expr)}
458 | {bra_re} expr_atom~nopar braargs assign_op expr {-> New expr.bra_reassign(expr_atom~nopar.expr, braargs.exprs, assign_op, expr)}
465 | {percent} percenteq
466 | {starstar} starstareq
474 do~withelse {-> expr}
475 = kwdo stmtso_withend label {-> New expr.do(kwdo, stmtso_withend.expr, label)}
476 | {nolabel} kwdo stmtso~withelse {-> New expr.do(kwdo, stmtso~withelse.expr, Null)}
479 if~withelse {-> expr}
480 = {onelineelse} kwif no expr [n2]:no kwthen stmt_withelse kwelse stmtso~withelse {-> New expr.if(kwif, expr, stmt_withelse.expr, stmtso~withelse.expr)}
481 !withelse | {oneline} kwif no expr [n2]:no kwthen stmt {-> New expr.if(kwif, expr, stmt.expr, Null)}
482 !withelse | {block} kwif no expr [n2]:no kwthen [n3]:n stmtsn elsepartblock {-> New expr.if(kwif, expr, stmtsn.expr, elsepartblock.expr)}
483 !withelse | {emptyblock} kwif no expr [n2]:no kwthen [n3]:n? elsepartblock {-> New expr.if(kwif, expr, Null, elsepartblock.expr)}
485 elsepartblock {-> expr?}
486 = {else} kwelse stmtso {-> stmtso.expr}
487 | {empty} kwend {-> New expr.block([], kwend)}
490 loop~withelse {-> expr}
491 = kwloop stmtso_withend label {-> New expr.loop(kwloop, stmtso_withend.expr, label)}
492 | {nolabel} kwloop stmtso~withelse {-> New expr.loop(kwloop, stmtso~withelse.expr, Null)}
495 while~withelse {-> expr}
496 = kwwhile no expr [n2]:no kwdo stmtso_withend label {-> New expr.while(kwwhile, expr, kwdo, stmtso_withend.expr, label)}
497 | {nolabel} kwwhile no expr [n2]:no kwdo stmtso~withelse {-> New expr.while(kwwhile, expr, kwdo, stmtso~withelse.expr, Null)}
500 for~withelse {-> expr}
501 = 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)}
502 | {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)}
505 with~withelse {-> expr}
506 = kwwith no withexpr [n4]:no kwdo stmtso_withend label {-> New expr.with(kwwith, withexpr.expr, kwdo, stmtso_withend.expr, label)}
507 | {nolabel} kwwith no withexpr [n4]:no kwdo stmtso~withelse {-> New expr.with(kwwith, withexpr.expr, kwdo, stmtso~withelse.expr, Null)}
511 = {assign} id annotations? typing_o assign no expr {-> New expr.vardecl(Null, id, typing_o.type, assign, expr.expr, annotations)}
515 assert~withelse {-> expr}
516 = {else} kwassert assertid? expr kwelse stmtso~withelse {-> New expr.assert(kwassert, assertid.id, expr, stmtso~withelse.expr)}
517 !withelse| {noelse} kwassert assertid? expr {-> New expr.assert(kwassert, assertid.id, expr, Null)}
522 /* EXPRESSIONS ***************************************************************/
523 expr~nopar~nobra {-> expr}
524 = expr_and~nopar~nobra {-> expr_and~nopar~nobra.expr}
525 | {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)}
528 expr_and~nopar~nobra {-> expr}
529 = expr_not~nopar~nobra {-> expr_not~nopar~nobra.expr}
530 | {:or} expr_and~nopar~nobra kwor :no expr_not~nopar~nobra
531 | {:and} expr_and~nopar~nobra kwand :no expr_not~nopar~nobra
532 | {:or_else} expr_and~nopar~nobra kwor kwelse :no expr_not~nopar~nobra
533 | {:implies} expr_and~nopar~nobra kwimplies :no expr_not~nopar~nobra
536 expr_not~nopar~nobra {-> expr}
537 = expr_eq~nopar~nobra {-> expr_eq~nopar~nobra.expr}
538 | {not} kwnot no expr_not~nopar~nobra {-> New expr.not(kwnot, expr_not~nopar~nobra.expr)}
541 expr_eq~nopar~nobra {-> expr}
542 = expr_bitor~nopar~nobra {-> expr_bitor~nopar~nobra.expr}
543 | {:eq} expr_bitor~nopar~nobra eq :no [expr2]:expr_bitor~nopar~nobra
544 | {:ne} expr_bitor~nopar~nobra ne :no [expr2]:expr_bitor~nopar~nobra
545 | {:lt} expr_bitor~nopar~nobra lt :no [expr2]:expr_bitor~nopar~nobra
546 | {:le} expr_bitor~nopar~nobra le :no [expr2]:expr_bitor~nopar~nobra
547 | {:gt} expr_bitor~nopar~nobra gt :no [expr2]:expr_bitor~nopar~nobra
548 | {:ge} expr_bitor~nopar~nobra ge :no [expr2]:expr_bitor~nopar~nobra
549 | {:starship} expr_bitor~nopar~nobra starship :no [expr2]:expr_bitor~nopar~nobra
550 | {:isa} expr_bitor~nopar~nobra kwisa :no type~nobra
553 expr_bitor~nopar~nobra {-> expr}
554 = [expr]:expr_bitxor~nopar~nobra {-> expr.expr}
555 | {:pipe} expr_bitor~nopar~nobra pipe :no [expr2]:expr_bitxor~nopar~nobra
558 expr_bitxor~nopar~nobra {-> expr}
559 = [expr]:expr_bitand~nopar~nobra {-> expr.expr}
560 | {:caret} expr_bitxor~nopar~nobra caret :no [expr2]:expr_bitand~nopar~nobra
563 expr_bitand~nopar~nobra {-> expr}
564 = [expr]:expr_shift~nopar~nobra {-> expr.expr}
565 | {:amp} expr_bitand~nopar~nobra amp :no [expr2]:expr_shift~nopar~nobra
568 expr_shift~nopar~nobra {-> expr}
569 = [expr]:expr_add~nopar~nobra {-> expr.expr}
570 | {:ll} expr_shift~nopar~nobra ll :no [expr2]:expr_add~nopar~nobra
571 | {:gg} expr_shift~nopar~nobra gg :no [expr2]:expr_add~nopar~nobra
574 expr_add~nopar~nobra {-> expr}
575 = expr_mul~nopar~nobra {-> expr_mul~nopar~nobra.expr}
576 | {:plus} expr_add~nopar~nobra plus :no [expr2]:expr_mul~nopar~nobra
577 | {:minus} expr_add~nopar~nobra minus :no [expr2]:expr_mul~nopar~nobra
580 expr_mul~nopar~nobra {-> expr}
581 = expr_pow~nopar~nobra {-> expr_pow~nopar~nobra.expr}
582 | {:star} expr_mul~nopar~nobra star :no [expr2]:expr_pow~nopar~nobra
583 | {:slash} expr_mul~nopar~nobra slash :no [expr2]:expr_pow~nopar~nobra
584 | {:percent} expr_mul~nopar~nobra percent :no [expr2]:expr_pow~nopar~nobra
587 expr_pow~nopar~nobra {-> expr}
588 = expr_minus~nopar~nobra {-> expr_minus~nopar~nobra.expr}
589 | {:starstar} expr_minus~nopar~nobra starstar :no [expr2]:expr_pow~nopar~nobra
592 expr_minus~nopar~nobra {-> expr}
593 = expr_new~nopar~nobra {-> expr_new~nopar~nobra.expr}
594 | {:uminus} minus expr_minus~nobra
595 | {:uplus} plus expr_minus~nobra
596 | {:utilde} tilde expr_minus~nobra
597 | {:once} kwonce :no expr_minus~nobra
600 expr_new~nopar~nobra {-> expr}
601 = expr_atom~nopar~nobra {-> expr_atom~nopar~nobra.expr}
602 | {new} kwnew no type~nobra_nopar args {-> New expr.new(kwnew, type~nobra_nopar.type, Null, args.exprs)}
603 | {isset_attr} kwisset recv~nopar~nobra qualified_o attrid {-> New expr.isset_attr(kwisset, recv~nopar~nobra.expr, attrid)}
606 expr_atom~nopar~nobra {-> expr}
607 = expr_single~nopar~nobra {-> expr_single~nopar~nobra.expr}
608 | {attr} recv~nopar~nobra qualified_o attrid {-> New expr.attr(recv~nopar~nobra.expr, attrid)}
609 | {call} recv~nopar~nobra qid args {-> New expr.call(recv~nopar~nobra.expr, qid.id, args.exprs)}
610 | {super} qualified_o kwsuper args {-> New expr.super(qualified_o.qualified, kwsuper, args.exprs)}
611 | {init} recv~nopar~nobra kwinit args {-> New expr.init(recv~nopar~nobra.expr, kwinit, args.exprs)}
612 !nobra | {bra} expr_atom~nopar braargs {-> New expr.bra(expr_atom~nopar.expr, braargs.exprs)}
613 | {new} kwnew no type~nobra_nopar dot [n2]:no qid args {-> New expr.new(kwnew, type~nobra_nopar.type, qid.id, args.exprs)}
614 | {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)}
615 | {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)}
616 | {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)}
619 arg~nopar~nobra {-> expr}
620 = [expr]:expr~nopar~nobra {-> expr.expr}
621 | {vararg} [expr]:expr~nopar~nobra dotdotdot {-> New expr.vararg(expr.expr, dotdotdot)}
624 expr_single~nopar~nobra {-> expr}
625 = {self} kwself annotations_o {-> New expr.self(kwself, annotations_o.annotations)}
626 | {true} kwtrue annotations_o {-> New expr.true(kwtrue, annotations_o.annotations)}
627 | {false} kwfalse annotations_o {-> New expr.false(kwfalse, annotations_o.annotations)}
628 | {null} kwnull annotations_o {-> New expr.null(kwnull, annotations_o.annotations)}
629 | {int} number annotations_o {-> New expr.dec_int(number, annotations_o.annotations)}
630 | {hex_int} hex_number annotations_o {-> New expr.hex_int(hex_number, annotations_o.annotations)}
631 | {float} float annotations_o {-> New expr.float(float, annotations_o.annotations)}
632 | {char} char annotations_o {-> New expr.char(char, annotations_o.annotations)}
633 | {string} string annotations_o {-> New expr.string(string, annotations_o.annotations)}
634 | {superstring} superstring {-> superstring.expr}
635 !nopar | {par} expr_par {-> expr_par.expr}
636 // !nopar to unambiguise 'foo[5].bar' between '(foo[5]).bar' and 'foo([5].bar),
637 !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)}
638 !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)}
639 !nobra!nopar | {array} obra no array_items typing_o cbra annotations_o {-> New expr.array(obra, [array_items.expr], typing_o.type, cbra, annotations_o.annotations)}
643 = {par} opar no any_expr [n2]:no cpar annotations_o {-> New expr.par(opar, any_expr.expr, cpar, annotations_o.annotations)}
644 | {tuple} opar no many_expr [n2]:no cpar annotations_o {-> New expr.par(opar, many_expr.expr, cpar, annotations_o.annotations)}
648 = any_expr many_expr_tail+ {-> New expr.many([any_expr.expr, many_expr_tail.expr])}
651 many_expr_tail {->expr}
652 = comma no any_expr {-> any_expr.expr}
655 array_items {-> expr*}
656 = array_item array_items_tail* {-> [array_item.expr, array_items_tail.expr]}
658 array_items_tail {-> expr}
659 = comma no array_item {-> array_item.expr}
663 | {for} kwfor no [ids]:idlist [n2]:no kwin [n3]:no expr [n4]:no kwdo [block]:array_item {-> New expr.for(kwfor, [ids.id], expr, kwdo, block.expr, Null)}
664 | {if} kwif [n1]:no expr [n2]:no kwthen [n3]:no [then]:array_item {-> New expr.if(kwif, expr, then.expr, Null)}
667 superstring {-> expr}
668 = superstring_start superstring_middle* superstring_end annotations_o {-> New expr.superstring([superstring_start.expr, superstring_middle.expr, superstring_end.expr], annotations_o.annotations)};
669 superstring_start {-> expr*}
670 = start_string_p no expr [n2]:no {-> [start_string_p.expr, expr]}
671 | {noexpr} start_string_p no {-> [start_string_p.expr]}
673 start_string_p {-> expr}
674 = start_string {-> New expr.start_string(start_string)};
675 superstring_middle {-> expr*}
676 = mid_string_p no expr [n2]:no {-> [mid_string_p.expr, expr]}
677 | {noexpr} mid_string_p no {-> [mid_string_p.expr]}
679 mid_string_p {-> expr}
680 = mid_string {-> New expr.mid_string(mid_string)};
681 superstring_end {-> expr}
682 = end_string {-> New expr.end_string(end_string)};
684 /* ANNOTATIONS *******************************************************************/
686 annotations~nopar {-> annotations}
687 = {one} at one_annotation~nopar {-> New annotations(at, Null, [one_annotation~nopar.annotation], Null)}
688 | {many} at opar no annotation_list [n2]:no cpar {-> New annotations(at, opar, [annotation_list.annotation], cpar)}
690 annotations_o~nopar {-> annotations?}
691 = annotations~nopar {-> annotations~nopar.annotations}
695 one_annotation~nopar {-> annotation}
696 = {alone} redef visibility atid annotations_o~nopar {-> New annotation(Null, redef.kwredef, visibility, atid, Null, [], Null, annotations_o~nopar.annotations)}
697 // !nopar to unambiguise 'new T@foo(bar)' between 'new T@(foo(bar))' and 'new (T@foo)(bar)'
698 !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)}
701 many_annotations {-> annotations}
702 = {many} annotation_list {-> New annotations(Null, Null, [annotation_list.annotation], Null)}
705 annotation_list {-> annotation*}
706 = {many} one_annotation_list annotations_tail* {-> [one_annotation_list.annotation, annotations_tail.annotation] }
709 one_annotation_list~nopar {-> annotation}
710 = {alone} redef visibility atid annotations_o~nopar {-> New annotation(Null, redef.kwredef, visibility, atid, Null, [], Null, annotations_o~nopar.annotations)}
711 // !nopar to unambiguise 'new T@foo(bar)' between 'new T@(foo(bar))' and 'new (T@foo)(bar)'
712 !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)}
713 !nopar | {nopar} redef visibility atid at_arg_single {-> New annotation(Null, redef.kwredef, visibility, atid, Null, [at_arg_single.expr], Null, Null)}
715 at_arg_single {-> expr}
716 // FIXME: why expr_single but not expr_atom is not clear :(
717 = {expr} [expr]:expr_single_nopar {-> expr.expr}
720 annotations_tail {-> annotation}
721 = comma no one_annotation_list {-> one_annotation_list.annotation}
724 line_annotations {-> annotations}
725 = line_annotation+ {-> New annotations(Null, Null, [line_annotation.annotation], Null) }
727 line_annotation {-> annotation}
728 = [doc]:no redef visibility atid annotations? n1 {-> New annotation(doc.doc, redef.kwredef, visibility, atid.atid, Null, [], Null, annotations)}
729 | {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)}
730 | {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)}
732 line_annotation_forclass {-> propdef}
733 = [doc]:no atid_forclass annotations? {-> New propdef.annot(doc.doc, Null, Null, atid_forclass.atid, Null, [], Null, annotations)}
734 | {args} [doc]:no atid_forclass opar no at_args cpar annotations? {-> New propdef.annot(doc.doc, Null, Null, atid_forclass.atid, opar, [at_args.expr], cpar, annotations)}
735 | {nopar} [doc]:no atid_forclass at_args_nopar {-> New propdef.annot(doc.doc, Null, Null, atid_forclass.atid, Null, [at_args_nopar.expr], Null, Null)}
738 at_args~nopar {-> expr* }
739 = {many} any_expr~nopar at_args_tail* {-> [any_expr~nopar.expr, at_args_tail.expr]}
742 at_args_tail {-> expr}
743 = comma no any_expr {-> any_expr.expr}
746 any_expr~nopar {-> expr}
747 = {type} type {-> New expr.type(type)}
748 | {expr} expr~nopar {-> expr~nopar.expr}
749 | {stmt} stmt_noexpr~nopar {-> stmt_noexpr~nopar.expr}
750 | {methid} recv~nopar qmethid_noid {-> New expr.methid(recv~nopar.expr, qmethid_noid.methid)}
751 !nopar | {at} annotations {-> New expr.at(annotations.annotations)}
754 atid~forclass {-> atid}
755 = {id} id {-> New atid.id(id)}
756 !forclass | {kwextern} kwextern {-> New atid.kwextern(kwextern)}
757 // | {kwimport} kwimport {-> New atid.kwimport(kwimport)}
758 | {kwabstract} kwabstract {-> New atid.kwabstract(kwabstract)}
761 /* MISC **********************************************************************/
763 recv~nopar~nobra {-> expr}
764 = expr_atom~nopar~nobra dot no {-> expr_atom~nopar~nobra.expr}
765 | {implicit} {-> New expr.implicit_self()}
769 = args_n {-> args_n.exprs}
770 | {empty} {-> New exprs.list([])}
773 = opar no expr_list cpar {-> New exprs.par(opar, [expr_list.expr], cpar) }
774 | {emptypar} opar no cpar {-> New exprs.par(opar, [], cpar) }
776 args_nopar {-> exprs}
777 = opar no expr_list cpar {-> New exprs.par(opar, [expr_list.expr], cpar) }
778 | {onearg} expr_nopar {-> New exprs.list([expr_nopar.expr])}
779 | {emptypar} opar no cpar {-> New exprs.par(opar, [], cpar) }
780 | {empty} {-> New exprs.list([])}
783 = obra no expr_list cbra {-> New exprs.bra(obra, [expr_list.expr], cbra)};
785 = arg [n2]:no expr_tail* {-> [arg.expr, expr_tail.expr]};
787 = comma no arg [n2]:no {-> arg.expr};
789 = opar no idlist_nopar [n2]:no cpar {-> [idlist_nopar.id]}
790 | {nopar} idlist_nopar {-> [idlist_nopar.id]}
792 idlist_nopar {-> id*}
793 = {single} id {-> [id]}
794 | {more} idlist_nopar comma [n2]:no id {-> [idlist_nopar.id, id]}
797 module_name {-> module_name}
798 = {mod} modquad* id {-> New module_name(Null, [modquad.id], id)}
799 | {root} quad no modquad* id {-> New module_name(quad, [modquad.id], id)}
803 = {cla} modquad* classquad {-> New qualified([modquad.id], classquad.classid)}
804 | {mod} modquad+ {-> New qualified([modquad.id], Null)}
806 qualified_o {-> qualified?}
807 = qualified {-> qualified}
811 = qualified? id {-> id}
813 qclassid {-> classid}
814 = qualified? classid {-> classid}
816 qmethid~noid {-> methid}
817 = qualified? methid~noid {-> methid~noid.methid}
820 = id quad no {-> id};
821 classquad {-> classid}
822 = classid quad no {-> classid};
828 n1 = {a} comment | {b} eol;
830 = {a} n2? comment+ {-> New doc([comment])}
839 = {a} n2? comment+ eol+
843 /*****************************************************************************/
845 /*****************************************************************************/
847 module = moduledecl? [imports]:import* [extern_code_blocks]:extern_code_block* [classdefs]:classdef*;
850 = doc? kwredef? visibility kwmodule [name]:module_name annotations?;
852 import = {std} visibility kwimport [name]:module_name annotations?
853 | {no} visibility kwimport kwend
858 | {private} kwprivate
859 | {protected} kwprotected
860 | {intrude} kwintrude
863 classdef= {std} doc? kwredef? visibility classkind [id]:classid? [formaldefs]:formaldef* extern_code_block? [propdefs]:propdef* kwend
864 | {top} [propdefs]:propdef*
865 | {main} [propdefs]:propdef*
869 | {abstract} kwabstract kwclass
870 | {interface} kwinterface
872 | {extern} kwextern kwclass?
874 formaldef = [id]:classid type? annotations?;
877 propdef = {attr} doc? kwredef? visibility kwvar [id2]:id type? expr? annotations? [block]:expr?
878 | {main_meth} kwredef? [block]:expr?
879 | {type} doc? kwredef? visibility kwtype [id]:classid type annotations?
880 | {meth} doc? kwredef? visibility kwmeth? kwinit? kwnew? methid? signature annotations? extern_calls? extern_code_block? [block]:expr?
881 | {super} doc? kwredef? visibility kwsuper type annotations?
882 | {annot} doc? kwredef? visibility? atid opar? [args]:expr* cpar? annotations?
890 | {starstar} [op]:starstar
892 | {percent} [op]:percent
901 | {starship} [op]:starship
908 | {braassign} obra cbra assign
911 signature = opar? [params]:param* cpar? type?;
913 param = id type? dotdotdot? annotations?
916 type = kwnullable? [id]:classid [types]:type* annotations?;
920 expr = {block} expr* kwend?
921 | {vardecl} kwvar? id type? assign? expr? annotations?
922 | {return} kwreturn? expr?
923 | {break} kwbreak label?
925 | {continue} kwcontinue? label?
926 | {do} kwdo [block]:expr? label?
927 | {if} kwif expr [then]:expr? [else]:expr?
928 | {ifexpr} kwif expr kwthen [then]:expr kwelse [else]:expr
929 | {while} kwwhile expr kwdo [block]:expr? label?
930 | {loop} kwloop [block]:expr? label?
931 | {for} kwfor [ids]:id* expr kwdo [block]:expr? label?
932 | {with} kwwith expr kwdo [block]:expr? label?
933 | {assert} kwassert id? expr [else]:expr?
936 | {binop} expr [expr2]:expr
937 | {or} expr [op]:kwor [expr2]:expr
938 | {and} expr [op]:kwand [expr2]:expr
939 | {or_else} expr [op]:kwor kwelse [expr2]:expr
940 | {implies} expr [op]:kwimplies [expr2]:expr
942 | {eq} expr [op]:eq [expr2]:expr
943 | {ne} expr [op]:ne [expr2]:expr
944 | {lt} expr [op]:lt [expr2]:expr
945 | {le} expr [op]:le [expr2]:expr
946 | {ll} expr [op]:ll [expr2]:expr
947 | {gt} expr [op]:gt [expr2]:expr
948 | {ge} expr [op]:ge [expr2]:expr
949 | {gg} expr [op]:gg [expr2]:expr
950 | {isa} expr kwisa type
951 | {plus} expr [op]:plus [expr2]:expr
952 | {minus} expr [op]:minus [expr2]:expr
953 | {starship} expr [op]:starship [expr2]:expr
954 | {star} expr [op]:star [expr2]:expr
955 | {starstar} expr [op]:starstar [expr2]:expr
956 | {slash} expr [op]:slash [expr2]:expr
957 | {percent} expr [op]:percent [expr2]:expr
958 | {pipe} expr [op]:pipe [expr2]:expr
959 | {caret} expr [op]:caret [expr2]:expr
960 | {amp} expr [op]:amp [expr2]:expr
961 | {uminus} [op]:minus expr
962 | {uplus} [op]:plus expr
963 | {utilde} [op]:tilde expr
964 | {new} kwnew type id? [args]:exprs
965 | {attr} expr [id]:attrid
966 | {attr_assign} expr [id]:attrid assign [value]:expr
967 | {attr_reassign} expr [id]:attrid assign_op [value]:expr
968 | {call} expr id [args]:exprs
969 | {call_assign} expr id [args]:exprs assign [value]:expr
970 | {call_reassign} expr id [args]:exprs assign_op [value]:expr
971 | {super} qualified? kwsuper [args]:exprs
972 | {init} expr kwinit [args]:exprs
973 | {bra} expr [args]:exprs
974 | {bra_assign} expr [args]:exprs assign [value]:expr
975 | {bra_reassign} expr [args]:exprs assign_op [value]:expr
977 | {var_assign} id assign [value]:expr
978 | {var_reassign} id assign_op [value]:expr
979 | {range} expr [expr2]:expr annotations?
980 | {crange} obra expr [expr2]:expr cbra annotations?
981 | {orange} obra expr [expr2]:expr [cbra]:obra annotations?
982 | {array} obra [exprs]:expr* type? cbra annotations?
983 | {self} kwself annotations?
985 | {true} kwtrue annotations?
986 | {false} kwfalse annotations?
987 | {null} kwnull annotations?
988 | {dec_int} number annotations?
989 | {hex_int} hex_number annotations?
990 | {float} float annotations?
991 | {char} char annotations?
992 | {string} string annotations?
993 | {start_string} [string]:start_string
994 | {mid_string} [string]:mid_string
995 | {end_string} [string]:end_string
996 | {superstring} [exprs]:expr* annotations?
997 | {par} opar expr cpar annotations?
998 | {as_cast} expr kwas opar? type cpar?
999 | {as_notnull} expr kwas opar? kwnot kwnull cpar?
1000 | {isset_attr} kwisset expr [id]:attrid
1001 | {debug_type} kwdebug kwtype expr type
1002 | {vararg} expr dotdotdot
1004 | {methid} expr [id]:methid
1006 | {many} [exprs]:expr*
1009 = {list} [exprs]:expr*
1010 | {par} opar [exprs]:expr* cpar
1011 | {bra} obra [exprs]:expr* cbra
1014 = {plus} [op]:pluseq
1015 | {minus}[op]:minuseq
1016 | {star} [op]:stareq
1017 | {slash} [op]:slasheq
1018 | {percent} [op]:percenteq
1019 | {starstar} [op]:starstareq
1020 | {pipe} [op]:pipeeq
1021 | {caret} [op]:careteq
1027 module_name = quad? [path]:id* id;
1028 extern_calls = kwimport [extern_calls]:extern_call*
1032 | {local_prop} methid
1033 | {full_prop} type dot? methid
1035 | {cast_as} [from_type]:type dot? kwas [to_type]:type
1036 | {as_nullable} type kwas kwnullable
1037 | {as_not_nullable} type kwas kwnot kwnullable
1039 in_language = kwin string;
1040 extern_code_block = in_language? extern_code_segment;
1042 qualified = id* classid? ;
1046 annotations = at? opar? [items]:annotation* cpar?;
1048 annotation = doc? kwredef? visibility? atid opar? [args]:expr* cpar? annotations?;
1050 atid = {id} id | {kwextern} [id]:kwextern | {kwabstract} [id]:kwabstract | {kwimport} [id]:kwimport;
1052 /*****************************************************************************/