Differences From 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]
To Artifact [71d187282fb3ce05]:
- File
polemy/parse.d
- 2010-11-21 09:53:17 - part of checkin [435fa085ec] on branch trunk - refactored predefined layer names, and filled readme.txt. (user: kinaba) [annotate]
5 5 * Parser for Polemy programming language
6 6 */
7 7 module polemy.parse;
8 8 import polemy._common;
9 9 import polemy.failure;
10 10 import polemy.lex;
11 11 import polemy.ast;
12 +import polemy.layer;
12 13
13 14 /// Parse a string and return its AST
14 15 /// Throws: ParseException, LexException, UnexpectedEOF
15 16
16 17 AST parseString(S, T...)(S str, T fn_ln_cn)
17 18 {
18 19 return parserFromString(str, fn_ln_cn).parse();
................................................................................
98 99 string kwd = "@" ~ layer;
99 100 string var = layer;
100 101
101 102 auto e = tryEat("(")
102 103 ? parseLambdaAfterOpenParen(pos) // let var ( ...
103 104 : (eat("=", "after "~kwd), E(0)); // let var = ...
104 105 if( moreDeclarationExists() )
105 - return new LetExpression(pos, var, "(system)", e, Body());
106 + return new LetExpression(pos, var, SystemLayer, e, Body());
106 107 else
107 - return new LetExpression(pos, var, "(system)", e, new VarExpression(pos, var));
108 + return new LetExpression(pos, var, SystemLayer, e, new VarExpression(pos, var));
108 109 }
109 110 else
110 111 {
111 112 string kwd = layer;
112 113 if( layer.empty && !tryEat(kwd="let") && !tryEat(kwd="var") && !tryEat(kwd="def") )
113 114 return null; // none of {@lay, let, var, def} occurred, it's not a declaration
114 115
................................................................................
471 472 assert_eq(parseString(`def foo(x) { x+1 }; foo`),
472 473 let("foo", "",
473 474 fun(["x"], call(var("+"), var("x"), intl(1))),
474 475 var("foo"))
475 476 );
476 477
477 478 assert_eq(parseString(`@@type ( x ) { x }`),
478 - let("@type", "(system)", fun(["x"], var("x")), var("@type")) );
479 + let("@type", SystemLayer, fun(["x"], var("x")), var("@type")) );
479 480
480 481 assert_eq(parseString(`{}`), call(var("{}")));
481 482 assert_eq(parseString(`{foo:1,"bar":2}`),
482 483 call(var(".="), call(var(".="), call(var("{}")), strl("foo"), intl(1)), strl("bar"), intl(2)));
483 484 assert_eq(parseString(`{}.foo`), call(var("."),call(var("{}")),strl("foo")));
484 485 assert_eq(parseString(`{}.?foo`), call(var(".?"),call(var("{}")),strl("foo")));
485 486 assert_eq(parseString(`x{y:1}`), call(var(".="),var("x"),strl("y"),intl(1)));
486 487 }