Differences From Artifact [de91c770214a43a1]:
- File
polemy/parse.d
- 2010-11-08 11:42:14 - part of checkin [5e407d7cf8] on branch trunk - Lexer Refactored so that it can accpet multi-symbol token (user: kinaba) [annotate]
To Artifact [51dd3bd106fd9ecb]:
- File
polemy/parse.d
- 2010-11-08 12:26:39 - part of checkin [80ff567c75] on branch trunk - Testing easyAST. (user: kinaba) [annotate]
303 303 {
304 304 auto p = parserFromString(`
305 305 var zzz = 100; # comment
306 306 zzz = zzz + zzz * "fo\no"; # comment
307 307 42;
308 308 `);
309 309
310 - auto s0 = new DeclStatement(null, "zzz", new IntLiteralExpression(null, BigInt(100)));
311 - auto s1 = new ExprStatement(null, new AssignExpression(null,
310 + mixin EasyAst;
311 + auto s0 = decl("zzz", intl(BigInt(100)));
312 + auto s1 = expr( new AssignExpression(null,
312 313 new VarExpression(null, "zzz"),
313 314 new FuncallExpression(null, new VarExpression(null,"+"),
314 315 new VarExpression(null, "zzz"),
315 316 new FuncallExpression(null, new VarExpression(null,"*"),
316 317 new VarExpression(null, "zzz"),
317 318 new StrLiteralExpression(null, "fo\\no")
318 319 ))));
................................................................................
327 328
328 329 unittest
329 330 {
330 331 auto p = parserFromString(`
331 332 var f = fun(x,y){x+y;};
332 333 f(1,fun(abc){}(4));
333 334 `);
335 + mixin EasyAst;
334 336 Program prog = p.parseProgram();
335 337 assert( prog.length == 2 );
336 - assert( prog[0] == new DeclStatement(null, "f", new FunLiteralExpression(null,
337 - ["x","y"], [new ExprStatement(null,
338 - new FuncallExpression(null, new VarExpression(null, "+"),
339 - new VarExpression(null, "x"), new VarExpression(null, "y")))]
340 - )));
341 - assert( prog[1] == new ExprStatement(null, new FuncallExpression(null,
342 - new VarExpression(null, "f"),
343 - new IntLiteralExpression(null, BigInt(1)),
344 - new FuncallExpression(null,
345 - new FunLiteralExpression(null, ["abc"], [
346 - ]),
347 - new IntLiteralExpression(null, BigInt(4))
348 - ))));
338 + assert( prog[0] == decl("f", fun(
339 + ["x","y"], [expr(funcall(var("+"), var("x"), var("y")))]
340 + )));
341 + assert( prog[1] == expr(funcall(var("f"),
342 + intl(BigInt(1)),
343 + funcall(
344 + fun(["abc"], cast(Statement[])[]),
345 + intl(BigInt(4))
346 + ))));
349 347 }
350 348
351 349 unittest
352 350 {
353 351 auto p = parserFromString(`var x = 1; var f = fun(){x=x+1;}; f(); f(); x;`);
354 352 Program prog = p.parseProgram();
355 353 }