Diff
Not logged in

Differences From Artifact [a024e7c2d40e70c4]:

To Artifact [25ec86a59533b939]:


193 193 } 194 194 195 195 AST Funcall() 196 196 { 197 197 /// Funcall ::= BaseExpression ["(" Expression%"," ")"]* 198 198 199 199 auto e = BaseExpression(); 200 - while( tryEat("(") ) 201 - { 202 - auto pos = currentPosition(); 203 - AST[] args; 204 - while( !tryEat(")") ) { 205 - if( lex.empty ) 206 - throw genex!UnexpectedEOF(pos, "closing ')' for arguments not found"); 207 - args ~= E(0); 208 - if( !tryEat(",") ) { 209 - eat(")", "after function parameters"); 210 - break; 200 + for(;;) 201 + if( tryEat("(") ) 202 + { 203 + auto pos = currentPosition(); 204 + AST[] args; 205 + while( !tryEat(")") ) { 206 + if( lex.empty ) 207 + throw genex!UnexpectedEOF(pos, "closing ')' for arguments not found"); 208 + args ~= E(0); 209 + if( !tryEat(",") ) { 210 + eat(")", "after function parameters"); 211 + break; 212 + } 211 213 } 214 + e = new FuncallExpression(e.pos, e, args); 215 + } 216 + else if( tryEat("{") ) 217 + { 218 + e = parseTableSetAfterBrace(e); 212 219 } 213 - e = new FuncallExpression(e.pos, e, args); 220 + else 221 + break; 222 + return e; 223 + } 224 + 225 + AST parseTableSetAfterBrace(AST e) 226 + { 227 + if( tryEat("}") ) 228 + return e; 229 + auto pos = currentPosition(); 230 + for(;;) 231 + { 232 + string key = eatId("for table key", AllowQuoted); 233 + eat(":", "after table key"); 234 + AST val = E(0); 235 + e = new FuncallExpression(pos, new VarExpression(pos,".="), 236 + e, new StrLiteral(pos,key), val); 237 + if( !tryEat(",") ) 238 + { 239 + eat("}", "for the end of table literal"); 240 + break; 241 + } 214 242 } 215 243 return e; 216 244 } 217 245 218 246 AST BaseExpression() 219 247 { 220 248 if( lex.empty ) ................................................................................ 244 272 auto e = Body(); 245 273 eat(")", "after parenthesized expression"); 246 274 return e; 247 275 } 248 276 if( tryEat("{") ) 249 277 { 250 278 AST e = new FuncallExpression(pos, new VarExpression(pos,"{}")); 251 - if( tryEat("}") ) 252 - return e; 253 - for(;;) 254 - { 255 - string key = eatId("for table key", AllowQuoted); 256 - eat(":", "after table key"); 257 - AST val = E(0); 258 - e = new FuncallExpression(pos, new VarExpression(pos,".="), 259 - e, new StrLiteral(pos,key), val); 260 - if( !tryEat(",") ) 261 - { 262 - eat("}", "for the end of table literal"); 263 - break; 264 - } 265 - } 266 - return e; 279 + return parseTableSetAfterBrace(e); 267 280 } 268 281 if( tryEat("if") ) 269 282 { 270 283 eat("(", "after if"); 271 284 auto cond = E(0); 272 285 eat(")", "after if condition"); 273 286 auto thenPos = lex.front.pos; ................................................................................ 465 478 let("@type", "(system)", fun(["x"], var("x")), var("@type")) ); 466 479 467 480 assert_eq(parseString(`{}`), call(var("{}"))); 468 481 assert_eq(parseString(`{foo:1,"bar":2}`), 469 482 call(var(".="), call(var(".="), call(var("{}")), strl("foo"), intl(1)), strl("bar"), intl(2))); 470 483 assert_eq(parseString(`{}.foo`), call(var("."),call(var("{}")),strl("foo"))); 471 484 assert_eq(parseString(`{}.?foo`), call(var(".?"),call(var("{}")),strl("foo"))); 485 + assert_eq(parseString(`x{y:1}`), call(var(".="),var("x"),strl("y"),intl(1))); 472 486 }