Diff
Not logged in

Differences From Artifact [7ed0053850ffa032]:

To Artifact [6bec0997c5764737]:


163 163 ["|"], 164 164 ["^"], 165 165 ["&"], 166 166 ["<<", ">>"], 167 167 ["+","-"], 168 168 ["~"], 169 169 ["*","/","%"], 170 - ["^^","**"] 170 + ["^^","**"], 171 + [".",".?"] 171 172 ]; 172 173 173 174 AST E(size_t level) 174 175 { 175 176 /// Expression ::= (Binary left-associative operators over) Funcall 176 177 177 178 AST rec(AST lhs) ................................................................................ 178 179 { 179 180 if( closingBracket() ) 180 181 return lhs; 181 182 182 183 auto pos = currentPosition(); 183 184 foreach(op; operator_perferences[level]) 184 185 if( tryEat(op) ) 186 + if( op[0]=='.' ) 187 + return rec( 188 + new FuncallExpression(lhs.pos, new VarExpression(pos, op), lhs, parseId())); 189 + else 185 190 return rec( 186 191 new FuncallExpression(lhs.pos, new VarExpression(pos, op), lhs, E(level+1))); 187 192 return lhs; 188 193 } 189 194 190 195 if( operator_perferences.length <= level ) 191 196 return Funcall(); ................................................................................ 241 246 return new LayeredExpression(pos, lay, e); 242 247 } 243 248 if( tryEat("(") ) 244 249 { 245 250 auto e = Body(); 246 251 eat(")", "after parenthesized expression"); 247 252 return e; 253 + } 254 + if( tryEat("{") ) 255 + { 256 + AST e = new FuncallExpression(pos, new VarExpression(pos,"{}")); 257 + if( tryEat("}") ) 258 + return e; 259 + for(;;) 260 + { 261 + string key = eatId("for table key", AllowQuoted); 262 + eat(":", "after table key"); 263 + AST val = E(0); 264 + e = new FuncallExpression(pos, new VarExpression(pos,".="), 265 + e, new StrLiteral(pos,key), val); 266 + if( !tryEat(",") ) 267 + { 268 + eat("}", "for the end of table literal"); 269 + break; 270 + } 271 + } 272 + return e; 248 273 } 249 274 if( tryEat("if") ) 250 275 { 251 276 eat("(", "after if"); 252 277 auto cond = E(0); 253 278 eat(")", "after if condition"); 254 279 auto thenPos = lex.front.pos; ................................................................................ 273 298 { 274 299 eat("(", "after fun"); 275 300 return parseLambdaAfterOpenParen(pos); 276 301 } 277 302 scope(exit) lex.popFront; 278 303 return new VarExpression(pos, lex.front.str); 279 304 } 305 + 306 + AST parseId() 307 + { 308 + scope(exit) lex.popFront; 309 + return new StrLiteral(currentPosition(), lex.front.str); 310 + } 280 311 281 312 AST parseLambdaAfterOpenParen(immutable LexPosition pos) 282 313 { 283 314 Parameter[] params; 284 315 while( !tryEat(")") ) 285 316 { 286 317 params ~= parseParam(); ................................................................................ 434 465 let("foo", "", 435 466 fun(["x"], call(var("+"), var("x"), intl(1))), 436 467 var("foo")) 437 468 ); 438 469 439 470 assert_eq(parseString(`@@type ( x ) { x }`), 440 471 let("@type", "(system)", fun(["x"], var("x")), var("@type")) ); 472 + 473 + assert_eq(parseString(`{}`), call(var("{}"))); 474 + assert_eq(parseString(`{foo:1,"bar":2}`), 475 + call(var(".="), call(var(".="), call(var("{}")), strl("foo"), intl(1)), strl("bar"), intl(2))); 476 + assert_eq(parseString(`{}.foo`), call(var("."),call(var("{}")),strl("foo"))); 477 + assert_eq(parseString(`{}.?foo`), call(var(".?"),call(var("{}")),strl("foo"))); 441 478 }