From 063ca3b644cab4a12840957ed73d4fcdb5c19154 Mon Sep 17 00:00:00 2001 From: Joe Conigliaro Date: Wed, 4 Mar 2020 02:05:16 +1100 Subject: [PATCH] v2: make array append `<<` right associative --- vlib/v/parser/parser.v | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/vlib/v/parser/parser.v b/vlib/v/parser/parser.v index a10d82022e..28c805dfe1 100644 --- a/vlib/v/parser/parser.v +++ b/vlib/v/parser/parser.v @@ -828,6 +828,19 @@ pub fn (p mut Parser) expr(precedence int) (ast.Expr,table.Type) { typ: typ } } + // `arr << 'a'` | `arr << 'a' + 'b'` + else if p.tok.kind == .left_shift { + tok := p.tok + p.next() + mut right := ast.Expr{} + right, typ = p.expr(precedence-1) + node = ast.InfixExpr{ + left: node + right: right + op: tok.kind + pos: tok.position() + } + } else if p.tok.kind.is_infix() { node,typ = p.infix_expr(node) }