Merge: new `with` statement
[nit.git] / src / parser / nit.sablecc3xx
index 7c74a99..26946a7 100644 (file)
@@ -145,6 +145,7 @@ kwas = 'as';
 kwnullable = 'nullable';
 kwisset = 'isset';
 kwlabel = 'label';
+kwwith = 'with';
 kwdebug = '__debug__';
 
 opar = '(';
@@ -253,12 +254,13 @@ 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 {-> propdef*}
        = propdefn+ no {-> [propdefn.propdef]}
+       | {super} superclass {-> [superclass.propdef]}
        | {empty} no {-> []}
        ;
 propdefn {-> propdef}
@@ -276,6 +278,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}
@@ -413,6 +417,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)}
@@ -471,6 +476,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)}
@@ -663,13 +678,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* }
@@ -811,13 +823,14 @@ 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} 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;
@@ -832,7 +845,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
@@ -843,6 +856,7 @@ 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