grammar: add `for_group` in `for` for multi-iterators
[nit.git] / src / parser / nit.sablecc3xx
index e47b96c..694da7b 100644 (file)
@@ -26,8 +26,17 @@ Helpers
 all = [0 .. 0xFF];
 lowercase = ['a' .. 'z'];
 uppercase = ['A' .. 'Z'];
+
 digit = ['0' .. '9'];
-hexdigit = ['0'..'9'] | ['a'..'f'] | ['A'..'F'];
+hexdigit = ['0'..'9'] | ['a'..'f'] | ['A'..'F'] | '_';
+bindigit = '0' | '1' | '_';
+octdigit = ['0' .. '7'] | '_';
+number = digit (digit | '_')*;
+hex_number = ('0x' | '0X') hexdigit+;
+bin_number = ('0b' | '0B') bindigit+;
+oct_number = ('0o' | '0O') octdigit+;
+prec = '8' | '16' | '32';
+
 letter = lowercase | uppercase | digit | '_';
 
 tab = 9;
@@ -191,14 +200,14 @@ gg = '>>';
 starship = '<=>';
 bang='!';
 at='@';
+semi=';';
 
 classid = uppercase letter*;
 id = lowercase letter*;
 attrid = '_' lowercase letter*;
 
-number = digit+;
-hex_number = ('0x' | '0X') hexdigit+;
-float = digit* '.' digit+;
+integer = (number | hex_number | bin_number | oct_number) (('u' prec) | ('i' prec) |);
+float = digit* '.' digit+ | (digit+ | digit* '.' digit+) ('E'|'e') ('+'|'-'|) digit+;
 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;
@@ -224,11 +233,11 @@ module
        = 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])};
 
 moduledecl
-       = [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)};
+       = [doc]:nd redef visibility kwmodule no module_name annotation_withend [n2]:n1 {-> New moduledecl(doc.doc, redef.kwredef, visibility, kwmodule, module_name, annotation_withend.annotations)};
 
 import
-       = {std} [doc]:no redef visibility kwimport no module_name annotation_withend [n2]:n1 {-> New import.std(visibility, kwimport, module_name, annotation_withend.annotations)}
-       | {no} [doc]:no redef visibility kwimport no kwend [n2]:n1 {-> New import.no(visibility, kwimport, kwend)}
+       = {std} [doc]:nd redef visibility kwimport no module_name annotation_withend [n2]:n1 {-> New import.std(visibility, kwimport, module_name, annotation_withend.annotations)}
+       | {no} [doc]:nd redef visibility kwimport no kwend [n2]:n1 {-> New import.no(visibility, kwimport, kwend)}
        ;
 
 topdef {-> classdef}
@@ -241,13 +250,16 @@ implicit_main_class {-> classdef?}
        | {null} n? {-> Null}
        ;
 implicit_main_meth {-> propdef}
-       = [doc]:no stmts {-> New propdef.main_meth(Null, stmts.expr)}
-       | {n} [doc]:no stmtsn {-> New propdef.main_meth(Null, stmtsn.expr)}
+       = [doc]:nd stmts {-> New propdef.main_meth(Null, stmts.expr)}
+       | {n} [doc]:nd stmtsn {-> New propdef.main_meth(Null, stmtsn.expr)}
        ;
 
 /* CLASSES *******************************************************************/
 classdef
-       = [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)};
+       = [doc]:nd redef visibility classkind no qclassid extern_code_block? propdefs kwend {-> New classdef.std(doc.doc, redef.kwredef, visibility, classkind, qclassid.classid, Null, [], Null, extern_code_block, [propdefs.propdef], kwend)}
+       | {for} [doc]:nd redef visibility classkind no qclassid obra [n2]:no formaldefs cbra extern_code_block? propdefs kwend {-> New classdef.std(doc.doc, redef.kwredef, visibility, classkind, qclassid.classid, obra, [formaldefs.formaldef], cbra, extern_code_block, [propdefs.propdef], kwend)}
+       ;
+
 redef {-> kwredef?}
        = kwredef? {-> kwredef};
 classkind
@@ -259,49 +271,49 @@ classkind
        ;
 
 formaldefs {-> formaldef*}
-       = obra no formaldef formaldefs_tail* [n2]:no cbra {-> [formaldef, formaldefs_tail.formaldef]}
-       | {null} {-> []}
+       = formaldef formaldefs_tail* {-> [formaldef, formaldefs_tail.formaldef]}
+       | {empty} {->[]}
        ;
 formaldefs_tail {-> formaldef}
        = comma no formaldef {-> formaldef};
 formaldef
-       = classid annotations? typing_o {-> New formaldef(classid, typing_o.type, annotations)};
+       = classid annotations? typing_o no {-> New formaldef(classid, typing_o.type, 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)}
+       = {super} [doc]:nd 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 {-> []}
+       | {empty} nd {-> []}
        ;
 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)}
-       | {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)}
-!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)}
-!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)}
-       | {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)}
-!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)}
-!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)}
-!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)}
-!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)}
+       = {meth} [doc]:nd 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, kwdo, stmtso.expr, kwend_o.kwend)}
+       | {nobody} [doc]:nd 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, Null, Null)}
+!toplevel| {intern_new} [doc]:nd 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, Null, Null)}
+!toplevel| {new} [doc]:nd 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, kwdo, stmtso.expr, kwend_o.kwend)}
+       | {extern_implicit} [doc]:nd 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, Null, Null)}
+!toplevel| {var3} [doc]:nd redef visibility kwvar id typing_o annotation_withend {-> New propdef.attr(doc.doc, redef.kwredef, visibility, kwvar, id, typing_o.type, Null, Null, annotation_withend.annotations, Null, Null, Null)}
+!toplevel| {var4} [doc]:nd 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, assign, expr.expr, annotation_withend.annotations, Null, Null, Null)}
+!toplevel| {var5} [doc]:nd 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, Null, annotation_noend.annotations, kwdo, stmtso.expr, kwend)}
+!toplevel| {init} [doc]:nd 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, kwdo, stmtso.expr, kwend_o.kwend)}
+!toplevel| {type} [doc]:nd 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]:nd 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, Null, 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}
-       | {more} kwis n1 line_annotations kwend {-> line_annotations.annotations}
+       = {oneliner} kwis annotation_list {-> New annotations(kwis, Null, Null, [annotation_list.annotation], Null, Null)}
+       | {more} kwis n1 line_annotation+ kwend {-> New annotations(kwis, Null, Null, [line_annotation.annotation], Null, kwend) }
 !nonull        | {null} {-> Null}
        ;
 annotation_noend {-> annotations}
-       = {oneliner} kwis many_annotations {-> many_annotations.annotations}
-       | {more} kwis n1 line_annotations {-> line_annotations.annotations}
+       = {oneliner} kwis annotation_list {-> New annotations(kwis, Null, Null, [annotation_list.annotation], Null, Null)}
+       | {more} kwis n1 line_annotation+ {-> New annotations(kwis, Null, Null, [line_annotation.annotation], Null, Null) }
        ;
 
 visibility
@@ -393,8 +405,8 @@ extern_code_body {-> extern_code_block} = no extern_code_block {-> extern_code_b
 
 /* TYPES *********************************************************************/
 type~nobra~nopar {-> type}
-       = {simple} kwnullable? classid annotations_o~nopar {-> New type(kwnullable, classid, [], annotations_o~nopar.annotations)}
-!nobra | {generic} kwnullable? classid obra no types [n2]:no cbra annotations_o~nopar {-> New type(kwnullable, classid, [types.type], annotations_o~nopar.annotations)}
+       = {simple} kwnullable? classid annotations_o~nopar {-> New type(kwnullable, classid, Null, [], Null, annotations_o~nopar.annotations)}
+!nobra | {generic} kwnullable? classid obra no types [n2]:no cbra annotations_o~nopar {-> New type(kwnullable, classid, obra, [types.type], cbra, annotations_o~nopar.annotations)}
        ;
 types {-> type*} 
        = type types_tail* {-> [type, types_tail.type]};
@@ -436,7 +448,7 @@ stmt~withelse~noexpr~nopar {-> 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        | {call} recv qid args_nopar {-> New expr.call(recv.expr, qid, args_nopar.exprs)}
 !noexpr        | {super} qualified_o kwsuper args_nopar {-> New expr.super(qualified_o.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 {-> New expr.debug_type(kwdebug, kwtype, expr.expr, type) }
@@ -451,10 +463,10 @@ vardecl{-> expr}
 
 assignment~nopar {-> expr}
        = {attr} recv~nopar qualified_o attrid assign expr {-> New expr.attr_assign(recv~nopar.expr, attrid, assign, expr)}
-       | {call} recv~nopar qid args assign expr {-> New expr.call_assign(recv~nopar.expr, qid.id, args.exprs, assign,  expr)}
+       | {call} recv~nopar qid args assign expr {-> New expr.call_assign(recv~nopar.expr, qid, args.exprs, assign,  expr)}
        | {bra} expr_atom~nopar braargs assign expr {-> New expr.bra_assign(expr_atom~nopar.expr, braargs.exprs, assign,  expr)}
        | {attr_re} recv~nopar qualified_o attrid assign_op expr {-> New expr.attr_reassign(recv~nopar.expr, attrid, assign_op,  expr)}
-       | {call_re} recv~nopar qid args assign_op expr {-> New expr.call_reassign(recv~nopar.expr, qid.id, args.exprs, assign_op,  expr)}
+       | {call_re} recv~nopar qid args assign_op expr {-> New expr.call_reassign(recv~nopar.expr, qid, args.exprs, assign_op,  expr)}
        | {bra_re} expr_atom~nopar braargs assign_op expr {-> New expr.bra_reassign(expr_atom~nopar.expr, braargs.exprs, assign_op,  expr)}
        ;
 assign_op
@@ -477,14 +489,15 @@ do~withelse {-> expr}
        ;
 
 if~withelse {-> expr}
-       = {onelineelse} kwif no expr [n2]:no kwthen stmt_withelse kwelse stmtso~withelse {-> New expr.if(kwif, expr, stmt_withelse.expr, stmtso~withelse.expr)}
-!withelse      | {oneline} kwif no expr [n2]:no kwthen stmt {-> New expr.if(kwif, expr, stmt.expr, Null)}
-!withelse      | {block} kwif no expr [n2]:no kwthen [n3]:n stmtsn elsepartblock {-> New expr.if(kwif, expr, stmtsn.expr, elsepartblock.expr)}
-!withelse      | {emptyblock} kwif no expr [n2]:no kwthen [n3]:n? elsepartblock {-> New expr.if(kwif, expr, Null, elsepartblock.expr)}
+       = {onelineelse} kwif no expr [n2]:no kwthen stmt_withelse kwelse stmtso~withelse {-> New expr.if(kwif, expr, kwthen, stmt_withelse.expr, kwelse, stmtso~withelse.expr)}
+!withelse      | {oneline} kwif no expr [n2]:no kwthen stmt {-> New expr.if(kwif, expr, kwthen, stmt.expr, Null, Null)}
+!withelse      | {block} kwif no expr [n2]:no kwthen [n3]:n stmtsn kwelse stmtso {-> New expr.if(kwif, expr, kwthen, stmtsn.expr, kwelse, stmtso.expr)}
+!withelse      | {emptyblock} kwif no expr [n2]:no kwthen [n3]:n? kwelse stmtso {-> New expr.if(kwif, expr, kwthen, Null, kwelse, stmtso.expr)}
+!withelse      | {blocknoelse} kwif no expr [n2]:no kwthen [n3]:n stmtsn endblock {-> New expr.if(kwif, expr, kwthen, stmtsn.expr, Null, endblock.expr)}
+!withelse      | {emptyblocknoelse} kwif no expr [n2]:no kwthen [n3]:n? endblock {-> New expr.if(kwif, expr, kwthen, Null, Null, endblock.expr)}
        ;
-elsepartblock {-> expr?}
-       = {else} kwelse stmtso {-> stmtso.expr}
-       | {empty} kwend {-> New expr.block([], kwend)}
+endblock {-> expr}
+       = {empty} kwend {-> New expr.block([], kwend)}
        ;
 
 loop~withelse {-> expr}
@@ -498,8 +511,16 @@ while~withelse {-> expr}
        ;
 
 for~withelse {-> expr}
-       = 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)}
+       = kwfor no for_groups [n4]:no kwdo stmtso_withend label {-> New expr.for(kwfor, [for_groups.for_group], kwdo, stmtso_withend.expr, label)}
+       | {nolabel} kwfor no for_groups [n4]:no kwdo stmtso~withelse {-> New expr.for(kwfor, [for_groups.for_group], kwdo, stmtso~withelse.expr, Null)}
+       ;
+
+for_groups {-> for_group*}
+       = {one} for_group {-> [for_group]}
+       | {many} for_groups no comma [n2]:no for_group {-> [for_groups.for_group, for_group] }
+       ;
+for_group
+       = [ids]:idlist [n2]:no kwin [n3]:no expr {-> New for_group([ids.id], kwin, expr)}
        ;
 
 with~withelse {-> expr}
@@ -513,8 +534,8 @@ withexpr {-> 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)}
+       = {else} kwassert assertid? expr kwelse stmtso~withelse {-> New expr.assert(kwassert, assertid.id, expr, kwelse, stmtso~withelse.expr)}
+!withelse| {noelse} kwassert assertid? expr {-> New expr.assert(kwassert, assertid.id, expr, Null, Null)}
        ;
 assertid {-> id}
        = id column {-> id};
@@ -606,11 +627,11 @@ expr_new~nopar~nobra {-> expr}
 expr_atom~nopar~nobra {-> expr}
        = expr_single~nopar~nobra {-> expr_single~nopar~nobra.expr}
        | {attr} recv~nopar~nobra qualified_o attrid {-> New expr.attr(recv~nopar~nobra.expr, attrid)}
-       | {call} recv~nopar~nobra qid args {-> New expr.call(recv~nopar~nobra.expr, qid.id, args.exprs)}
+       | {call} recv~nopar~nobra qid args {-> New expr.call(recv~nopar~nobra.expr, qid, args.exprs)}
        | {super} qualified_o kwsuper args {-> New expr.super(qualified_o.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 qid args {-> New expr.new(kwnew, type~nobra_nopar.type, qid.id, args.exprs)}
+       | {new} kwnew no type~nobra_nopar dot [n2]:no qid args {-> New expr.new(kwnew, type~nobra_nopar.type, qid, args.exprs)}
         | {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)}
@@ -619,6 +640,7 @@ expr_atom~nopar~nobra {-> expr}
 arg~nopar~nobra {-> expr}
        = [expr]:expr~nopar~nobra {-> expr.expr}
        | {vararg} [expr]:expr~nopar~nobra dotdotdot {-> New expr.vararg(expr.expr, dotdotdot)}
+       | {namedarg} id assign [expr]:expr~nopar~nobra  {-> New expr.namedarg(id, assign, expr.expr) }
        ;
 
 expr_single~nopar~nobra {-> expr}
@@ -626,16 +648,15 @@ expr_single~nopar~nobra {-> expr}
        | {true} kwtrue annotations_o {-> New expr.true(kwtrue, annotations_o.annotations)}
        | {false} kwfalse annotations_o {-> New expr.false(kwfalse, annotations_o.annotations)}
        | {null} kwnull annotations_o {-> New expr.null(kwnull, annotations_o.annotations)}
-       | {int} number annotations_o {-> New expr.dec_int(number, annotations_o.annotations)}
-       | {hex_int} hex_number annotations_o {-> New expr.hex_int(hex_number, annotations_o.annotations)}
+       | {integer} integer annotations_o {-> New expr.integer(integer, annotations_o.annotations)}
        | {float} float annotations_o {-> New expr.float(float, annotations_o.annotations)}
        | {char} char annotations_o {-> New expr.char(char, annotations_o.annotations)}
        | {string} string annotations_o {-> New expr.string(string, annotations_o.annotations)}
        | {superstring} superstring  {-> superstring.expr}
 !nopar | {par} expr_par {-> expr_par.expr}
 // !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_o {-> New expr.crange(obra, expr, expr2.expr, cbra, annotations_o.annotations)}
-!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)}
+!nobra!nopar   | {range} obra no expr [n2]:no dotdot [n3]:no [expr2]:expr_nobra [n4]:no cbra annotations_o {-> New expr.crange(obra, expr, dotdot, expr2.expr, cbra, annotations_o.annotations)}
+!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, dotdot, expr2.expr, cbra, annotations_o.annotations)}
 !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)}
        ;
 
@@ -660,8 +681,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)}
+       | {for} kwfor no for_groups [n4]:no kwdo [block]:array_item {-> New expr.for(kwfor, [for_groups.for_group], kwdo, block.expr, Null)}
+       | {if} kwif [n1]:no expr [n2]:no kwthen [n3]:no [then]:array_item {-> New expr.if(kwif, expr, kwthen, then.expr, Null, Null)}
        ;
 
 superstring {-> expr} 
@@ -684,8 +705,8 @@ superstring_end {-> expr}
 /* 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} at one_annotation~nopar {-> New annotations(Null, at, Null, [one_annotation~nopar.annotation], Null, Null)}
+       | {many} at opar no annotation_list [n2]:no cpar {-> New annotations(Null, at, opar, [annotation_list.annotation], cpar, Null)}
        ;
 annotations_o~nopar {-> annotations?}
        = annotations~nopar {-> annotations~nopar.annotations}
@@ -698,10 +719,6 @@ one_annotation~nopar {-> annotation}
 !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)}
        ;
 
-many_annotations {-> annotations}
-       = {many} annotation_list {-> New annotations(Null, Null, [annotation_list.annotation], Null)}
-       ;
-
 annotation_list {-> annotation*}
        = {many} one_annotation_list annotations_tail* {-> [one_annotation_list.annotation, annotations_tail.annotation] }
        ;
@@ -721,18 +738,15 @@ annotations_tail {-> annotation}
        = comma no one_annotation_list {-> one_annotation_list.annotation}
        ;
 
-line_annotations {-> annotations}
-       = line_annotation+ {-> New annotations(Null, Null, [line_annotation.annotation], Null) }
-       ;
 line_annotation {-> annotation}
-       = [doc]:no redef visibility atid annotations? n1 {-> New annotation(doc.doc, redef.kwredef, visibility, atid.atid, Null, [], Null, annotations)}
-       | {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)}
+       = [doc]:nd redef visibility atid annotations? n1 {-> New annotation(doc.doc, redef.kwredef, visibility, atid.atid, Null, [], Null, annotations)}
+       | {args} [doc]:nd 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]:nd redef visibility atid at_args_nopar n1 {-> New annotation(doc.doc, redef.kwredef, visibility, atid.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)}
+       = [doc]:nd atid_forclass annotations? {-> New propdef.annot(doc.doc, Null, Null, atid_forclass.atid, Null, [], Null, annotations)}
+       | {args} [doc]:nd 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]:nd 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* }
@@ -807,8 +821,8 @@ qualified_o {-> qualified?}
        = qualified {-> qualified}
        | {null} {-> Null}
        ;
-qid {-> id}
-       = qualified? id {-> id}
+qid
+       = qualified? id
        ;
 qclassid {-> classid}
        = qualified? classid {-> classid}
@@ -825,19 +839,32 @@ kwend_o {-> kwend?}
        = kwend? {-> kwend}
        ;
 
-n1     = {a} comment | {b} eol;
-n {-> doc?}
-       = {a} n2? comment+ {-> New doc([comment])}
-       | {b} n2 {-> Null}
+/* A single hard break */
+n1     = {a} comment | {b} eol | {c} semi;
+
+/* A mandatory hard break, returns the last comment */
+n~nosemi {-> doc?}
+       = {a} n2* comment+ {-> New doc([comment])}
+       | {b} n2+ {-> Null}
+!nosemi | {c} n2* comment* semi n? {-> n.doc }
        ;
-no {-> doc?}
+
+/* An optional hard break, returns the last comment.
+ * Used mainly to introduce optional documentation */
+nd {-> doc?}
        = {empty} {-> Null}
        | n {-> n.doc}
        ;
 
+/* An optional soft break.
+ * Used when a unambiguous line break or comment could be inserted/ */
+no
+       = {empty}
+       | n_nosemi
+       ;
+
 n2
-       = {a} n2? comment+ eol+
-       | {b} eol+
+       = {a} comment* eol
        ;
 
 /*****************************************************************************/
@@ -860,7 +887,7 @@ visibility
        | {intrude} kwintrude
        ;
 
-classdef= {std} doc? kwredef? visibility classkind [id]:classid? [formaldefs]:formaldef* extern_code_block? [propdefs]:propdef* kwend
+classdef= {std} doc? kwredef? visibility classkind [id]:classid? obra? [formaldefs]:formaldef* cbra? extern_code_block? [propdefs]:propdef* kwend
        | {top} [propdefs]:propdef*
        | {main} [propdefs]:propdef*
        ;
@@ -874,10 +901,10 @@ classkind
 formaldef = [id]:classid type? annotations?;
 
 
-propdef = {attr} doc? kwredef? visibility kwvar [id2]:id type? expr? annotations? [block]:expr?
+propdef = {attr} doc? kwredef? visibility kwvar [id2]:id type? assign? expr? annotations? kwdo? [block]:expr? kwend?
        | {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?
+       | {meth} doc? kwredef? visibility kwmeth? kwinit? kwnew? methid? signature annotations? extern_calls? extern_code_block? kwdo? [block]:expr? kwend?
        | {super} doc? kwredef? visibility kwsuper type annotations?
        | {annot} doc? kwredef? visibility? atid opar? [args]:expr* cpar? annotations?
        ;
@@ -908,12 +935,16 @@ methid
        | {braassign} obra cbra assign
        ;
 
+qid
+       = qualified? id
+       ;
+
 signature = opar? [params]:param* cpar? type?;
 
 param  = id type? dotdotdot? annotations?
        ;
 
-type   = kwnullable? [id]:classid [types]:type* annotations?;
+type   = kwnullable? [id]:classid obra? [types]:type* cbra? annotations?;
 
 label = kwlabel id?;
 
@@ -924,13 +955,13 @@ expr      = {block} expr* kwend?
        | {abort} kwabort
        | {continue} kwcontinue? label?
        | {do} kwdo [block]:expr? label?
-       | {if} kwif expr [then]:expr? [else]:expr? 
+       | {if} kwif expr kwthen [then]:expr? kwelse? [else]:expr?
        | {ifexpr} kwif expr kwthen [then]:expr kwelse [else]:expr
        | {while} kwwhile expr kwdo [block]:expr? label?
        | {loop} kwloop [block]:expr? label?
-       | {for} kwfor [ids]:id* expr kwdo [block]:expr? label?
+       | {for} kwfor [groups]:for_group* kwdo [block]:expr? label?
        | {with} kwwith expr kwdo [block]:expr? label?
-       | {assert} kwassert id? expr [else]:expr?
+       | {assert} kwassert id? expr kwelse? [else]:expr?
        | {once} kwonce expr 
        | {send} expr 
        | {binop} expr [expr2]:expr 
@@ -961,13 +992,13 @@ expr      = {block} expr* kwend?
        | {uminus} [op]:minus expr
        | {uplus} [op]:plus expr
        | {utilde} [op]:tilde expr
-       | {new} kwnew type id? [args]:exprs
+       | {new} kwnew type qid? [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]:exprs
-       | {call_assign} expr id [args]:exprs assign [value]:expr
-       | {call_reassign} expr id [args]:exprs assign_op [value]:expr 
+       | {call} expr qid [args]:exprs
+       | {call_assign} expr qid [args]:exprs assign [value]:expr
+       | {call_reassign} expr qid [args]:exprs assign_op [value]:expr
        | {super} qualified? kwsuper [args]:exprs
        | {init} expr kwinit [args]:exprs 
        | {bra} expr [args]:exprs
@@ -977,16 +1008,15 @@ expr     = {block} expr* kwend?
        | {var_assign} id assign [value]:expr 
        | {var_reassign} id assign_op [value]:expr 
        | {range} expr [expr2]:expr annotations?
-       | {crange} obra expr [expr2]:expr cbra annotations?
-       | {orange} obra expr [expr2]:expr [cbra]:obra annotations?
+       | {crange} obra expr dotdot [expr2]:expr cbra annotations?
+       | {orange} obra expr dotdot [expr2]:expr [cbra]:obra annotations?
        | {array} obra [exprs]:expr* type? cbra annotations?
        | {self} kwself annotations?
        | {implicit_self} 
        | {true} kwtrue annotations?
        | {false} kwfalse annotations?
        | {null} kwnull annotations?
-       | {dec_int} number annotations?
-       | {hex_int} hex_number annotations?
+       | {integer} integer annotations?
        | {float} float annotations?
        | {char} char annotations?
        | {string} string annotations?
@@ -1000,6 +1030,7 @@ expr      = {block} expr* kwend?
        | {isset_attr} kwisset expr [id]:attrid
        | {debug_type} kwdebug kwtype expr type
        | {vararg} expr dotdotdot
+       | {namedarg} id assign expr
        | {type} type
        | {methid} expr [id]:methid
        | {at} annotations
@@ -1023,6 +1054,9 @@ assign_op
        | {ll} [op]:lleq
        | {gg} [op]:ggeq
        ;
+for_group
+       = [ids]:id* kwin expr
+       ;
 
 module_name = quad? [path]:id* id;
 extern_calls = kwimport [extern_calls]:extern_call*
@@ -1043,7 +1077,7 @@ qualified = id* classid? ;
 
 doc = comment+;
 
-annotations = at? opar? [items]:annotation* cpar?;
+annotations = kwis? at? opar? [items]:annotation* cpar? kwend?;
 
 annotation = doc? kwredef? visibility? atid opar? [args]:expr* cpar? annotations?;