Diff
Not logged in

Differences From Artifact [9b22488b3393157f]:

To Artifact [f03af1208bc8c434]:


2 2 * Authors: k.inaba 3 3 * License: NYSL 0.9982 http://www.kmonos.net/nysl/ 4 4 * 5 5 * Syntax tree for Polemy programming language. 6 6 */ 7 7 module polemy.ast; 8 8 import polemy._common; 9 -import polemy.lex : LexPosition; 9 +import polemy.lex; 10 10 11 11 alias Statement[] Program; 12 12 13 13 abstract class Statement 14 14 { 15 15 immutable LexPosition pos; 16 16 mixin SimpleConstructor; 17 17 } 18 18 19 19 class DeclStatement : Statement 20 20 { 21 21 string var; 22 22 Expression expr; 23 - mixin SimpleConstructor; 24 - mixin SimpleCompare; 23 + mixin SimpleClass; 25 24 } 26 25 27 26 class ExprStatement : Statement 28 27 { 29 28 Expression expr; 30 - mixin SimpleConstructor; 31 - mixin SimpleCompare; 29 + mixin SimpleClass; 32 30 } 33 31 34 32 abstract class Expression 35 33 { 36 34 immutable LexPosition pos; 37 35 mixin SimpleConstructor; 38 - mixin SimpleCompare; 39 36 } 40 37 41 38 class StrLiteralExpression : Expression 42 39 { 43 40 string data; 44 - mixin SimpleConstructor; 45 - mixin SimpleCompare; 41 + mixin SimpleClass; 46 42 } 47 43 48 44 class IntLiteralExpression : Expression 49 45 { 50 46 BigInt data; 51 - mixin SimpleConstructor; 52 - mixin SimpleCompare; 47 + mixin SimpleClass; 53 48 } 54 49 55 50 class VarExpression : Expression 56 51 { 57 52 string var; 58 - mixin SimpleConstructor; 59 - mixin SimpleCompare; 53 + mixin SimpleClass; 60 54 } 61 55 62 56 class AssignExpression : Expression 63 57 { 64 58 Expression lhs; 65 59 Expression rhs; 66 - mixin SimpleConstructor; 67 - mixin SimpleCompare; 60 + mixin SimpleClass; 68 61 } 69 62 70 63 class FuncallExpression : Expression 71 64 { 72 65 Expression fun; 73 66 Expression[] args; 74 67 this(immutable LexPosition pos, Expression fun, Expression[] args...) 75 68 { super(pos); this.fun=fun; this.args=args.dup; } 76 - mixin SimpleCompare; 69 + mixin SimpleClass; 77 70 } 78 71 79 72 class FunLiteralExpression : Expression 80 73 { 81 74 string[] params; 82 75 Program funbody; 83 - mixin SimpleConstructor; 84 - mixin SimpleCompare; 76 + mixin SimpleClass; 77 +} 78 + 79 +/// Handy Generator for AST nodes. To use this, mixin EasyAst; 80 + 81 +/*mixin*/ 82 +template EasyAst() 83 +{ 84 + template genEast(T) 85 + { T genEast(P...)(P ps) { return new T(LexPosition.dummy, ps); } } 86 + 87 + alias genEast!DeclStatement decl; 88 + alias genEast!ExprStatement expr; 89 + alias genEast!VarExpression var; 90 + alias genEast!FuncallExpression funcall; 91 + alias genEast!IntLiteralExpression intl; 92 + alias genEast!StrLiteralExpression strl; 93 + alias genEast!FunLiteralExpression fun; 85 94 }