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 AST Body() 57 AST Body()
58 { 58 {
59 if( lex.empty || !lex.front.quoted && lex.front.str=="}" ) 59 if( lex.empty || !lex.front.quoted && lex.front.str=="}" )
60 return doNothingExpression(); 60 return doNothingExpression();
61 61
> 62 auto saved = lex.save;
62 auto pos = lex.front.pos; 63 auto pos = lex.front.pos;
63 string kwd = lex.front.str; 64 string kwd = lex.front.str;
64 if( tryEat("let") || tryEat("var") || tryEat("def") || tryEat("@ 65 if( tryEat("let") || tryEat("var") || tryEat("def") || tryEat("@
65 { 66 {
66 if( kwd == "@" ) | 67 if( kwd == "@" ) {
67 kwd ~= eatId("after @"); 68 kwd ~= eatId("after @");
> 69 if( tryEat("(") ) {
> 70 lex = saved;
> 71 goto asExpression;
> 72 }
> 73 }
68 immutable LexPosition varpos = (lex.empty ? null : lex.f 74 immutable LexPosition varpos = (lex.empty ? null : lex.f
69 string var = eatId("after "~kwd); 75 string var = eatId("after "~kwd);
70 eat("=", "after "~kwd); 76 eat("=", "after "~kwd);
71 kwd = (kwd[0]=='@' ? kwd : ""); // "let, var, def ==> ne 77 kwd = (kwd[0]=='@' ? kwd : ""); // "let, var, def ==> ne
72 auto e = E(0); 78 auto e = E(0);
73 if( tryEat(";") && !lex.empty && (lex.front.quoted || (l 79 if( tryEat(";") && !lex.empty && (lex.front.quoted || (l
74 return new LetExpression(pos, var, kwd, e, Body( 80 return new LetExpression(pos, var, kwd, e, Body(
75 else 81 else
76 return new LetExpression(pos, var, kwd, e, new V 82 return new LetExpression(pos, var, kwd, e, new V
77 } 83 }
78 else 84 else
79 { 85 {
> 86 asExpression:
80 auto e = E(0); 87 auto e = E(0);
81 if( tryEat(";") && !lex.empty && (lex.front.quoted || (l 88 if( tryEat(";") && !lex.empty && (lex.front.quoted || (l
82 return new LetExpression(pos, "_", "@val", e, Bo 89 return new LetExpression(pos, "_", "@val", e, Bo
83 else 90 else
84 return e; 91 return e;
85 } 92 }
86 } 93 }
................................................................................................................................................................................
158 return new StrLiteral(pos, lex.front.str); 165 return new StrLiteral(pos, lex.front.str);
159 } 166 }
160 if( isNumber(lex.front.str) ) 167 if( isNumber(lex.front.str) )
161 { 168 {
162 scope(exit) lex.popFront; 169 scope(exit) lex.popFront;
163 return new IntLiteral(pos, BigInt(cast(string)lex.front. 170 return new IntLiteral(pos, BigInt(cast(string)lex.front.
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 if( tryEat("(") ) 180 if( tryEat("(") )
166 { 181 {
167 auto e = Body(); 182 auto e = Body();
168 eat(")", "after parenthesized expression"); 183 eat(")", "after parenthesized expression");
169 return e; 184 return e;
170 } 185 }
171 if( tryEat("if") ) 186 if( tryEat("if") )
................................................................................................................................................................................
273 assert_eq(parseString(`if(1){2}else{3}`), call(var("if"),intl(1),fun([], 288 assert_eq(parseString(`if(1){2}else{3}`), call(var("if"),intl(1),fun([],
274 assert_eq(parseString(`if(1){}else{3}()()`), 289 assert_eq(parseString(`if(1){}else{3}()()`),
275 call(call(call(var("if"),intl(1),fun([],intl(178)),fun([],intl(3 290 call(call(call(var("if"),intl(1),fun([],intl(178)),fun([],intl(3
276 assert_eq(parseString(`1+2*3`), call(var("+"),intl(1),call(var("*"),intl 291 assert_eq(parseString(`1+2*3`), call(var("+"),intl(1),call(var("*"),intl
277 assert_eq(parseString(`(1+2)*3`), call(var("*"),call(var("+"),intl(1),in 292 assert_eq(parseString(`(1+2)*3`), call(var("*"),call(var("+"),intl(1),in
278 assert_eq(parseString(`1*(2+3)`), call(var("*"),intl(1),call(var("+"),in 293 assert_eq(parseString(`1*(2+3)`), call(var("*"),intl(1),call(var("+"),in
279 assert_eq(parseString(`1*2+3`), call(var("+"),call(var("*"),intl(1),intl 294 assert_eq(parseString(`1*2+3`), call(var("+"),call(var("*"),intl(1),intl
> 295 assert_eq(parseString(`@x(1)`), lay("@x", intl(1)));
280 296
281 assert_eq(parseString(` 297 assert_eq(parseString(`
282 let x = 100; #comment 298 let x = 100; #comment
283 let y = 200; #comment!!!!! 299 let y = 200; #comment!!!!!
284 x+y 300 x+y
285 `), 301 `),
286 let("x", "", intl(100), let("y", "", intl(200), call(var("+"), v 302 let("x", "", intl(100), let("y", "", intl(200), call(var("+"), v