Differences From Artifact [9aca36046bea5df8]:
- File
polemy/parse.d
- 2010-11-26 05:03:10 - part of checkin [207cea338a] on branch trunk - changed hiding mechanizem of x in let x = ... for @macro layer. Old: set(x,ValueLayer,undefined) Nee: set(x,NoopLayer,null) (user: kinaba) [annotate]
To Artifact [3ad9850246d5111f]:
- File
polemy/parse.d
- 2010-11-26 05:29:24 - part of checkin [f8684f4d69] on branch trunk - changed the desugaring of >>@macro x=e from >>@macro x=e in x to >>@macro x=e in "(macro definition)" for convenience during REPL interaction (user: kinaba) [annotate]
118 118 string var = eatId("after "~kwd, AllowQuoted); // name of the declared variable
119 119
120 120 auto e = tryEat("(")
121 121 ? parseLambdaAfterOpenParen(pos) // let var ( ...
122 122 : (eat("=", "after "~kwd), E(0)); // let var = ...
123 123 if( moreDeclarationExists() )
124 124 return new Let(pos, var, layer, e, Body());
125 - else
126 - return new Let(pos, var, layer, e, new Var(varpos, var));
125 + else {
126 + if( layer.empty )
127 + return new Let(pos, var, layer, e, new Var(varpos, var));
128 + else if( isMacroLayer(layer) )
129 + return new Let(pos, var, layer, e, new Str(varpos, "(macro definition)"));
130 + else
131 + return new Let(pos, var, layer, e, new Lay(varpos, layer, new Var(varpos, var)));
132 + }
127 133 }
128 134 }
129 135
130 136 AST TopLevelExpression()
131 137 {
132 138 /// TopLevelExpression ::= Expression ([";"|"in"] Body?)?
133 139
................................................................................
567 573 mixin EasyAST;
568 574
569 575 assert_eq(parseString(`123`), intl(123));
570 576 assert_eq(parseString(`"foo"`), strl("foo"));
571 577 assert_eq(parseString(`fun(){1}`), fun([],intl(1)));
572 578 assert_eq(parseString(`fun(x){1}`), fun(["x"],intl(1)));
573 579 assert_eq(parseString("\u03BB(){1}"), fun([],intl(1)));
574 - assert_eq(parseString("\u03BB(x){1}"), fun(["x"],intl(1)));
580 + assert_eq(parseString("\u03BB(x,y){1}"), fun(["x","y"],intl(1)));
575 581 assert_eq(parseString(`1;2`), let("_","",intl(1),intl(2)));
576 582 assert_eq(parseString(`1;2;`), let("_","",intl(1),intl(2)));
577 583 assert_eq(parseString(`let x=1 in 2`), let("x","",intl(1),intl(2)));
578 584 assert_eq(parseString(`var x=1;2;`), let("x","",intl(1),intl(2)));
579 585 assert_eq(parseString(`def x=1`), let("x","",intl(1),var("x")));
580 - assert_eq(parseString(`@val x=1;`), let("x","@val",intl(1),var("x")));
581 - assert_eq(parseString(`@typ x="#int";`), let("x","@typ",strl("#int"),var("x")));
586 + assert_eq(parseString(`@val x=1;`), let("x","@val",intl(1),lay("@val",var("x"))));
587 + assert_eq(parseString(`@typ x="#int";`), let("x","@typ",strl("#int"),lay("@typ",var("x"))));
588 + assert_eq(parseString(`@macro x=1`), let("x","@macro",intl(1),strl("(macro definition)")));
582 589 assert_eq(parseString(`f(1,2)`), call(var("f"),intl(1),intl(2)));
583 590 assert_eq(parseString(`if 1 then 2`), call(var("if"),intl(1),fun([],intl(2)),fun([],strl("(empty function body)"))));
584 591 assert_eq(parseString(`if 1 then: 2 else(3)`), call(var("if"),intl(1),fun([],intl(2)),fun([],intl(3))));
585 592 assert_eq(parseString(`(if 1 then () else 3)()()`),
586 593 call(call(call(var("if"),intl(1),fun([],strl("(empty function body)")),fun([],intl(3))))));
587 594 assert_eq(parseString(`1+2*3`), call(var("+"),intl(1),call(var("*"),intl(2),intl(3))));
588 595 assert_eq(parseString(`(1+2)*3`), call(var("*"),call(var("+"),intl(1),intl(2)),intl(3)));