X-Git-Url: http://nitlanguage.org diff --git a/src/parser/nit.sablecc3xx b/src/parser/nit.sablecc3xx index 52fc5ec..e47b96c 100644 --- a/src/parser/nit.sablecc3xx +++ b/src/parser/nit.sablecc3xx @@ -145,6 +145,7 @@ kwas = 'as'; kwnullable = 'nullable'; kwisset = 'isset'; kwlabel = 'label'; +kwwith = 'with'; kwdebug = '__debug__'; opar = '('; @@ -157,6 +158,15 @@ quad = '::'; assign = '='; pluseq = '+='; minuseq = '-='; +stareq = '*='; +slasheq = '/='; +percenteq = '%='; +starstareq = '**='; +pipeeq = '|='; +careteq = '^='; +ampeq = '&='; +lleq = '<<='; +ggeq = '>>='; dotdotdot = '...'; dotdot = '..'; dot = '.'; @@ -166,6 +176,10 @@ star = '*'; starstar = '**'; slash = '/'; percent = '%'; +pipe = '|'; +caret = '^'; +amp = '&'; +tilde = '~'; eq = '=='; ne = '!='; lt = '<'; @@ -219,7 +233,7 @@ import topdef {-> classdef} = {classdef} classdef {-> classdef} - | propdefs_toplevel {-> New classdef.top([propdefs_toplevel.propdef])} + | propdef_toplevel n1 {-> New classdef.top([propdef_toplevel.propdef])} ; implicit_main_class {-> classdef?} @@ -233,7 +247,7 @@ implicit_main_meth {-> propdef} /* CLASSES *******************************************************************/ classdef - = [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)}; + = [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)}; redef {-> kwredef?} = kwredef? {-> kwredef}; classkind @@ -253,12 +267,17 @@ formaldefs_tail {-> formaldef} formaldef = classid annotations? typing_o {-> New formaldef(classid, typing_o.type, annotations)}; -superclass {-> superclass} - = {super} no kwsuper [n2]:no type annotation_withend {-> New superclass(kwsuper, type, annotation_withend.annotations)} +superclass {-> propdef} + = {super} [doc]:no redef visibility kwsuper [n2]:no type annotation_withend {-> New propdef.super(doc.doc, redef.kwredef, visibility, kwsuper, type, annotation_withend.annotations)} ; -propdefs~toplevel {-> propdef} - = propdef~toplevel n1 {-> propdef~toplevel.propdef} +propdefs {-> propdef*} + = propdefn+ no {-> [propdefn.propdef]} + | {super} superclass {-> [superclass.propdef]} + | {empty} no {-> []} + ; +propdefn {-> propdef} + = propdef n1 {-> propdef.propdef} ; propdef~toplevel {-> propdef} = {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)} @@ -272,6 +291,8 @@ propdef~toplevel {-> propdef} !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)} !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_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)} +!toplevel| {annot} line_annotation_forclass {-> line_annotation_forclass.propdef} +!toplevel| {super} superclass {-> superclass.propdef} ; annotation_withend~nonull {-> annotations?} = {oneliner} kwis many_annotations {-> many_annotations.annotations} @@ -298,6 +319,10 @@ methid~noid {-> methid} | {starstar} starstar {-> New methid.starstar(starstar)} | {slash} slash {-> New methid.slash(slash)} | {percent} percent {-> New methid.percent(percent)} + | {pipe} pipe {-> New methid.pipe(pipe)} + | {caret} caret {-> New methid.caret(caret)} + | {amp} amp {-> New methid.amp(amp)} + | {tilde} tilde {-> New methid.tilde(tilde)} | {eq} eq {-> New methid.eq(eq)} | {ne} ne {-> New methid.ne(ne)} | {le} le {-> New methid.le(le)} @@ -409,6 +434,7 @@ stmt~withelse~noexpr~nopar {-> expr} | {while} while~withelse {-> while~withelse.expr} | {loop} loop~withelse {-> loop~withelse.expr} | {for} for~withelse {-> for~withelse.expr} + | {with} with~withelse {-> with~withelse.expr} | {assert} assert~withelse {-> assert~withelse.expr} !noexpr | {call} recv qid args_nopar {-> New expr.call(recv.expr, qid.id, args_nopar.exprs)} !noexpr | {super} qualified_o kwsuper args_nopar {-> New expr.super(qualified_o.qualified, kwsuper, args_nopar.exprs)} @@ -434,6 +460,15 @@ assignment~nopar {-> expr} assign_op = {plus} pluseq | {minus} minuseq + | {star} stareq + | {slash} slasheq + | {percent} percenteq + | {starstar} starstareq + | {pipe} pipeeq + | {caret} careteq + | {amp} ampeq + | {ll} lleq + | {gg} ggeq ; do~withelse {-> expr} @@ -467,6 +502,16 @@ for~withelse {-> expr} | {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)} ; +with~withelse {-> expr} + = kwwith no withexpr [n4]:no kwdo stmtso_withend label {-> New expr.with(kwwith, withexpr.expr, kwdo, stmtso_withend.expr, label)} + | {nolabel} kwwith no withexpr [n4]:no kwdo stmtso~withelse {-> New expr.with(kwwith, withexpr.expr, kwdo, stmtso~withelse.expr, Null)} + ; + +withexpr {-> expr} + = {assign} id annotations? typing_o assign no expr {-> New expr.vardecl(Null, id, typing_o.type, assign, expr.expr, annotations)} + | expr {-> expr} + ; + assert~withelse {-> expr} = {else} kwassert assertid? expr kwelse stmtso~withelse {-> New expr.assert(kwassert, assertid.id, expr, stmtso~withelse.expr)} !withelse| {noelse} kwassert assertid? expr {-> New expr.assert(kwassert, assertid.id, expr, Null)} @@ -482,10 +527,10 @@ 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 - | {: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 + | {: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} @@ -494,40 +539,61 @@ 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 - | {: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_bitor~nopar~nobra {-> expr_bitor~nopar~nobra.expr} + | {:eq} expr_bitor~nopar~nobra eq :no [expr2]:expr_bitor~nopar~nobra + | {:ne} expr_bitor~nopar~nobra ne :no [expr2]:expr_bitor~nopar~nobra + | {:lt} expr_bitor~nopar~nobra lt :no [expr2]:expr_bitor~nopar~nobra + | {:le} expr_bitor~nopar~nobra le :no [expr2]:expr_bitor~nopar~nobra + | {:gt} expr_bitor~nopar~nobra gt :no [expr2]:expr_bitor~nopar~nobra + | {:ge} expr_bitor~nopar~nobra ge :no [expr2]:expr_bitor~nopar~nobra + | {:starship} expr_bitor~nopar~nobra starship :no [expr2]:expr_bitor~nopar~nobra + | {:isa} expr_bitor~nopar~nobra kwisa :no type~nobra + ; + +expr_bitor~nopar~nobra {-> expr} + = [expr]:expr_bitxor~nopar~nobra {-> expr.expr} + | {:pipe} expr_bitor~nopar~nobra pipe :no [expr2]:expr_bitxor~nopar~nobra + ; + +expr_bitxor~nopar~nobra {-> expr} + = [expr]:expr_bitand~nopar~nobra {-> expr.expr} + | {:caret} expr_bitxor~nopar~nobra caret :no [expr2]:expr_bitand~nopar~nobra + ; + +expr_bitand~nopar~nobra {-> expr} + = [expr]:expr_shift~nopar~nobra {-> expr.expr} + | {:amp} expr_bitand~nopar~nobra amp :no [expr2]:expr_shift~nopar~nobra + ; + +expr_shift~nopar~nobra {-> expr} + = [expr]:expr_add~nopar~nobra {-> expr.expr} + | {:ll} expr_shift~nopar~nobra ll :no [expr2]:expr_add~nopar~nobra + | {:gg} expr_shift~nopar~nobra gg :no [expr2]:expr_add~nopar~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 - | {:minus} expr_add~nopar~nobra :minus :no [expr2]:expr_mul~nopar~nobra + | {: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_pow~nopar~nobra {-> expr_pow~nopar~nobra.expr} - | {:star} expr_mul~nopar~nobra :star :no [expr2]:expr_pow~nopar~nobra - | {:slash} expr_mul~nopar~nobra :slash :no [expr2]:expr_pow~nopar~nobra - | {:percent} expr_mul~nopar~nobra :percent :no [expr2]:expr_pow~nopar~nobra + | {:star} expr_mul~nopar~nobra star :no [expr2]:expr_pow~nopar~nobra + | {:slash} expr_mul~nopar~nobra slash :no [expr2]:expr_pow~nopar~nobra + | {:percent} expr_mul~nopar~nobra percent :no [expr2]:expr_pow~nopar~nobra ; expr_pow~nopar~nobra {-> expr} = expr_minus~nopar~nobra {-> expr_minus~nopar~nobra.expr} - | {:starstar} expr_minus~nopar~nobra :starstar :no [expr2]:expr_pow~nopar~nobra + | {:starstar} expr_minus~nopar~nobra starstar :no [expr2]:expr_pow~nopar~nobra ; expr_minus~nopar~nobra {-> expr} = expr_new~nopar~nobra {-> expr_new~nopar~nobra.expr} | {:uminus} minus expr_minus~nobra + | {:uplus} plus expr_minus~nobra + | {:utilde} tilde expr_minus~nobra | {:once} kwonce :no expr_minus~nobra ; @@ -548,7 +614,11 @@ expr_atom~nopar~nobra {-> 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, 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)} | {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)} - | {vararg} [expr]:expr_atom~nopar~nobra dotdotdot {-> New expr.vararg(expr.expr, dotdotdot)} + ; + +arg~nopar~nobra {-> expr} + = [expr]:expr~nopar~nobra {-> expr.expr} + | {vararg} [expr]:expr~nopar~nobra dotdotdot {-> New expr.vararg(expr.expr, dotdotdot)} ; expr_single~nopar~nobra {-> expr} @@ -590,6 +660,8 @@ array_items_tail {-> expr} ; array_item {-> expr} = expr no {-> expr} + | {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)} + | {if} kwif [n1]:no expr [n2]:no kwthen [n3]:no [then]:array_item {-> New expr.if(kwif, expr, then.expr, Null)} ; superstring {-> expr} @@ -657,13 +729,10 @@ line_annotation {-> annotation} | {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)} | {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)} ; -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(doc.doc, Null, Null, atid_forclass.atid, Null, [], Null, annotations)} - | {args} [doc]:no atid_forclass opar no at_args cpar annotations? n1 {-> New annotation(doc.doc, Null, Null, atid_forclass.atid, opar, [at_args.expr], cpar, annotations)} - | {nopar} [doc]:no atid_forclass at_args_nopar n1 {-> New annotation(doc.doc, Null, Null, atid_forclass.atid, Null, [at_args_nopar.expr], Null, Null)} +line_annotation_forclass {-> propdef} + = [doc]:no atid_forclass annotations? {-> New propdef.annot(doc.doc, Null, Null, atid_forclass.atid, Null, [], Null, annotations)} + | {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)} + | {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)} ; at_args~nopar {-> expr* } @@ -712,12 +781,10 @@ args_nopar {-> exprs} ; braargs {-> exprs} = obra no expr_list cbra {-> New exprs.bra(obra, [expr_list.expr], cbra)}; -args_list {-> exprs} - = expr_list {-> New exprs.list([expr_list.expr])}; expr_list {-> expr*} - = expr [n2]:no expr_tail* {-> [expr, expr_tail.expr]}; + = arg [n2]:no expr_tail* {-> [arg.expr, expr_tail.expr]}; expr_tail {-> expr} - = comma no expr [n2]:no {-> expr}; + = comma no arg [n2]:no {-> arg.expr}; idlist {-> id*} = opar no idlist_nopar [n2]:no cpar {-> [idlist_nopar.id]} | {nopar} idlist_nopar {-> [idlist_nopar.id]} @@ -793,7 +860,7 @@ visibility | {intrude} kwintrude ; -classdef= {std} doc? kwredef? visibility classkind [id]:classid? [formaldefs]:formaldef* annotations? extern_code_block? [superclasses]:superclass* [propdefs]:propdef* kwend +classdef= {std} doc? kwredef? visibility classkind [id]:classid? [formaldefs]:formaldef* extern_code_block? [propdefs]:propdef* kwend | {top} [propdefs]:propdef* | {main} [propdefs]:propdef* ; @@ -805,17 +872,42 @@ classkind | {extern} kwextern kwclass? ; formaldef = [id]:classid type? annotations?; -superclass = kwsuper type annotations?; propdef = {attr} doc? kwredef? visibility kwvar [id2]:id type? expr? annotations? [block]:expr? | {main_meth} kwredef? [block]:expr? | {type} doc? kwredef? visibility kwtype [id]:classid type annotations? | {meth} doc? kwredef? visibility kwmeth? kwinit? kwnew? methid? signature annotations? extern_calls? extern_code_block? [block]:expr? + | {super} doc? kwredef? visibility kwsuper type annotations? + | {annot} doc? kwredef? visibility? atid opar? [args]:expr* cpar? annotations? + ; + +methid + = {id} id + | {plus} [op]:plus + | {minus} [op]:minus + | {star} [op]:star + | {starstar} [op]:starstar + | {slash} [op]:slash + | {percent} [op]:percent + | {eq} [op]:eq + | {ne} [op]:ne + | {le} [op]:le + | {ge} [op]:ge + | {lt} [op]:lt + | {gt} [op]:gt + | {ll} [op]:ll + | {gg} [op]:gg + | {starship} [op]:starship + | {pipe} [op]:pipe + | {caret} [op]:caret + | {amp} [op]:amp + | {tilde} [op]:tilde + | {bra} obra cbra + | {assign} id assign + | {braassign} obra cbra assign ; -methid = {id} id | {plus} plus | {minus} minus | {star} star | {starstar} starstar | {slash} slash | {percent} percent | {eq} eq | {ne} ne | {le} le | {ge} ge | {lt} lt | {gt} gt | {ll} ll | {gg} gg | {bra} obra cbra | {starship} starship | {assign} id assign | {braassign} obra cbra assign; - signature = opar? [params]:param* cpar? type?; param = id type? dotdotdot? annotations? @@ -826,7 +918,7 @@ type = kwnullable? [id]:classid [types]:type* annotations?; label = kwlabel id?; expr = {block} expr* kwend? - | {vardecl} kwvar id type? assign? expr? annotations? + | {vardecl} kwvar? id type? assign? expr? annotations? | {return} kwreturn? expr? | {break} kwbreak label? | {abort} kwabort @@ -837,32 +929,38 @@ expr = {block} expr* kwend? | {while} kwwhile expr kwdo [block]:expr? label? | {loop} kwloop [block]:expr? label? | {for} kwfor [ids]:id* expr kwdo [block]:expr? label? + | {with} kwwith expr kwdo [block]:expr? label? | {assert} kwassert id? expr [else]:expr? | {once} kwonce expr | {send} expr | {binop} expr [expr2]: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 - | {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 - | {starship} expr [expr2]:expr - | {star} expr [expr2]:expr - | {starstar} expr [expr2]:expr - | {slash} expr [expr2]:expr - | {percent} expr [expr2]:expr - | {uminus} minus expr + | {or} expr [op]:kwor [expr2]:expr + | {and} expr [op]:kwand [expr2]:expr + | {or_else} expr [op]:kwor kwelse [expr2]:expr + | {implies} expr [op]:kwimplies [expr2]:expr + | {not} kwnot expr + | {eq} expr [op]:eq [expr2]:expr + | {ne} expr [op]:ne [expr2]:expr + | {lt} expr [op]:lt [expr2]:expr + | {le} expr [op]:le [expr2]:expr + | {ll} expr [op]:ll [expr2]:expr + | {gt} expr [op]:gt [expr2]:expr + | {ge} expr [op]:ge [expr2]:expr + | {gg} expr [op]:gg [expr2]:expr + | {isa} expr kwisa type + | {plus} expr [op]:plus [expr2]:expr + | {minus} expr [op]:minus [expr2]:expr + | {starship} expr [op]:starship [expr2]:expr + | {star} expr [op]:star [expr2]:expr + | {starstar} expr [op]:starstar [expr2]:expr + | {slash} expr [op]:slash [expr2]:expr + | {percent} expr [op]:percent [expr2]:expr + | {pipe} expr [op]:pipe [expr2]:expr + | {caret} expr [op]:caret [expr2]:expr + | {amp} expr [op]:amp [expr2]:expr + | {uminus} [op]:minus expr + | {uplus} [op]:plus expr + | {utilde} [op]:tilde expr | {new} kwnew type id? [args]:exprs | {attr} expr [id]:attrid | {attr_assign} expr [id]:attrid assign [value]:expr @@ -913,8 +1011,17 @@ exprs | {bra} obra [exprs]:expr* cbra ; assign_op - = {plus} pluseq - | {minus} minuseq + = {plus} [op]:pluseq + | {minus}[op]:minuseq + | {star} [op]:stareq + | {slash} [op]:slasheq + | {percent} [op]:percenteq + | {starstar} [op]:starstareq + | {pipe} [op]:pipeeq + | {caret} [op]:careteq + | {amp} [op]:ampeq + | {ll} [op]:lleq + | {gg} [op]:ggeq ; module_name = quad? [path]:id* id;