*/
/* This grammar defines the NIT language. */
+Package org.nitlanguage.gen;
/*****************************************************************************/
Helpers
cr = 13;
lf = 10;
any = [all - [cr + lf]];
+eol_helper = cr lf | cr | lf; // This takes care of different platforms
// characers inside strings and super-strings (atomaton powaa)
str_char
;
str_body = str_char*;
-eol_helper = cr lf | cr | lf; // This takes care of different platforms
+sstr_char
+ = [any - [''' + '\']]
+ | '\' any
+ ;
+
+sstr_body = sstr_char*;
+
+long_str_char = str_char | cr | lf;
+
+// because no substraction in sablecc3, complex long strings are difficult to express
+ls1 = '"' '"'? ;
+ls2 = '{' '{'? ;
+ls12 = ls1? (ls2 ls1)* ls2?;
+
+long_str_part
+ = ls12 long_str_char
+ ;
+
+long_str_body = long_str_part*;
+lsend1 = ls2? (ls1 ls2)* '"""';
+lsend2 = ls1? (ls2 ls1)* '{{{';
+
+long_sstr_char = sstr_char | cr | lf;
+long_sstr_part
+ = long_sstr_char
+ | ''' long_sstr_char
+ | ''' ''' long_sstr_char
+ ;
+
+long_sstr_body = long_sstr_part*;
+
+
+extern_code_char
+ = [all - ['`' + '\']]
+ | '\' all
+ ;
+extern_code_body = extern_code_char*;
/*****************************************************************************/
States
blank = (' ' | tab)+;
eol = eol_helper;
-comment = '#' any* eol_helper;
+comment = '#' any* eol_helper?;
-kwpackage = 'package'|'module';
+kwpackage = 'package';
+kwmodule = 'module';
kwimport = 'import';
kwclass = 'class';
kwabstract = 'abstract';
kwinterface = 'interface';
-kwuniversal = 'universal';
-kwspecial = 'special';
+kwenum = 'universal'|'enum';
kwend = 'end';
kwmeth = 'fun';
kwtype = 'type';
kwand = 'and';
kwor = 'or';
kwnot = 'not';
+kwimplies = 'implies';
kwreturn = 'return';
kwcontinue = 'continue';
kwbreak = 'break';
kwnullable = 'nullable';
kwisset = 'isset';
kwlabel = 'label';
+kwdebug = '__debug__';
opar = '(';
cpar = ')';
ne = '!=';
lt = '<';
le = '<=';
+ll = '<<';
gt = '>';
ge = '>=';
+gg = '>>';
starship = '<=>';
bang='!';
+at='@';
classid = uppercase letter*;
id = lowercase letter*;
number = digit+;
float = digit* '.' digit+;
-char = ''' [any - ''']* ''';
-string = '"' str_body '"';
-start_string = '"' str_body '{';
-mid_string = '}' str_body '{';
-end_string = '}' str_body '"';
+string = '"' str_body '"' | '"' '"' '"' long_str_body lsend1 | ''' ''' ''' long_sstr_body ''' ''' ''';
+start_string = '"' str_body '{' | '"' '"' '"' long_str_body lsend2;
+mid_string = '}' str_body '{' | '}' '}' '}' long_str_body lsend2;
+end_string = '}' str_body '"' | '}' '}' '}' long_str_body lsend1;
+char = (''' [[any - '''] - '\'] ''') | (''' '\' any ''');
+bad_string = ('"'|'}') str_body | '"' '"' '"' long_str_body | ''' ''' ''' long_sstr_body;
+bad_char = ''' '\'? any;
+extern_code_segment = '`' '{' extern_code_body '`' '}';
/*****************************************************************************/
Ignored Tokens
/* MODULES *******************************************************************/
module
- = packagedecl? [imports]:import* [classdefs]:classdef* implicit_top_class? implicit_main_class? {-> New module(packagedecl, [imports.import],[classdefs.classdef,implicit_top_class.classdef,implicit_main_class.classdef])};
+ = 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])};
-packagedecl
- = [doc]:no kwpackage no id [n2]:n1 {-> New packagedecl(doc.doc, kwpackage, id)};
+moduledecl
+ = [doc]:no kwmodule no module_name annotation_withend? [n2]:n1 {-> New moduledecl(doc.doc, kwmodule, module_name, annotation_withend.annotations)};
import
- = {std} [doc]:no visibility kwimport no id [n2]:n1 {-> New import.std(visibility, kwimport, id)}
- | {no} [doc]:no visibility kwimport no kwend [n2]:n1 {-> New import.no(visibility, kwimport, kwend)}
+ = {std} [doc]:no visibility kwimport no module_name annotation_withend? [n2]:n1 {-> New import.std(visibility, kwimport, module_name, annotation_withend.annotations)}
+ | {no} [doc]:no visibility kwimport no kwend [n2]:n1 {-> New import.no(visibility, kwimport, kwend)}
;
implicit_top_class {-> classdef}
/* CLASSES *******************************************************************/
classdef
- = [doc]:no redef visibility classkind no classid formaldefs? [specials]:special* propdefs* [n2]:no kwend {-> New classdef.std(doc.doc, redef.kwredef, visibility, classkind, classid, [formaldefs.formaldef], [specials.superclass], [propdefs.propdef])};
+ = [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)};
redef {-> kwredef?}
= kwredef? {-> kwredef};
classkind
= {concrete} kwclass
| {abstract} kwabstract kwclass
| {interface} kwinterface
- | {universal} kwuniversal
+ | {enum} kwenum
+ | {extern} kwextern kwclass?
;
formaldefs {-> formaldef*}
formaldefs_tail {-> formaldef}
= comma no formaldef {-> formaldef};
formaldef
- = classid typing? {-> New formaldef(classid, typing.type)};
+ = classid annotations? typing? {-> New formaldef(classid, typing.type, annotations)};
-special {-> superclass}
- = {special} no kwspecial [n2]:no type {-> New superclass(kwspecial, Null, type)}
- | {super} no kwsuper [n2]:no type {-> New superclass(Null, kwsuper, type)}
+superclass {-> superclass}
+ = {super} no kwsuper [n2]:no type annotation_withend? {-> New superclass(kwsuper, type, annotation_withend.annotations)}
;
propdefs~toplevel {-> propdef}
= propdef~toplevel n1 {-> propdef~toplevel.propdef}
;
propdef~toplevel {-> propdef}
- = {meth} [doc]:no redef visibility kwmeth methid signature kwdo stmtso kwend? {-> New propdef.concrete_meth(doc.doc, redef.kwredef, visibility, kwmeth, methid, signature, stmtso.expr)}
- | {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, assign_return.expr)}
-!toplevel| {deferred} [doc]:no redef visibility kwmeth methid signature kwis kwabstract {-> New propdef.deferred_meth(doc.doc, redef.kwredef, visibility, kwmeth, methid, signature.signature)}
+ = {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)}
+ | {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)}
+ | {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)}
+!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)}
!toplevel| {intern} [doc]:no redef visibility kwmeth methid signature kwis kwintern {-> New propdef.intern_meth(doc.doc, redef.kwredef, visibility, kwmeth, methid, signature.signature)}
- | {extern} [doc]:no redef visibility kwmeth methid signature kwis kwextern string? {-> New propdef.extern_meth(doc.doc, redef.kwredef, visibility, kwmeth, methid, signature.signature, string)}
-!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, typing.type, Null)}
-!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, typing.type, expr)}
-!toplevel| {init} [doc]:no redef visibility kwinit methid? signature kwdo stmtso kwend? {-> New propdef.concrete_init(doc.doc, redef.kwredef, visibility, kwinit, methid, signature, stmtso.expr)}
-!toplevel| {type} [doc]:no redef visibility kwtype classid typing {-> New propdef.type(doc.doc, redef.kwredef, visibility, kwtype, classid, typing.type)}
+ | {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)}
+ | {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)}
+!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)}
+!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)}
+!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)}
+!toplevel| {var4} [doc]:no redef visibility kwvar id typing? writable2? assign [n2]:no expr annotation_withend? {-> New propdef.attr(doc.doc, Null, writable2.able, redef.kwredef, visibility, kwvar, Null, id, typing.type, annotation_withend.annotations, expr.expr)}
+!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)}
+!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)}
+!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)}
+!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)}
+ ;
+annotation_withend {-> annotations}
+ = {oneliner} kwis many_annotations {-> many_annotations.annotations}
+ | {more} kwis n1 line_annotations kwend {-> line_annotations.annotations}
+ ;
+annotation_noend {-> annotations}
+ = {oneliner} kwis many_annotations {-> many_annotations.annotations}
+ | {more} kwis n1 line_annotations {-> line_annotations.annotations}
;
readable {-> able}
= redef kwreadable {-> New able.read(redef.kwredef, kwreadable)}
;
writable {-> able}
- = redef kwwritable {-> New able.write(redef.kwredef, kwwritable)}
+ = redef kwwritable {-> New able.write(redef.kwredef, Null, kwwritable)}
+ ;
+writable2 {-> able}
+ = redef visibility kwwritable {-> New able.write(redef.kwredef, visibility, kwwritable)}
;
visibility
| {ge} ge {-> New methid.ge(ge)}
| {lt} lt {-> New methid.lt(lt)}
| {gt} gt {-> New methid.gt(gt)}
+ | {ll} ll {-> New methid.ll(ll)}
+ | {gg} gg {-> New methid.gg(gg)}
| {bra} obra cbra {-> New methid.bra(obra, cbra)}
| {starship} starship {-> New methid.starship(starship)}
| {assign} id assign {-> New methid.assign(id, assign)}
;
signature~withret {-> signature}
- = params? typing closure_decls {-> New signature([params.param], typing.type, [closure_decls.closure_decl])}
- | {noclosures} params? typing no {-> New signature([params.param], typing.type, [])}
-!withret| {noret} params? closure_decls {-> New signature([params.param], Null, [closure_decls.closure_decl])}
-!withret| {noretnoclosures} params? no {-> New signature([params.param], Null, [])}
+ = opar no params? cpar typing [no2]:no {-> New signature(opar, [params.param], cpar, typing.type)}
+!withret| {noret} opar no params? cpar [no2]:no {-> New signature(opar, [params.param], cpar, Null)}
+ | {nopar} typing no {-> New signature(Null, [], Null, typing.type)}
+!withret| {noparnoret} no {-> New signature(Null, [], Null, Null)}
;
-signature_noclosures {-> signature}
- = params? typing? {-> New signature([params.param], typing.type, [])};
-
params {-> param*}
- = opar no param params_tail* [n2]:no cpar {-> [param, params_tail.param]}
- | {empty} opar no cpar {-> []}
+ = param params_tail* [n2]:no {-> [param, params_tail.param] }
;
params_tail {-> param}
= comma no param {-> param};
param
- = {untyped} id {-> New param(id, Null, Null)}
- | id typing dotdotdot? {-> New param(id, typing.type, dotdotdot)}
- ;
-
-closure_decls {->closure_decl*}
- = no closure_decl+ {-> [closure_decl]};
-closure_decl
- = kwbreak? bang id signature_noclosures n {-> New closure_decl(kwbreak, bang, id, signature_noclosures.signature, Null)}
- | {optionnal} kwbreak? bang id signature_noclosures kwdo stmtso n {-> New closure_decl(kwbreak, bang, id, signature_noclosures.signature, stmtso.expr)}
- | {assign} kwbreak? bang id signature_noclosures assign no assign_continue n {-> New closure_decl(kwbreak, bang, id, signature_noclosures.signature, assign_continue.expr)}
+ = {untyped} id annotations? {-> New param(id, Null, Null, annotations)}
+ | id annotations? typing dotdotdot? {-> New param(id, typing.type, dotdotdot, annotations)}
;
assign_return{-> expr}
= expr_final {-> New expr.return(Null, expr_final.expr)}
;
+extern_calls {-> extern_calls}
+ = kwimport no extern_call extern_call_tail* {-> New extern_calls( kwimport, [extern_call, extern_call_tail.extern_call] )}
+ ;
+extern_call_tail {-> extern_call}
+ = comma no extern_call {-> extern_call};
+extern_call {-> extern_call}
+ = {prop} extern_call_prop {-> extern_call_prop.extern_call}
+ | {cast} extern_call_cast {-> extern_call_cast.extern_call}
+ | {super} kwsuper {-> New extern_call.super( kwsuper )}
+ ;
+extern_call_prop {-> extern_call}
+ = {local} methid {-> New extern_call.local_prop( methid )}
+ | {full} type quad methid {-> New extern_call.full_prop( type, Null, methid )}
+ | {full2} type dot methid {-> New extern_call.full_prop( type, dot, methid )}
+ | {init} type {-> New extern_call.init_prop( type )}
+ ;
+extern_call_cast {-> extern_call}
+ = {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)}
+ | {as_nullable} type dot? kwas [n2]:no kwnullable {-> New extern_call.as_nullable( type, kwas, kwnullable)}
+ | {as_not_nullable} type dot? kwas [n2]:no kwnot [n3]:no kwnullable {-> New extern_call.as_not_nullable( type, kwas, kwnot, kwnullable)}
+ ;
+
+in_language = kwin string;
+extern_code_block = in_language? extern_code_segment;
+extern_code_body {-> extern_code_block} = no extern_code_block {-> extern_code_block};
/* TYPES *********************************************************************/
-type~nobra {-> type}
- = {simple} kwnullable? classid {-> New type(kwnullable, classid, [])}
-!nobra | {generic} kwnullable? classid obra no types [n2]:no cbra {-> New type(kwnullable, classid, [types.type])}
+type~nobra~nopar {-> type}
+ = {simple} kwnullable? classid annotations~nopar? {-> New type(kwnullable, classid, [], annotations~nopar.annotations)}
+!nobra | {generic} kwnullable? classid obra no types [n2]:no cbra annotations~nopar? {-> New type(kwnullable, classid, [types.type], annotations~nopar.annotations)}
;
types {-> type*}
= type types_tail* {-> [type, types_tail.type]};
/* STATMENTS *****************************************************************/
stmtso~withelse~withend {-> expr?}
- = {block} n stmtsn kwend {-> stmtsn.expr}
- | {emptyblock} n kwend {-> New expr.block([])}
- | {emptyoneline} kwend {-> New expr.block([])}
+ = {block} n stmtsnend {-> stmtsnend.expr}
+ | {emptyblock} n kwend {-> New expr.block([], kwend)}
+ | {emptyoneline} kwend {-> New expr.block([], kwend)}
!withend| {oneline} stmt~withelse {-> stmt~withelse.expr}
;
stmts {-> expr}
- = stmt stmts_tail* {-> New expr.block([stmt.expr, stmts_tail.expr])};
+ = stmt stmts_tail* {-> New expr.block([stmt.expr, stmts_tail.expr], Null)};
stmtsn {-> expr}
- = stmt stmts_tail* n {-> New expr.block([stmt.expr, stmts_tail.expr])};
+ = stmt stmts_tail* n {-> New expr.block([stmt.expr, stmts_tail.expr], Null)};
+stmtsnend {-> expr}
+ = stmt stmts_tail* n kwend {-> New expr.block([stmt.expr, stmts_tail.expr], kwend)};
stmts_tail {-> expr}
= n stmt {-> stmt.expr};
-stmt~withelse {-> expr}
+stmt~withelse~noexpr~nopar {-> expr}
= {vardecl} vardecl~withelse {-> vardecl~withelse.expr}
- | {assign} assignment~withelse {-> assignment~withelse.expr}
+ | {assign} assignment~withelse~nopar {-> assignment~withelse~nopar.expr}
| {return} kwreturn expr_final~withelse? {-> New expr.return(kwreturn, expr_final~withelse.expr)}
| {break} kwbreak label? expr_final~withelse? {-> New expr.break(kwbreak, label, expr_final~withelse.expr)}
| {abort} kwabort {-> New expr.abort(kwabort)}
| {continue} kwcontinue label? expr_final~withelse? {-> New expr.continue(kwcontinue, label, expr_final~withelse.expr)}
| {do} do~withelse {-> do~withelse.expr}
- | {if} if~withelse {-> if~withelse.expr}
+!noexpr | {if} if~withelse {-> if~withelse.expr}
| {while} while~withelse {-> while~withelse.expr}
| {loop} loop~withelse {-> loop~withelse.expr}
| {for} for~withelse {-> for~withelse.expr}
| {assert} assert~withelse {-> assert~withelse.expr}
- | {call} recv id args_nopar closure_defs~withelse? {-> New expr.call(recv.expr, id, [args_nopar.expr], [closure_defs~withelse.closure_def])}
- | {super} qualified? kwsuper args_nopar {-> New expr.super(qualified, kwsuper, [args_nopar.expr])}
- | {init} recv kwinit args_nopar {-> New expr.init(recv.expr, kwinit, [args_nopar.expr])}
+!noexpr | {call} recv qualified? id args_nopar {-> New expr.call(recv.expr, id, args_nopar.exprs)}
+!noexpr | {super} qualified? kwsuper args_nopar {-> New expr.super(qualified, kwsuper, args_nopar.exprs)}
+!noexpr | {init} recv qualified? kwinit args_nopar {-> New expr.init(recv.expr, kwinit, args_nopar.exprs)}
+ | {debug_type_is} kwdebug kwtype type column expr_final~withelse {-> New expr.debug_type(kwdebug, kwtype, expr_final~withelse.expr, type) }
;
label= kwlabel id;
-closure_defs~withelse {-> closure_def*}
- = {one} closure_def_last~withelse {-> [closure_def_last~withelse.closure_def]}
- | closure_def closure_defs~withelse {-> [closure_def, closure_defs~withelse.closure_def]}
- ;
-
-closure_def_last~withelse {-> closure_def}
- = bang [id]:closure_id idlist? kwdo stmtso_withend label {-> New closure_def(bang, id, [idlist.id], kwdo, stmtso_withend.expr, label)}
- | {nolabel} bang [id]:closure_id idlist? kwdo stmtso~withelse {-> New closure_def(bang, id, [idlist.id], kwdo, stmtso~withelse.expr, Null)}
- | {assign} bang [id]:closure_id idlist? assign no assign_continue~withelse {-> New closure_def(bang, id, [idlist.id], Null, assign_continue~withelse.expr, Null)}
- ;
-
-closure_def {-> closure_def}
- = bang [id]:closure_id idlist? kwdo n stmtsn {-> New closure_def(bang, id, [idlist.id], kwdo, stmtsn.expr, Null)}
- | {empty} bang [id]:closure_id idlist? kwdo n {-> New closure_def(bang, id, [idlist.id], kwdo, Null, Null)}
- ;
-closure_id
- = {simple} id
- | {break} kwbreak
- ;
-
assign_continue~withelse{-> expr}
= expr_final~withelse {-> New expr.continue(Null, Null, expr_final~withelse.expr)}
;
vardecl~withelse{-> expr}
- = kwvar id typing? {-> New expr.vardecl(kwvar, id, typing.type, Null, Null)}
- | {assign} kwvar id typing? assign no expr_final~withelse {-> New expr.vardecl(kwvar, id, typing.type, assign, expr_final~withelse.expr)}
+ = kwvar id annotations? typing? {-> New expr.vardecl(kwvar, id, typing.type, Null, Null, annotations)}
+ | {assign} kwvar id annotations? typing? assign no expr_final~withelse {-> New expr.vardecl(kwvar, id, typing.type, assign, expr_final~withelse.expr, annotations)}
;
-assignment~withelse {-> expr}
- = {attr} recv attrid assign expr_final~withelse {-> New expr.attr_assign(recv.expr, attrid, assign, expr_final~withelse.expr)}
- | {call} recv id args assign expr_final~withelse {-> New expr.call_assign(recv.expr, id, [args.expr], assign, expr_final~withelse.expr)}
- | {bra} expr_atom braargs assign expr_final~withelse {-> New expr.bra_assign(expr_atom.expr, [braargs.expr], assign, expr_final~withelse.expr)}
- | {attr_re} recv attrid assign_op expr_final~withelse {-> New expr.attr_reassign(recv.expr, attrid, assign_op, expr_final~withelse.expr)}
- | {call_re} recv id args assign_op expr_final~withelse {-> New expr.call_reassign(recv.expr, id, [args.expr], assign_op, expr_final~withelse.expr)}
- | {bra_re} expr_atom braargs assign_op expr_final~withelse {-> New expr.bra_reassign(expr_atom.expr, [braargs.expr], assign_op, expr_final~withelse.expr)}
+assignment~withelse~nopar {-> expr}
+ = {attr} recv~nopar qualified? attrid assign expr_final~withelse {-> New expr.attr_assign(recv~nopar.expr, attrid, assign, expr_final~withelse.expr)}
+ | {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)}
+ | {bra} expr_atom~nopar braargs assign expr_final~withelse {-> New expr.bra_assign(expr_atom~nopar.expr, braargs.exprs, assign, expr_final~withelse.expr)}
+ | {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)}
+ | {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)}
+ | {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)}
;
assign_op
= {plus} pluseq
;
elsepartblock {-> expr?}
= {else} kwelse stmtso {-> stmtso.expr}
- | {empty} kwend {-> Null}
+ | {empty} kwend {-> New expr.block([], kwend)}
;
loop~withelse {-> expr}
;
for~withelse {-> expr}
- = kwfor no id [n2]:no kwin [n3]:no expr [n4]:no kwdo stmtso_withend label {-> New expr.for(kwfor, id, expr, kwdo, stmtso_withend.expr, label)}
- | {nolabel} kwfor no id [n2]:no kwin [n3]:no expr [n4]:no kwdo stmtso~withelse {-> New expr.for(kwfor, id, expr, kwdo, stmtso~withelse.expr, Null)}
+ = 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)}
+ | {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)}
;
assert~withelse {-> expr}
/* EXPRESSIONS ***************************************************************/
expr_final~nopar~withelse~nobra {-> expr}
= expr~nopar~nobra {-> expr~nopar~nobra.expr}
- | {closure_call} recv~nobra id args closure_defs~withelse {-> New expr.call(recv~nobra.expr, id, [args.expr], [closure_defs~withelse.closure_def])}
-!nobra!nopar | {closure_bra} expr_atom braargs closure_defs~withelse {-> New expr.bra(expr_atom.expr, [braargs.expr], [closure_defs~withelse.closure_def])}
;
expr~nopar~nobra {-> expr}
expr_and~nopar~nobra {-> expr}
= expr_not~nopar~nobra {-> expr_not~nopar~nobra.expr}
- | {or} expr_and~nopar~nobra kwor no expr_not~nopar~nobra {-> New expr.or(expr_and~nopar~nobra.expr, expr_not~nopar~nobra.expr)}
- | {and} expr_and~nopar~nobra kwand no expr_not~nopar~nobra {-> New expr.and(expr_and~nopar~nobra.expr, expr_not~nopar~nobra.expr)}
- | {or_else} expr_and~nopar~nobra kwor kwelse no expr_not~nopar~nobra {-> New expr.or_else(expr_and~nopar~nobra.expr, expr_not~nopar~nobra.expr)}
+ | {:or} expr_and~nopar~nobra :kwor :no expr_not~nopar~nobra
+ | {:and} expr_and~nopar~nobra :kwand :no expr_not~nopar~nobra
+ | {:or_else} expr_and~nopar~nobra :kwor :kwelse :no expr_not~nopar~nobra
+ | {:implies} expr_and~nopar~nobra :kwimplies :no expr_not~nopar~nobra
;
expr_not~nopar~nobra {-> expr}
expr_eq~nopar~nobra {-> expr}
= expr_add~nopar~nobra {-> expr_add~nopar~nobra.expr}
- | {eq} expr_add~nopar~nobra eq no [expr2]:expr_add~nopar~nobra {-> New expr.eq(expr_add~nopar~nobra.expr, expr2.expr)}
- | {ee} expr_add~nopar~nobra kwis no [expr2]:expr_add~nopar~nobra {-> New expr.ee(expr_add~nopar~nobra.expr, expr2.expr)}
- | {ne} expr_add~nopar~nobra ne no [expr2]:expr_add~nopar~nobra {-> New expr.ne(expr_add~nopar~nobra.expr, expr2.expr)}
- | {lt} expr_add~nopar~nobra lt no [expr2]:expr_add~nopar~nobra {-> New expr.lt(expr_add~nopar~nobra.expr, expr2.expr)}
- | {le} expr_add~nopar~nobra le no [expr2]:expr_add~nopar~nobra {-> New expr.le(expr_add~nopar~nobra.expr, expr2.expr)}
- | {gt} expr_add~nopar~nobra gt no [expr2]:expr_add~nopar~nobra {-> New expr.gt(expr_add~nopar~nobra.expr, expr2.expr)}
- | {ge} expr_add~nopar~nobra ge no [expr2]:expr_add~nopar~nobra {-> New expr.ge(expr_add~nopar~nobra.expr, expr2.expr)}
- | {starship} expr_add~nopar~nobra starship no [expr2]:expr_add~nopar~nobra {-> New expr.starship(expr_add~nopar~nobra.expr, expr2.expr)}
- | {isa} expr_add~nopar~nobra kwisa no type~nobra {-> New expr.isa(expr_add~nopar~nobra.expr, type~nobra.type)}
+ | {:eq} expr_add~nopar~nobra :eq :no [expr2]:expr_add~nopar~nobra
+ | {:ne} expr_add~nopar~nobra :ne :no [expr2]:expr_add~nopar~nobra
+ | {:lt} expr_add~nopar~nobra :lt :no [expr2]:expr_add~nopar~nobra
+ | {:le} expr_add~nopar~nobra :le :no [expr2]:expr_add~nopar~nobra
+ | {:ll} expr_eq~nopar~nobra :ll :no [expr2]:expr_add~nopar~nobra
+ | {:gt} expr_add~nopar~nobra :gt :no [expr2]:expr_add~nopar~nobra
+ | {:ge} expr_add~nopar~nobra :ge :no [expr2]:expr_add~nopar~nobra
+ | {:gg} expr_eq~nopar~nobra :gg :no [expr2]:expr_add~nopar~nobra
+ | {:starship} expr_add~nopar~nobra :starship :no [expr2]:expr_add~nopar~nobra
+ | {:isa} expr_add~nopar~nobra :kwisa :no type~nobra
;
expr_add~nopar~nobra {-> expr}
= expr_mul~nopar~nobra {-> expr_mul~nopar~nobra.expr}
- | {plus} expr_add~nopar~nobra plus no [expr2]:expr_mul~nopar~nobra {-> New expr.plus(expr_add~nopar~nobra.expr, expr2.expr)}
- | {minus} expr_add~nopar~nobra minus no [expr2]:expr_mul~nopar~nobra {-> New expr.minus(expr_add~nopar~nobra.expr, expr2.expr)}
+ | {:plus} expr_add~nopar~nobra :plus :no [expr2]:expr_mul~nopar~nobra
+ | {:minus} expr_add~nopar~nobra :minus :no [expr2]:expr_mul~nopar~nobra
;
expr_mul~nopar~nobra {-> expr}
= expr_minus~nopar~nobra {-> expr_minus~nopar~nobra.expr}
- | {star} expr_mul~nopar~nobra star no [expr2]:expr_minus~nopar~nobra {-> New expr.star(expr_mul~nopar~nobra.expr, expr2.expr)}
- | {slash} expr_mul~nopar~nobra slash no [expr2]:expr_minus~nopar~nobra {-> New expr.slash(expr_mul~nopar~nobra.expr, expr2.expr)}
- | {percent} expr_mul~nopar~nobra percent no [expr2]:expr_minus~nopar~nobra {-> New expr.percent(expr_mul~nopar~nobra.expr, expr2.expr)}
+ | {:star} expr_mul~nopar~nobra :star :no [expr2]:expr_minus~nopar~nobra
+ | {:slash} expr_mul~nopar~nobra :slash :no [expr2]:expr_minus~nopar~nobra
+ | {:percent} expr_mul~nopar~nobra :percent :no [expr2]:expr_minus~nopar~nobra
;
expr_minus~nopar~nobra {-> expr}
= expr_new~nopar~nobra {-> expr_new~nopar~nobra.expr}
- | {minus} minus no expr_minus~nopar~nobra {-> New expr.uminus(minus, expr_minus~nopar~nobra.expr)}
- | {once} kwonce no expr_minus~nopar~nobra {-> New expr.once(kwonce, expr_minus~nopar~nobra.expr)}
+ | {:uminus} minus :no expr_minus~nopar~nobra
+ | {:once} kwonce :no expr_minus~nopar~nobra
;
expr_new~nopar~nobra {-> expr}
= expr_atom~nopar~nobra {-> expr_atom~nopar~nobra.expr}
- | {new} kwnew no type~nobra args {-> New expr.new(kwnew, type~nobra.type, Null, [args.expr])}
- | {isset_attr} kwisset recv~nopar~nobra attrid {-> New expr.isset_attr(kwisset, recv~nopar~nobra.expr, attrid)}
+ | {new} kwnew no type~nobra_nopar args {-> New expr.new(kwnew, type~nobra_nopar.type, Null, args.exprs)}
+ | {isset_attr} kwisset recv~nopar~nobra qualified? attrid {-> New expr.isset_attr(kwisset, recv~nopar~nobra.expr, attrid)}
;
expr_atom~nopar~nobra {-> expr}
- = {attr} recv~nopar~nobra attrid {-> New expr.attr(recv~nopar~nobra.expr, attrid)}
- | {call} recv~nopar~nobra id args {-> New expr.call(recv~nopar~nobra.expr, id, [args.expr], [])}
- | {super} qualified? kwsuper args {-> New expr.super(qualified, kwsuper, [args.expr])}
- | {init} recv~nopar~nobra kwinit args {-> New expr.init(recv~nopar~nobra.expr, kwinit, [args.expr])}
-!nobra | {bra} expr_atom~nopar braargs {-> New expr.bra(expr_atom~nopar.expr, [braargs.expr], [])}
- | {new} kwnew no type~nobra dot [n2]:no id args {-> New expr.new(kwnew, type~nobra.type, id, [args.expr])}
-// FIXME: Why are these 3 !nopar mandatory?
-!nobra!nopar | {range} obra no expr [n2]:no dotdot [n3]:no [expr2]:expr_nobra [n4]:no cbra {-> New expr.crange(expr, expr2.expr)}
-!nobra!nopar | {orange} obra no expr [n2]:no dotdot [n3]:no [expr2]:expr_nobra [n4]:no [cbra]:obra {-> New expr.orange(expr, expr2.expr)}
-!nobra!nopar | {array} braargs {-> New expr.array([braargs.expr])}
- | {self} kwself {-> New expr.self(kwself)}
- | {true} kwtrue {-> New expr.true(kwtrue)}
- | {false} kwfalse {-> New expr.false(kwfalse)}
- | {null} kwnull {-> New expr.null(kwnull)}
- | {int} number {-> New expr.int(number)}
- | {float} float {-> New expr.float(float)}
- | {char} char {-> New expr.char(char)}
- | {string} string {-> New expr.string(string)}
+ = {attr} recv~nopar~nobra qualified? attrid {-> New expr.attr(recv~nopar~nobra.expr, attrid)}
+ | {call} recv~nopar~nobra qualified? id args {-> New expr.call(recv~nopar~nobra.expr, id, args.exprs)}
+ | {super} qualified? kwsuper args {-> New expr.super(qualified, kwsuper, args.exprs)}
+ | {init} recv~nopar~nobra kwinit args {-> New expr.init(recv~nopar~nobra.expr, kwinit, args.exprs)}
+!nobra | {bra} expr_atom~nopar braargs {-> New expr.bra(expr_atom~nopar.expr, braargs.exprs)}
+ | {new} kwnew no type~nobra_nopar dot [n2]:no qualified? id args {-> New expr.new(kwnew, type~nobra_nopar.type, id, args.exprs)}
+// !nopar to unambiguise 'foo[5].bar' between '(foo[5]).bar' and 'foo([5].bar),
+!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)}
+!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)}
+!nobra!nopar | {array} braargs annotations? {-> New expr.array(braargs.exprs, annotations)}
+ | {self} kwself annotations? {-> New expr.self(kwself, annotations)}
+ | {true} kwtrue annotations? {-> New expr.true(kwtrue, annotations)}
+ | {false} kwfalse annotations? {-> New expr.false(kwfalse, annotations)}
+ | {null} kwnull annotations? {-> New expr.null(kwnull, annotations)}
+ | {int} number annotations? {-> New expr.int(number, annotations)}
+ | {float} float annotations? {-> New expr.float(float, annotations)}
+ | {char} char annotations? {-> New expr.char(char, annotations)}
+ | {string} string annotations? {-> New expr.string(string, annotations)}
| {superstring} superstring {-> superstring.expr}
-!nopar | {par} opar expr cpar {-> expr}
- | {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, type)}
- | {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, kwnot, kwnull)}
+!nopar | {par} opar no expr [n2]:no cpar annotations? {-> New expr.par(opar, expr, cpar, annotations)}
+ | {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)}
+ | {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)}
;
superstring {-> expr}
- = superstring_start superstring_middle* superstring_end {-> New expr.superstring([superstring_start.expr, superstring_middle.expr, superstring_end.expr])};
+ = superstring_start superstring_middle* superstring_end annotations? {-> New expr.superstring([superstring_start.expr, superstring_middle.expr, superstring_end.expr], annotations)};
superstring_start {-> expr*}
= start_string_p no expr [n2]:no {-> [start_string_p.expr, expr]};
start_string_p {-> expr}
superstring_end {-> expr}
= end_string {-> New expr.end_string(end_string)};
+/* ANNOTATIONS *******************************************************************/
+
+annotations~nopar {-> annotations}
+ = {one} at one_annotation~nopar {-> New annotations(at, Null, [one_annotation~nopar.annotation], Null)}
+ | {many} at opar no annotation_list [n2]:no cpar {-> New annotations(at, opar, [annotation_list.annotation], cpar)}
+ ;
+
+one_annotation~nopar {-> annotation}
+ = {alone} atid annotations~nopar? {-> New annotation(atid, Null, [], Null, annotations~nopar.annotations)}
+// !nopar to unambiguise 'new T@foo(bar)' between 'new T@(foo(bar))' and 'new (T@foo)(bar)'
+!nopar | {args} atid opar no at_args [n2]:no cpar annotations~nopar? {-> New annotation(atid, opar, [at_args.at_arg], cpar, annotations~nopar.annotations)}
+ ;
+
+many_annotations {-> annotations}
+ = {many} annotation_list {-> New annotations(Null, Null, [annotation_list.annotation], Null)}
+ ;
+
+annotation_list {-> annotation*}
+ = {many} one_annotation annotations_tail* {-> [one_annotation.annotation, annotations_tail.annotation] }
+ ;
+
+line_annotations~forclass {-> annotations}
+ = line_annotation~forclass+ {-> New annotations(Null, Null, [line_annotation~forclass.annotation], Null) }
+ ;
+line_annotation~forclass {-> annotation}
+ = [doc]:no atid~forclass annotations? n1 {-> New annotation(atid~forclass.atid, Null, [], Null, annotations)}
+ | {args} [doc]:no atid~forclass opar no at_args cpar annotations? n1 {-> New annotation(atid~forclass.atid, opar, [at_args.at_arg], cpar, annotations)}
+ | {nopar} [doc]:no atid~forclass at_args_nopar n1 {-> New annotation(atid~forclass.atid, Null, [at_args_nopar.at_arg], Null, Null)}
+ ;
+
+annotations_tail {-> annotation}
+ = comma no one_annotation {-> one_annotation.annotation}
+ ;
+
+at_args~nopar {-> at_arg* }
+ = {many} at_arg~nopar at_args_tail* {-> [at_arg~nopar.at_arg, at_args_tail.at_arg]}
+ ;
+
+at_args_tail {-> at_arg}
+ = comma no at_arg {-> at_arg}
+ ;
+
+at_arg~nopar {-> at_arg}
+ = {type} type {-> New at_arg.type(type)}
+ | {expr} expr~nopar {-> New at_arg.expr(expr~nopar.expr)}
+ | {stmt} stmt_noexpr~nopar {-> New at_arg.expr(stmt_noexpr~nopar.expr)}
+!nopar | {at} annotations {-> New at_arg.at(annotations.annotations)}
+ ;
+
+atid~forclass {-> atid}
+ = {id} id {-> New atid.id(id)}
+//!forclass | {kwextern} qualified? kwextern {-> New atid.kwextern(kwextern)}
+//!forclass | {kwintern} qualified? kwintern {-> New atid.kwintern(kwintern)}
+!forclass | {kwreadable} kwreadable {-> New atid.kwreadable(kwreadable)}
+!forclass | {kwwritable} kwwritable {-> New atid.kwwritable(kwwritable)}
+ | {kwimport} kwimport {-> New atid.kwimport(kwimport)}
+ ;
+
/* MISC **********************************************************************/
recv~nopar~nobra {-> expr}
| {implicit} {-> New expr.implicit_self()}
;
-args {-> expr*}
- = opar no expr [n2]:no args_tail* cpar {-> [expr, args_tail.expr]}
- | {emptypar} opar no cpar {-> []}
- | {empty} {-> []}
+args {-> exprs}
+ = opar no expr_list cpar {-> New exprs.par(opar, [expr_list.expr], cpar) }
+ | {emptypar} opar no cpar {-> New exprs.par(opar, [], cpar) }
+ | {empty} {-> New exprs.list([])}
;
-args_nopar {-> expr*}
- = opar no expr [n2]:no args_tail* cpar {-> [expr, args_tail.expr]}
- | {onearg} expr_nopar {-> [expr_nopar.expr]}
- | {emptypar} opar no cpar {-> []}
- | {empty} {-> []}
+args_nopar {-> exprs}
+ = opar no expr_list cpar {-> New exprs.par(opar, [expr_list.expr], cpar) }
+ | {onearg} expr_nopar {-> New exprs.list([expr_nopar.expr])}
+ | {emptypar} opar no cpar {-> New exprs.par(opar, [], cpar) }
+ | {empty} {-> New exprs.list([])}
;
-braargs {-> expr*}
- = obra no expr [n2]:no args_tail* cbra {-> [expr, args_tail.expr]};
-args_tail {-> expr}
+braargs {-> exprs}
+ = obra no expr_list cbra {-> New exprs.bra(obra, [expr_list.expr], cbra)};
+expr_list {-> expr*}
+ = expr [n2]:no expr_tail* {-> [expr, expr_tail.expr]};
+expr_tail {-> expr}
= comma no expr [n2]:no {-> expr};
idlist {-> id*}
- = opar idlist_nopar cpar {-> [idlist_nopar.id]}
+ = opar no idlist_nopar [n2]:no cpar {-> [idlist_nopar.id]}
| {nopar} idlist_nopar {-> [idlist_nopar.id]}
;
idlist_nopar {-> id*}
| {more} idlist_nopar no comma [n2]:no id {-> [idlist_nopar.id, id]}
;
+module_name {-> module_name}
+ = {mod} modquad* id {-> New module_name(Null, [modquad.id], id)}
+ | {root} quad no modquad* id {-> New module_name(quad, [modquad.id], id)}
+ ;
+
qualified
= {cla} modquad* classquad {-> New qualified([modquad.id], classquad.classid)}
| {mod} modquad+ {-> New qualified([modquad.id], Null)}
Abstract Syntax Tree
/*****************************************************************************/
-module = packagedecl? [imports]:import* [classdefs]:classdef*;
+module = moduledecl? [imports]:import* [extern_code_blocks]:extern_code_block* [classdefs]:classdef*;
-packagedecl
- = doc? kwpackage id;
+moduledecl
+ = doc? kwmodule [name]:module_name annotations?;
-import = {std} visibility kwimport id
+import = {std} visibility kwimport [name]:module_name annotations?
| {no} visibility kwimport kwend
;
| {intrude} kwintrude
;
-classdef= {std} doc? kwredef? visibility classkind [id]:classid? [formaldefs]:formaldef* [superclasses]:superclass* [propdefs]:propdef*
+classdef= {std} doc? kwredef? visibility classkind [id]:classid? [formaldefs]:formaldef* annotations? extern_code_block? [superclasses]:superclass* [propdefs]:propdef* kwend
| {top} [propdefs]:propdef*
| {main} [propdefs]:propdef*
;
= {concrete} kwclass
| {abstract} kwabstract kwclass
| {interface} kwinterface
- | {universal} kwuniversal
+ | {enum} kwenum
+ | {extern} kwextern kwclass?
;
-formaldef = [id]:classid type?;
-superclass = kwspecial? kwsuper? type;
+formaldef = [id]:classid type? annotations?;
+superclass = kwsuper type annotations?;
-propdef = {attr} doc? [readable]:able? [writable]:able? kwredef? visibility kwvar [id]:attrid type? expr?
- | {meth} doc? kwredef? visibility methid signature
- | {deferred_meth} doc? kwredef? visibility kwmeth methid signature
- | {intern_meth} doc? kwredef? visibility kwmeth methid signature
- | {extern_meth} doc? kwredef? visibility kwmeth methid signature [extern]:string?
- | {concrete_meth} doc? kwredef? visibility kwmeth methid signature [block]:expr?
- | {concrete_init} doc? kwredef? visibility kwinit methid? signature [block]:expr?
- | {main_meth} kwredef? [block]:expr?
- | {type} doc? kwredef? visibility kwtype [id]:classid type
+propdef = {attr} doc? [readable]:able? [writable]:able? kwredef? visibility kwvar [id]:attrid? [id2]:id? type? annotations? expr?
+ | {meth} doc? kwredef? visibility methid signature
+ | {deferred_meth} doc? kwredef? visibility kwmeth methid signature annotations?
+ | {intern_meth} doc? kwredef? visibility kwmeth methid signature
+ | {extern_meth} doc? kwredef? visibility kwmeth methid signature [extern]:string? extern_calls? extern_code_block?
+ | {concrete_meth} doc? kwredef? visibility kwmeth methid signature annotations? [block]:expr?
+ | {concrete_init} doc? kwredef? visibility kwinit methid? signature annotations? [block]:expr?
+ //| {concrete_new} doc? kwredef? visibility kwnew methid? signature [block]:expr?
+ | {extern_init} doc? kwredef? visibility kwnew methid? signature [extern]:string? extern_calls? extern_code_block?
+ | {main_meth} kwredef? [block]:expr?
+ | {type} doc? kwredef? visibility kwtype [id]:classid type annotations?
;
able = {read} kwredef? kwreadable
- | {write} kwredef? kwwritable
+ | {write} kwredef? visibility? kwwritable
;
-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 | {bra} obra cbra | {starship} starship | {assign} id assign | {braassign} obra cbra assign;
+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;
-signature = [params]:param* type? [closure_decls]:closure_decl*;
+signature = opar? [params]:param* cpar? type?;
-param = id type? dotdotdot?
+param = id type? dotdotdot? annotations?
;
-closure_decl = kwbreak? bang id signature expr?
- ;
-
-type = kwnullable? [id]:classid [types]:type*;
+type = kwnullable? [id]:classid [types]:type* annotations?;
label = kwlabel id;
-expr = {block} expr*
- | {vardecl} kwvar id type? assign? expr?
+expr = {block} expr* kwend?
+ | {vardecl} kwvar id type? assign? expr? annotations?
| {return} kwreturn? expr?
| {break} kwbreak label? expr?
| {abort} kwabort
| {ifexpr} kwif expr kwthen [then]:expr kwelse [else]:expr
| {while} kwwhile expr kwdo [block]:expr? label?
| {loop} kwloop [block]:expr? label?
- | {for} kwfor id expr kwdo [block]:expr? label?
+ | {for} kwfor [ids]:id* expr kwdo [block]:expr? label?
| {assert} kwassert id? expr [else]:expr?
| {once} kwonce expr
| {send} expr
| {or} expr [expr2]:expr
| {and} expr [expr2]:expr
| {or_else} expr [expr2]:expr
+ | {implies} expr [expr2]:expr
| {not} kwnot expr
| {eq} expr [expr2]:expr
- | {ee} expr [expr2]:expr
| {ne} expr [expr2]:expr
| {lt} expr [expr2]:expr
| {le} expr [expr2]:expr
+ | {ll} expr [expr2]:expr
| {gt} expr [expr2]:expr
| {ge} expr [expr2]:expr
+ | {gg} expr [expr2]:expr
| {isa} expr type
| {plus} expr [expr2]:expr
| {minus} expr [expr2]:expr
| {slash} expr [expr2]:expr
| {percent} expr [expr2]:expr
| {uminus} minus expr
- | {new} kwnew type id? [args]:expr*
+ | {new} kwnew type id? [args]:exprs
| {attr} expr [id]:attrid
| {attr_assign} expr [id]:attrid assign [value]:expr
| {attr_reassign} expr [id]:attrid assign_op [value]:expr
- | {call} expr id [args]:expr* [closure_defs]:closure_def*
- | {call_assign} expr id [args]:expr* assign [value]:expr
- | {call_reassign} expr id [args]:expr* assign_op [value]:expr
- | {super} qualified? kwsuper [args]:expr*
- | {init} expr kwinit [args]:expr*
- | {bra} expr [args]:expr* [closure_defs]:closure_def*
- | {bra_assign} expr [args]:expr* assign [value]:expr
- | {bra_reassign} expr [args]:expr* assign_op [value]:expr
- | {closure_call} id [args]:expr* [closure_defs]:closure_def*
+ | {call} expr id [args]:exprs
+ | {call_assign} expr id [args]:exprs assign [value]:expr
+ | {call_reassign} expr id [args]:exprs assign_op [value]:expr
+ | {super} qualified? kwsuper [args]:exprs
+ | {init} expr kwinit [args]:exprs
+ | {bra} expr [args]:exprs
+ | {bra_assign} expr [args]:exprs assign [value]:expr
+ | {bra_reassign} expr [args]:exprs assign_op [value]:expr
| {var} id
| {var_assign} id assign [value]:expr
| {var_reassign} id assign_op [value]:expr
- | {range} expr [expr2]:expr
- | {crange} expr [expr2]:expr
- | {orange} expr [expr2]:expr
- | {array} [exprs]:expr*
- | {self} kwself
+ | {range} expr [expr2]:expr annotations?
+ | {crange} obra expr [expr2]:expr cbra annotations?
+ | {orange} obra expr [expr2]:expr [cbra]:obra annotations?
+ | {array} [exprs]:exprs annotations?
+ | {self} kwself annotations?
| {implicit_self}
- | {true} kwtrue
- | {false} kwfalse
- | {null} kwnull
- | {int} number
- | {float} float
- | {char} char
- | {string} string
+ | {true} kwtrue annotations?
+ | {false} kwfalse annotations?
+ | {null} kwnull annotations?
+ | {int} number annotations?
+ | {float} float annotations?
+ | {char} char annotations?
+ | {string} string annotations?
| {start_string} [string]:start_string
| {mid_string} [string]:mid_string
| {end_string} [string]:end_string
- | {superstring} [exprs]:expr*
- | {par} expr
- | {as_cast} expr kwas type
- | {as_notnull} expr kwas kwnot kwnull
+ | {superstring} [exprs]:expr* annotations?
+ | {par} opar expr cpar annotations?
+ | {as_cast} expr kwas opar type cpar
+ | {as_notnull} expr kwas opar kwnot kwnull cpar
| {isset_attr} kwisset expr [id]:attrid
+ | {debug_type} kwdebug kwtype expr type
+ ;
+exprs
+ = {list} [exprs]:expr*
+ | {par} opar [exprs]:expr* cpar
+ | {bra} obra [exprs]:expr* cbra
;
assign_op
= {plus} pluseq
| {minus} minuseq
;
-closure_def
- = bang [id]:closure_id [ids]:id* kwdo? expr? label?
+module_name = quad? [path]:id* id;
+extern_calls = kwimport [extern_calls]:extern_call*
;
-closure_id
- = {simple} id
- | {break} kwbreak
+extern_call =
+ | {super} kwsuper
+ | {local_prop} methid
+ | {full_prop} type dot? methid
+ | {init_prop} type
+ | {cast_as} [from_type]:type dot? kwas [to_type]:type
+ | {as_nullable} type kwas kwnullable
+ | {as_not_nullable} type kwas kwnot kwnullable
;
+in_language = kwin string;
+extern_code_block = in_language? extern_code_segment;
qualified = id* classid? ;
doc = comment+;
+annotations = at? opar? [items]:annotation* cpar?;
+
+annotation = atid opar? [args]:at_arg* cpar? annotations?;
+
+at_arg
+ = {type} type
+ | {expr} expr
+ | {at} annotations
+ ;
+atid = {id} id | {kwextern} [id]:kwextern | {kwintern} [id]:kwintern | {kwreadable} [id]:kwreadable | {kwwritable} [id]:kwwritable | {kwimport} [id]:kwimport;
+
/*****************************************************************************/