From ac2106ec070b72b7bfbe8bb441a11743a466ec22 Mon Sep 17 00:00:00 2001 From: Jean Privat Date: Thu, 16 Oct 2014 00:18:04 -0400 Subject: [PATCH] parser: add tuples Signed-off-by: Jean Privat --- src/parser/nit.sablecc3xx | 16 +++++++++++++++- src/parser/parser_nodes.nit | 6 ++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/parser/nit.sablecc3xx b/src/parser/nit.sablecc3xx index ad3ad66..0d6cc6e 100644 --- a/src/parser/nit.sablecc3xx +++ b/src/parser/nit.sablecc3xx @@ -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* diff --git a/src/parser/parser_nodes.nit b/src/parser/parser_nodes.nit index 4a27d61..8793a00 100644 --- a/src/parser/parser_nodes.nit +++ b/src/parser/parser_nodes.nit @@ -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 -- 1.7.9.5