grammar: add syntax for typed literal arrays
authorJean Privat <jean@pryen.org>
Wed, 24 Sep 2014 20:45:47 +0000 (16:45 -0400)
committerJean Privat <jean@pryen.org>
Thu, 25 Sep 2014 01:55:03 +0000 (21:55 -0400)
~~~
var a = [1, 2, 1.5: Numeric]
~~~

Signed-off-by: Jean Privat <jean@pryen.org>

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

index e26cf3b..fa6d955 100644 (file)
@@ -567,7 +567,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} braargs annotations_o {-> New expr.array(braargs.exprs, 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)}
        ;
 
 superstring {-> expr} 
@@ -686,6 +686,8 @@ args_nopar {-> exprs}
        ;
 braargs        {-> exprs}
        = obra no expr_list cbra {-> New exprs.bra(obra, [expr_list.expr], cbra)};
+args_list {-> exprs}
+       = expr_list {-> New exprs.list([expr_list.expr])};
 expr_list {-> expr*}
        = expr [n2]:no expr_tail* {-> [expr, expr_tail.expr]};
 expr_tail {-> expr} 
@@ -850,7 +852,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} [exprs]:exprs annotations?
+       | {array} obra [exprs]:exprs type? cbra annotations?
        | {self} kwself annotations?
        | {implicit_self} 
        | {true} kwtrue annotations?
index d335917..5beee76 100644 (file)
@@ -1513,7 +1513,10 @@ end
 # A literal array. eg. `[x,y,z]`
 class AArrayExpr
        super AExpr
+       var n_obra: TObra is writable, noinit
        var n_exprs: AExprs is writable, noinit
+       var n_type: nullable AType = null is writable
+       var n_cbra: TCbra is writable, noinit
 end
 
 # A read of `self`