parser: add tuples
authorJean Privat <jean@pryen.org>
Thu, 16 Oct 2014 04:18:04 +0000 (00:18 -0400)
committerJean Privat <jean@pryen.org>
Fri, 17 Oct 2014 01:29:26 +0000 (21:29 -0400)
Signed-off-by: Jean Privat <jean@pryen.org>

src/parser/nit.sablecc3xx
src/parser/parser_nodes.nit

index ad3ad66..0d6cc6e 100644 (file)
@@ -559,13 +559,26 @@ expr_single~nopar~nobra {-> expr}
        | {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} opar no any_expr [n2]:no cpar annotations_o {-> New expr.par(opar, any_expr.expr, cpar, annotations_o.annotations)}
+!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   | {array} obra no args_list typing_o cbra annotations_o {-> New expr.array(obra, args_list.exprs, typing_o.type, cbra, annotations_o.annotations)}
        ;
 
+expr_par {-> expr}
+       = {par} opar no any_expr [n2]:no cpar annotations_o {-> New expr.par(opar, any_expr.expr, cpar, annotations_o.annotations)}
+       | {tuple} opar no many_expr [n2]:no cpar annotations_o {-> New expr.par(opar, many_expr.expr, cpar, annotations_o.annotations)}
+       ;
+
+many_expr {->expr}
+       = any_expr many_expr_tail+ {-> New expr.many([any_expr.expr, many_expr_tail.expr])}
+       ;
+
+many_expr_tail {->expr}
+       = comma no any_expr {-> any_expr.expr}
+       ;
+
 superstring {-> expr} 
        = superstring_start superstring_middle* superstring_end annotations_o {-> New expr.superstring([superstring_start.expr, superstring_middle.expr, superstring_end.expr], annotations_o.annotations)};
 superstring_start {-> expr*}
@@ -871,6 +884,7 @@ expr        = {block} expr* kwend?
        | {vararg} expr dotdotdot
        | {type} type
        | {at} annotations
+       | {many} [exprs]:expr*
        ;
 exprs
        = {list} [exprs]:expr*
index 4a27d61..8793a00 100644 (file)
@@ -1897,6 +1897,12 @@ class AVarargExpr
        var n_dotdotdot: TDotdotdot is writable, noinit
 end
 
+# A list of expression separated with commas (arguments for instance)
+class AManyExpr
+       super AExpr
+       var n_exprs = new ANodes[AExpr](self)
+end
+
 # A special expression that encapsulates a static type
 # Can only be found in special construction like arguments of annotations.
 class ATypeExpr