Check-in [6ecc7046fc]
Not logged in
Overview
SHA1 Hash:6ecc7046fcdc27e87af8a373c493df634067d842
Date: 2010-11-21 17:33:47
User: kinaba
Comment:tableset x{y:1} expression added
Timelines: family | ancestors | descendants | both | trunk
Downloads: Tarball | ZIP archive
Other Links: files | file ages | manifest
Tags And Properties
Changes

Modified polemy/parse.d from [a024e7c2d40e70c4] to [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 }

Modified tricks/test.d from [b9b84a35fccc5116] to [3ba75b9c3bef69b2].

100 100 assert_throw!AssertError( assert_throw!Error(nothing()) ); 101 101 assert_nothrow ( assert_throw!Error(assertError()) ); 102 102 assert_throw!AssertError( assert_throw!AssertError(error()) ); 103 103 } 104 104 105 105 template assertOp(string op) 106 106 { 107 - void assertOp(A, B, string fn=__FILE__, size_t ln=__LINE__)(A a, B b, string msg="") 107 + void assertOp(A, B, string fn=__FILE__, size_t ln=__LINE__)(lazy A a_, lazy B b_, string msg="") 108 108 { 109 109 try 110 - { if( mixin("a"~op~"b") ) return; } 110 + { A a=a_(); B b=b_(); if( mixin("a"~op~"b") ) return; 111 + onAssertErrorMsg(fn, ln, msg.length ? msg : text(a, " !", op, " ", b)); } 111 112 catch(Throwable e) 112 113 { onAssertErrorMsg(fn, ln, msg.length ? msg : "bad exception \n >> "~e.toString()); } 113 - onAssertErrorMsg(fn, ln, msg.length ? msg : text(a, " !", op, " ", b)); 114 + assert(false); 114 115 } 115 116 } 116 117 117 118 alias assertOp!(`==`) assert_eq; /// asserts two operands are == 118 119 alias assertOp!(`!=`) assert_ne; /// asserts two operands are != 119 120 alias assertOp!(`<`) assert_lt; /// asserts two operands are < 120 121 alias assertOp!(`<=`) assert_le; /// asserts two operands are <=