Differences From Artifact [e14df84da140adf3]:
- File
polemy/parse.d
- 2010-11-09 07:27:21 - part of checkin [0f02103885] on branch trunk - let, var, def became layer-neutral definition (not @val). scope splitting (let x=1;let x=2;let y=(let x=3);x is 1) is correctly implemented now. (user: kinaba) [annotate]
To Artifact [fafb5e120f10db35]:
- File
polemy/parse.d
- 2010-11-09 10:28:08 - part of checkin [dc93ad8cf6] on branch trunk - layered exec expression @lay(...) added (user: kinaba) [annotate]
55 55 }
56 56
57 57 AST Body()
58 58 {
59 59 if( lex.empty || !lex.front.quoted && lex.front.str=="}" )
60 60 return doNothingExpression();
61 61
62 + auto saved = lex.save;
62 63 auto pos = lex.front.pos;
63 64 string kwd = lex.front.str;
64 65 if( tryEat("let") || tryEat("var") || tryEat("def") || tryEat("@") )
65 66 {
66 - if( kwd == "@" )
67 + if( kwd == "@" ) {
67 68 kwd ~= eatId("after @");
69 + if( tryEat("(") ) {
70 + lex = saved;
71 + goto asExpression;
72 + }
73 + }
68 74 immutable LexPosition varpos = (lex.empty ? null : lex.front.pos);
69 75 string var = eatId("after "~kwd);
70 76 eat("=", "after "~kwd);
71 77 kwd = (kwd[0]=='@' ? kwd : ""); // "let, var, def ==> neutral layer"
72 78 auto e = E(0);
73 79 if( tryEat(";") && !lex.empty && (lex.front.quoted || (lex.front.str!="}" && lex.front.str!=")")) )
74 80 return new LetExpression(pos, var, kwd, e, Body());
75 81 else
76 82 return new LetExpression(pos, var, kwd, e, new VarExpression(varpos, var));
77 83 }
78 84 else
79 85 {
86 + asExpression:
80 87 auto e = E(0);
81 88 if( tryEat(";") && !lex.empty && (lex.front.quoted || (lex.front.str!="}" && lex.front.str!=")")) )
82 89 return new LetExpression(pos, "_", "@val", e, Body());
83 90 else
84 91 return e;
85 92 }
86 93 }
................................................................................
158 165 return new StrLiteral(pos, lex.front.str);
159 166 }
160 167 if( isNumber(lex.front.str) )
161 168 {
162 169 scope(exit) lex.popFront;
163 170 return new IntLiteral(pos, BigInt(cast(string)lex.front.str));
164 171 }
172 + if( tryEat("@") )
173 + {
174 + auto lay = "@"~eatId("for layer ID");
175 + eat("(", "for layered execution");
176 + auto e = E(0);
177 + eat(")", "after "~lay~"(...");
178 + return new LayeredExpression(pos, lay, e);
179 + }
165 180 if( tryEat("(") )
166 181 {
167 182 auto e = Body();
168 183 eat(")", "after parenthesized expression");
169 184 return e;
170 185 }
171 186 if( tryEat("if") )
................................................................................
273 288 assert_eq(parseString(`if(1){2}else{3}`), call(var("if"),intl(1),fun([],intl(2)),fun([],intl(3))));
274 289 assert_eq(parseString(`if(1){}else{3}()()`),
275 290 call(call(call(var("if"),intl(1),fun([],intl(178)),fun([],intl(3))))));
276 291 assert_eq(parseString(`1+2*3`), call(var("+"),intl(1),call(var("*"),intl(2),intl(3))));
277 292 assert_eq(parseString(`(1+2)*3`), call(var("*"),call(var("+"),intl(1),intl(2)),intl(3)));
278 293 assert_eq(parseString(`1*(2+3)`), call(var("*"),intl(1),call(var("+"),intl(2),intl(3))));
279 294 assert_eq(parseString(`1*2+3`), call(var("+"),call(var("*"),intl(1),intl(2)),intl(3)));
295 + assert_eq(parseString(`@x(1)`), lay("@x", intl(1)));
280 296
281 297 assert_eq(parseString(`
282 298 let x = 100; #comment
283 299 let y = 200; #comment!!!!!
284 300 x+y
285 301 `),
286 302 let("x", "", intl(100), let("y", "", intl(200), call(var("+"), var("x"), var("y"))))