Diff
Not logged in

Differences From Artifact [dd714695d64176f9]:

To Artifact [b8324439b8512940]:


4 4 * 5 5 * Syntax tree for Polemy programming language. 6 6 */ 7 7 module polemy.ast; 8 8 import polemy._common; 9 9 import polemy.lex; 10 10 11 +/// 11 12 abstract class AST 12 13 { 13 14 immutable LexPosition pos; 14 15 mixin SimpleConstructor; 15 16 } 16 17 18 +/// 17 19 class StrLiteral : AST 18 20 { 19 21 string data; 20 22 mixin SimpleClass; 21 23 } 22 24 25 +/// 23 26 class IntLiteral : AST 24 27 { 25 28 BigInt data; 26 29 mixin SimpleClass; 27 30 this(immutable LexPosition pos, long n) {super(pos); data = n;} 28 31 this(immutable LexPosition pos, BigInt n) {super(pos); data = n;} 29 32 this(immutable LexPosition pos, string n) {super(pos); data = BigInt(n);} 30 33 } 31 34 35 +/// 32 36 class VarExpression : AST 33 37 { 34 38 string var; 35 39 mixin SimpleClass; 36 40 } 37 41 42 +/// 38 43 class LayeredExpression : AST 39 44 { 40 45 string lay; 41 46 AST expr; 42 47 mixin SimpleClass; 43 48 } 44 49 50 +/// 45 51 class LetExpression : AST 46 52 { 47 53 string var; 48 54 string layer; 49 55 AST init; 50 56 AST expr; 51 57 mixin SimpleClass; 52 58 } 53 59 60 +/// 54 61 class FuncallExpression : AST 55 62 { 56 63 AST fun; 57 64 AST[] args; 58 65 this(immutable LexPosition pos, AST fun, AST[] args...) 59 66 { super(pos); this.fun=fun; this.args=args.dup; } 60 67 mixin SimpleClass; 61 68 } 62 69 70 +/// 63 71 class FunLiteral : AST 64 72 { 65 73 string[] params; 66 74 AST funbody; 67 75 mixin SimpleClass; 68 76 } 69 77 70 78 /// Handy Generator for AST nodes. To use this, mixin EasyAst; 71 79 72 80 /*mixin*/ 73 81 template EasyAST() 74 82 { 83 + /// 75 84 template genEast(T) 76 85 { T genEast(P...)(P ps) { return new T(LexPosition.dummy, ps); } } 77 86 78 - alias genEast!StrLiteral strl; 79 - alias genEast!IntLiteral intl; 80 - auto fun(string[] xs, AST ps) { return genEast!FunLiteral(xs,ps); } // to help type inference of D 81 - alias genEast!VarExpression var; 82 - alias genEast!LayeredExpression lay; 83 - alias genEast!LetExpression let; 84 - alias genEast!FuncallExpression call; 87 + alias genEast!StrLiteral strl; /// 88 + alias genEast!IntLiteral intl; /// 89 + auto fun(string[] xs, AST ps) { return genEast!FunLiteral(xs,ps); } /// 90 + alias genEast!VarExpression var; /// 91 + alias genEast!LayeredExpression lay; /// 92 + alias genEast!LetExpression let; /// 93 + alias genEast!FuncallExpression call; /// 85 94 }