Differences From Artifact [7ed0053850ffa032]:
- File
polemy/parse.d
- 2010-11-13 03:55:17 - part of checkin [c368edbcb1] on branch trunk - @@lay(x) { ... } declaration and value rising. (user: kinaba) [annotate]
To Artifact [6bec0997c5764737]:
- File
polemy/parse.d
- 2010-11-20 09:20:03 - part of checkin [515502e8d1] on branch trunk - table get, init, ask expressions addded (user: kinaba) [annotate]
163 ["|"], 163 ["|"],
164 ["^"], 164 ["^"],
165 ["&"], 165 ["&"],
166 ["<<", ">>"], 166 ["<<", ">>"],
167 ["+","-"], 167 ["+","-"],
168 ["~"], 168 ["~"],
169 ["*","/","%"], 169 ["*","/","%"],
170 ["^^","**"] | 170 ["^^","**"],
> 171 [".",".?"]
171 ]; 172 ];
172 173
173 AST E(size_t level) 174 AST E(size_t level)
174 { 175 {
175 /// Expression ::= (Binary left-associative operators over) Func 176 /// Expression ::= (Binary left-associative operators over) Func
176 177
177 AST rec(AST lhs) 178 AST rec(AST lhs)
................................................................................................................................................................................
178 { 179 {
179 if( closingBracket() ) 180 if( closingBracket() )
180 return lhs; 181 return lhs;
181 182
182 auto pos = currentPosition(); 183 auto pos = currentPosition();
183 foreach(op; operator_perferences[level]) 184 foreach(op; operator_perferences[level])
184 if( tryEat(op) ) 185 if( tryEat(op) )
> 186 if( op[0]=='.' )
> 187 return rec(
> 188 new FuncallExpression(lh
> 189 else
185 return rec( 190 return rec(
186 new FuncallExpression(lhs.pos, n 191 new FuncallExpression(lhs.pos, n
187 return lhs; 192 return lhs;
188 } 193 }
189 194
190 if( operator_perferences.length <= level ) 195 if( operator_perferences.length <= level )
191 return Funcall(); 196 return Funcall();
................................................................................................................................................................................
241 return new LayeredExpression(pos, lay, e); 246 return new LayeredExpression(pos, lay, e);
242 } 247 }
243 if( tryEat("(") ) 248 if( tryEat("(") )
244 { 249 {
245 auto e = Body(); 250 auto e = Body();
246 eat(")", "after parenthesized expression"); 251 eat(")", "after parenthesized expression");
247 return e; 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
> 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 if( tryEat("if") ) 274 if( tryEat("if") )
250 { 275 {
251 eat("(", "after if"); 276 eat("(", "after if");
252 auto cond = E(0); 277 auto cond = E(0);
253 eat(")", "after if condition"); 278 eat(")", "after if condition");
254 auto thenPos = lex.front.pos; 279 auto thenPos = lex.front.pos;
................................................................................................................................................................................
273 { 298 {
274 eat("(", "after fun"); 299 eat("(", "after fun");
275 return parseLambdaAfterOpenParen(pos); 300 return parseLambdaAfterOpenParen(pos);
276 } 301 }
277 scope(exit) lex.popFront; 302 scope(exit) lex.popFront;
278 return new VarExpression(pos, lex.front.str); 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 AST parseLambdaAfterOpenParen(immutable LexPosition pos) 312 AST parseLambdaAfterOpenParen(immutable LexPosition pos)
282 { 313 {
283 Parameter[] params; 314 Parameter[] params;
284 while( !tryEat(")") ) 315 while( !tryEat(")") )
285 { 316 {
286 params ~= parseParam(); 317 params ~= parseParam();
................................................................................................................................................................................
434 let("foo", "", 465 let("foo", "",
435 fun(["x"], call(var("+"), var("x"), intl(1))), 466 fun(["x"], call(var("+"), var("x"), intl(1))),
436 var("foo")) 467 var("foo"))
437 ); 468 );
438 469
439 assert_eq(parseString(`@@type ( x ) { x }`), 470 assert_eq(parseString(`@@type ( x ) { x }`),
440 let("@type", "(system)", fun(["x"], var("x")), var("@type")) ); 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"), in
> 476 assert_eq(parseString(`{}.foo`), call(var("."),call(var("{}")),strl("foo
> 477 assert_eq(parseString(`{}.?foo`), call(var(".?"),call(var("{}")),strl("f
441 } 478 }