@@ -196,22 +196,50 @@ { /// Funcall ::= BaseExpression ["(" Expression%"," ")"]* auto e = BaseExpression(); - while( tryEat("(") ) - { - auto pos = currentPosition(); - AST[] args; - while( !tryEat(")") ) { - if( lex.empty ) - throw genex!UnexpectedEOF(pos, "closing ')' for arguments not found"); - args ~= E(0); - if( !tryEat(",") ) { - eat(")", "after function parameters"); - break; + for(;;) + if( tryEat("(") ) + { + auto pos = currentPosition(); + AST[] args; + while( !tryEat(")") ) { + if( lex.empty ) + throw genex!UnexpectedEOF(pos, "closing ')' for arguments not found"); + args ~= E(0); + if( !tryEat(",") ) { + eat(")", "after function parameters"); + break; + } } + e = new FuncallExpression(e.pos, e, args); + } + else if( tryEat("{") ) + { + e = parseTableSetAfterBrace(e); } - e = new FuncallExpression(e.pos, e, args); + else + break; + return e; + } + + AST parseTableSetAfterBrace(AST e) + { + if( tryEat("}") ) + return e; + auto pos = currentPosition(); + for(;;) + { + string key = eatId("for table key", AllowQuoted); + eat(":", "after table key"); + AST val = E(0); + e = new FuncallExpression(pos, new VarExpression(pos,".="), + e, new StrLiteral(pos,key), val); + if( !tryEat(",") ) + { + eat("}", "for the end of table literal"); + break; + } } return e; } @@ -247,24 +275,9 @@ } if( tryEat("{") ) { AST e = new FuncallExpression(pos, new VarExpression(pos,"{}")); - if( tryEat("}") ) - return e; - for(;;) - { - string key = eatId("for table key", AllowQuoted); - eat(":", "after table key"); - AST val = E(0); - e = new FuncallExpression(pos, new VarExpression(pos,".="), - e, new StrLiteral(pos,key), val); - if( !tryEat(",") ) - { - eat("}", "for the end of table literal"); - break; - } - } - return e; + return parseTableSetAfterBrace(e); } if( tryEat("if") ) { eat("(", "after if"); @@ -468,5 +481,6 @@ assert_eq(parseString(`{foo:1,"bar":2}`), call(var(".="), call(var(".="), call(var("{}")), strl("foo"), intl(1)), strl("bar"), intl(2))); assert_eq(parseString(`{}.foo`), call(var("."),call(var("{}")),strl("foo"))); assert_eq(parseString(`{}.?foo`), call(var(".?"),call(var("{}")),strl("foo"))); + assert_eq(parseString(`x{y:1}`), call(var(".="),var("x"),strl("y"),intl(1))); }