From cf86692f2eaa70d9ec6aa764f39c3b07648aa15e Mon Sep 17 00:00:00 2001 From: Jean Privat Date: Wed, 17 Dec 2014 05:24:43 -0500 Subject: [PATCH] grammar: new production `array_items` to replace arg_list for literal arrays Signed-off-by: Jean Privat --- src/compiler/abstract_compiler.nit | 2 +- src/interpreter/naive_interpreter.nit | 2 +- src/parser/nit.sablecc3xx | 14 ++++++++++++-- src/parser/parser_abs.nit | 2 +- src/parser/parser_nodes.nit | 2 +- src/pretty.nit | 2 +- src/semantize/typing.nit | 2 +- src/transform.nit | 4 ++-- 8 files changed, 20 insertions(+), 10 deletions(-) diff --git a/src/compiler/abstract_compiler.nit b/src/compiler/abstract_compiler.nit index 2f58f29..5b88c2e 100644 --- a/src/compiler/abstract_compiler.nit +++ b/src/compiler/abstract_compiler.nit @@ -2652,7 +2652,7 @@ redef class AArrayExpr do var mtype = self.mtype.as(MClassType).arguments.first var array = new Array[RuntimeVariable] - for nexpr in self.n_exprs.n_exprs do + for nexpr in self.n_exprs do var i = v.expr(nexpr, mtype) array.add(i) end diff --git a/src/interpreter/naive_interpreter.nit b/src/interpreter/naive_interpreter.nit index 5d24e6c..a12657e 100644 --- a/src/interpreter/naive_interpreter.nit +++ b/src/interpreter/naive_interpreter.nit @@ -1532,7 +1532,7 @@ redef class AArrayExpr redef fun expr(v) do var val = new Array[Instance] - for nexpr in self.n_exprs.n_exprs do + for nexpr in self.n_exprs do var i = v.expr(nexpr) if i == null then return null val.add(i) diff --git a/src/parser/nit.sablecc3xx b/src/parser/nit.sablecc3xx index ff4a164..52fc5ec 100644 --- a/src/parser/nit.sablecc3xx +++ b/src/parser/nit.sablecc3xx @@ -566,7 +566,7 @@ expr_single~nopar~nobra {-> 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)} +!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)} ; expr_par {-> expr} @@ -582,6 +582,16 @@ many_expr_tail {->expr} = comma no any_expr {-> any_expr.expr} ; +array_items {-> expr*} + = array_item array_items_tail* {-> [array_item.expr, array_items_tail.expr]} + ; +array_items_tail {-> expr} + = comma no array_item {-> array_item.expr} + ; +array_item {-> expr} + = expr no {-> 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,7 +881,7 @@ expr = {block} expr* kwend? | {range} expr [expr2]:expr annotations? | {crange} obra expr [expr2]:expr cbra annotations? | {orange} obra expr [expr2]:expr [cbra]:obra annotations? - | {array} obra [exprs]:exprs type? cbra annotations? + | {array} obra [exprs]:expr* type? cbra annotations? | {self} kwself annotations? | {implicit_self} | {true} kwtrue annotations? diff --git a/src/parser/parser_abs.nit b/src/parser/parser_abs.nit index 07045e3..1aaa263 100644 --- a/src/parser/parser_abs.nit +++ b/src/parser/parser_abs.nit @@ -908,7 +908,7 @@ end class AArrayExpr super AExpr var n_obra: TObra is writable, noinit - var n_exprs: AExprs is writable, noinit + var n_exprs: List[AExpr] = new List[AExpr] var n_type: nullable AType = null is writable var n_cbra: TCbra is writable, noinit var n_annotations: nullable AAnnotations = null is writable diff --git a/src/parser/parser_nodes.nit b/src/parser/parser_nodes.nit index a7f8071..493ed0e 100644 --- a/src/parser/parser_nodes.nit +++ b/src/parser/parser_nodes.nit @@ -1773,7 +1773,7 @@ end class AArrayExpr super AExpr var n_obra: TObra is writable, noinit - var n_exprs: AExprs is writable, noinit + var n_exprs = new ANodes[AExpr](self) var n_type: nullable AType = null is writable var n_cbra: TCbra is writable, noinit end diff --git a/src/pretty.nit b/src/pretty.nit index 75d9879..3b9f7ef 100644 --- a/src/pretty.nit +++ b/src/pretty.nit @@ -2044,7 +2044,7 @@ end redef class AArrayExpr redef fun accept_pretty_printer(v) do v.consume "[" - v.visit_list n_exprs.n_exprs + v.visit_list n_exprs v.consume "]" end end diff --git a/src/semantize/typing.nit b/src/semantize/typing.nit index 2c58f74..4955eda 100644 --- a/src/semantize/typing.nit +++ b/src/semantize/typing.nit @@ -1193,7 +1193,7 @@ redef class AArrayExpr end var mtypes = new Array[nullable MType] var useless = false - for e in self.n_exprs.n_exprs do + for e in self.n_exprs do var t = v.visit_expr(e) if t == null then return # Skip error diff --git a/src/transform.nit b/src/transform.nit index 07acefb..fe46105 100644 --- a/src/transform.nit +++ b/src/transform.nit @@ -282,10 +282,10 @@ redef class AArrayExpr do var nblock = v.builder.make_block - var nnew = v.builder.make_new(with_capacity_callsite.as(not null), [v.builder.make_int(n_exprs.n_exprs.length)]) + var nnew = v.builder.make_new(with_capacity_callsite.as(not null), [v.builder.make_int(n_exprs.length)]) nblock.add nnew - for nexpr in self.n_exprs.n_exprs do + for nexpr in self.n_exprs do var nadd = v.builder.make_call(nnew.make_var_read, push_callsite.as(not null), [nexpr]) nblock.add nadd end -- 1.7.9.5