Differences From Artifact [a024e7c2d40e70c4]:
- File
polemy/parse.d
- 2010-11-20 16:35:14 - part of checkin [3464a035ec] on branch trunk - source code cleanup (user: kinaba) [annotate]
To Artifact [25ec86a59533b939]:
- File
polemy/parse.d
- 2010-11-21 08:33:47 - part of checkin [6ecc7046fc] on branch trunk - tableset x{y:1} expression added (user: kinaba) [annotate]
193 } 193 }
194 194
195 AST Funcall() 195 AST Funcall()
196 { 196 {
197 /// Funcall ::= BaseExpression ["(" Expression%"," ")"]* 197 /// Funcall ::= BaseExpression ["(" Expression%"," ")"]*
198 198
199 auto e = BaseExpression(); 199 auto e = BaseExpression();
> 200 for(;;)
200 while( tryEat("(") ) | 201 if( tryEat("(") )
201 { | 202 {
202 auto pos = currentPosition(); | 203 auto pos = currentPosition();
203 AST[] args; | 204 AST[] args;
204 while( !tryEat(")") ) { | 205 while( !tryEat(")") ) {
205 if( lex.empty ) | 206 if( lex.empty )
206 throw genex!UnexpectedEOF(pos, "closing | 207 throw genex!UnexpectedEOF(pos, "
207 args ~= E(0); | 208 args ~= E(0);
208 if( !tryEat(",") ) { | 209 if( !tryEat(",") ) {
209 eat(")", "after function parameters"); | 210 eat(")", "after function paramet
210 break; | 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 }
> 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);
213 e = new FuncallExpression(e.pos, e, args); | 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 return e; 243 return e;
216 } 244 }
217 245
218 AST BaseExpression() 246 AST BaseExpression()
219 { 247 {
220 if( lex.empty ) 248 if( lex.empty )
................................................................................................................................................................................
244 auto e = Body(); 272 auto e = Body();
245 eat(")", "after parenthesized expression"); 273 eat(")", "after parenthesized expression");
246 return e; 274 return e;
247 } 275 }
248 if( tryEat("{") ) 276 if( tryEat("{") )
249 { 277 {
250 AST e = new FuncallExpression(pos, new VarExpression(pos 278 AST e = new FuncallExpression(pos, new VarExpression(pos
251 if( tryEat("}") ) | 279 return parseTableSetAfterBrace(e);
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 <
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; <
267 } 280 }
268 if( tryEat("if") ) 281 if( tryEat("if") )
269 { 282 {
270 eat("(", "after if"); 283 eat("(", "after if");
271 auto cond = E(0); 284 auto cond = E(0);
272 eat(")", "after if condition"); 285 eat(")", "after if condition");
273 auto thenPos = lex.front.pos; 286 auto thenPos = lex.front.pos;
................................................................................................................................................................................
465 let("@type", "(system)", fun(["x"], var("x")), var("@type")) ); 478 let("@type", "(system)", fun(["x"], var("x")), var("@type")) );
466 479
467 assert_eq(parseString(`{}`), call(var("{}"))); 480 assert_eq(parseString(`{}`), call(var("{}")));
468 assert_eq(parseString(`{foo:1,"bar":2}`), 481 assert_eq(parseString(`{foo:1,"bar":2}`),
469 call(var(".="), call(var(".="), call(var("{}")), strl("foo"), in 482 call(var(".="), call(var(".="), call(var("{}")), strl("foo"), in
470 assert_eq(parseString(`{}.foo`), call(var("."),call(var("{}")),strl("foo 483 assert_eq(parseString(`{}.foo`), call(var("."),call(var("{}")),strl("foo
471 assert_eq(parseString(`{}.?foo`), call(var(".?"),call(var("{}")),strl("f 484 assert_eq(parseString(`{}.?foo`), call(var(".?"),call(var("{}")),strl("f
> 485 assert_eq(parseString(`x{y:1}`), call(var(".="),var("x"),strl("y"),intl(
472 } 486 }