@@ -101,12 +101,12 @@ auto e = tryEat("(") ? parseLambdaAfterOpenParen(pos) // let var ( ... : (eat("=", "after "~kwd), E(0)); // let var = ... if( moreDeclarationExists() ) - return new LetExpression(pos, var, SystemLayer, e, Body()); + return new Let(pos, var, SystemLayer, e, Body()); else - return new LetExpression(pos, var, SystemLayer, e, - new LayExpression(pos, SystemLayer, new VarExpression(pos, var)) + return new Let(pos, var, SystemLayer, e, + new Lay(pos, SystemLayer, new Var(pos, var)) ); } else { @@ -120,11 +120,11 @@ auto e = tryEat("(") ? parseLambdaAfterOpenParen(varpos) // let var ( ... : (eat("=", "after "~kwd), E(0)); // let var = ... if( moreDeclarationExists() ) - return new LetExpression(pos, var, layer, e, Body()); + return new Let(pos, var, layer, e, Body()); else - return new LetExpression(pos, var, layer, e, new VarExpression(varpos, var)); + return new Let(pos, var, layer, e, new Var(varpos, var)); } } AST TopLevelExpression() @@ -133,9 +133,9 @@ auto pos = currentPosition(); auto e = E(0); if( moreDeclarationExists() ) - return new LetExpression(pos, "_", "", e, Body()); + return new Let(pos, "_", "", e, Body()); else return e; } @@ -180,12 +180,12 @@ foreach(op; operator_perferences[level]) if( tryEat(op) ) if( op[0]=='.' ) return rec( - new FuncallExpression(lhs.pos, new VarExpression(pos, op), lhs, parseId())); + new App(lhs.pos, new Var(pos, op), lhs, parseId())); else - return rec( - new FuncallExpression(lhs.pos, new VarExpression(pos, op), lhs, E(level+1))); + return rec( + new App(lhs.pos, new Var(pos, op), lhs, E(level+1))); return lhs; } if( operator_perferences.length <= level ) @@ -212,9 +212,9 @@ eat(")", "after function parameters"); break; } } - e = new FuncallExpression(e.pos, e, args); + e = new App(e.pos, e, args); } else if( tryEat("{") ) { e = parseTableSetAfterBrace(e); @@ -233,10 +233,10 @@ { string key = eatId("for table key", AllowQuoted); eat(":", "after table key"); AST val = E(0); - e = new FuncallExpression(pos, new VarExpression(pos,".="), - e, new StrLiteral(pos,key), val); + e = new App(pos, new Var(pos,".="), + e, new Str(pos,key), val); if( !tryEat(",") ) { eat("}", "for the end of table literal"); break; @@ -253,22 +253,22 @@ auto pos = lex.front.pos; if( lex.front.quoted ) { scope(exit) lex.popFront; - return new StrLiteral(pos, lex.front.str); + return new Str(pos, lex.front.str); } if( isNumber(lex.front.str) ) { scope(exit) lex.popFront; - return new IntLiteral(pos, BigInt(cast(string)lex.front.str)); + return new Int(pos, BigInt(cast(string)lex.front.str)); } if( tryEat("@") ) { auto lay = "@"~eatId("for layer ID"); eat("(", "for layered execution"); auto e = Body(); eat(")", "after "~lay~"(..."); - return new LayExpression(pos, lay, e); + return new Lay(pos, lay, e); } if( tryEat("(") ) { auto e = Body(); @@ -276,9 +276,9 @@ return e; } if( tryEat("{") ) { - AST e = new FuncallExpression(pos, new VarExpression(pos,"{}")); + AST e = new App(pos, new Var(pos,"{}")); return parseTableSetAfterBrace(e); } if( tryEat("if") ) { @@ -295,13 +295,13 @@ eat("{", "after else"); el = Body(); eat("}", "after else body"); } - return new FuncallExpression(pos, - new VarExpression(pos, "if"), + return new App(pos, + new Var(pos, "if"), cond, - new FunLiteral(thenPos, [], th), - new FunLiteral(elsePos, [], el) + new Fun(thenPos, [], th), + new Fun(elsePos, [], el) ); } if( tryEat("case") ) { @@ -312,9 +312,9 @@ eat("(", "after fun"); return parseLambdaAfterOpenParen(pos); } scope(exit) lex.popFront; - return new VarExpression(pos, lex.front.str); + return new Var(pos, lex.front.str); } AST parsePatternMatch(LexPosition pos) { @@ -326,10 +326,10 @@ eat(")", "after case"); string pmVar = freshVarName(); string pmTryFirst = freshVarName(); AST pmBody = parsePatternMatchCases(pmVar, pmTryFirst, - new FuncallExpression(pos, new VarExpression(pos, pmTryFirst))); - return new LetExpression(pos, pmVar, [], pmExpr, pmBody); + new App(pos, new Var(pos, pmTryFirst))); + return new Let(pos, pmVar, [], pmExpr, pmBody); } AST parsePatternMatchCases(string pmVar, string tryThisBranchVar, AST thenDoThis) { @@ -346,23 +346,23 @@ auto pr = parsePattern(); eat(")", "after when"); eat("{", "after pattern"); AST cBody = Body(); - AST judgement = new FuncallExpression(pos, new VarExpression(pos, "if"), - ppTest(pmVar, pr), new FunLiteral(pos,[],ppBind(pmVar, pr, cBody)), - new VarExpression(pos, failBranchVar)); + AST judgement = new App(pos, new Var(pos, "if"), + ppTest(pmVar, pr), new Fun(pos,[],ppBind(pmVar, pr, cBody)), + new Var(pos, failBranchVar)); eat("}", "after pattern clause"); return parsePatternMatchCases(pmVar, failBranchVar, - new LetExpression(pos, tryThisBranchVar, [], - new FunLiteral(pos,[],judgement), thenDoThis) + new Let(pos, tryThisBranchVar, [], + new Fun(pos,[],judgement), thenDoThis) ); } else { auto pos = currentPosition(); - AST doNothing = new FunLiteral(pos,[], - new StrLiteral(pos, sprintf!"(pattern match failure:%s)"(pos))); - return new LetExpression(currentPosition(), tryThisBranchVar, [], doNothing, thenDoThis); + AST doNothing = new Fun(pos,[], + new Str(pos, sprintf!"(pattern match failure:%s)"(pos))); + return new Let(currentPosition(), tryThisBranchVar, [], doNothing, thenDoThis); } } // hageshiku tenuki @@ -371,29 +371,29 @@ string[] path; mixin SimpleClass; private AST access(string pmVar, string[] path) { auto pos = currentPosition(); - AST e = new VarExpression(pos, pmVar); + AST e = new Var(pos, pmVar); foreach(p; path) - e = new FuncallExpression(pos, new VarExpression(pos, "."), e, new StrLiteral(pos, p)); + e = new App(pos, new Var(pos, "."), e, new Str(pos, p)); return e; } private AST has(AST e, string k) { auto pos = currentPosition(); return opAndAnd( - new FuncallExpression(pos, new VarExpression(pos, "_istable"), e), - new FuncallExpression(pos, new VarExpression(pos, ".?"), e, new StrLiteral(pos, k)) + new App(pos, new Var(pos, "_istable"), e), + new App(pos, new Var(pos, ".?"), e, new Str(pos, k)) ); } private AST opAndAnd(AST a, AST b) { if( a is null ) return b; if( b is null ) return a; auto pos = currentPosition(); - return new FuncallExpression(pos, - new VarExpression(pos, "if"), + return new App(pos, + new Var(pos, "if"), a, - new FunLiteral(pos, [], b), - new FunLiteral(pos, [], new IntLiteral(pos, 0)) + new Fun(pos, [], b), + new Fun(pos, [], new Int(pos, 0)) ); } AST ppTest(string pmVar) { AST c = null; @@ -412,9 +412,9 @@ string name; mixin SimpleClass; AST ppBind(string pmVar, AST thenDoThis) { auto pos = currentPosition(); - return new LetExpression(pos, name, [], access(pmVar,path), thenDoThis); + return new Let(pos, name, [], access(pmVar,path), thenDoThis); } } class ConstantPattern : SinglePattern { @@ -422,9 +422,9 @@ mixin SimpleClass; AST ppTest(string pmVar) { auto pos = currentPosition(); return opAndAnd( super.ppTest(pmVar), - new FuncallExpression(pos, new VarExpression(pos,"=="), access(pmVar,path), e) + new App(pos, new Var(pos,"=="), access(pmVar,path), e) ); } } @@ -444,9 +444,9 @@ } else { AST e = E(0); - if(auto ev = cast(VarExpression)e) + if(auto ev = cast(Var)e) if(ev.name == "_") result ~= new WildPattern(path); else result ~= new VarPattern(path, ev.name); @@ -463,11 +463,11 @@ foreach(p; pats) { AST c2 = p.ppTest(pmVar); if( c2 !is null ) cond = cond is null ? c2 - : new FuncallExpression(pos, new VarExpression(pos,"&&"), cond, c2); + : new App(pos, new Var(pos,"&&"), cond, c2); } - return cond is null ? new IntLiteral(currentPosition(), 1) : cond; + return cond is null ? new Int(currentPosition(), 1) : cond; } AST ppBind(string pmVar, SinglePattern[] pats, AST thenDoThis) { @@ -478,9 +478,9 @@ AST parseId() { scope(exit) lex.popFront; - return new StrLiteral(currentPosition(), lex.front.str); + return new Str(currentPosition(), lex.front.str); } AST parseLambdaAfterOpenParen(immutable LexPosition pos) { @@ -495,9 +495,9 @@ } eat("{", "after function parameters"); auto funbody = Body(); eat("}", "after function body"); - return new FunLiteral(pos, params, funbody); + return new Fun(pos, params, funbody); } Parameter parseParam() { @@ -557,9 +557,9 @@ } AST doNothingExpression() { - return new StrLiteral(currentPosition(), "(empty function body)"); + return new Str(currentPosition(), "(empty function body)"); } immutable(LexPosition) currentPosition() {