1 module argon.ast; 2 3 import std.format; 4 5 interface ASTVisitor 6 { 7 void visit(ASTTemplateNode node); 8 void visit(ASTHTMLNode node); 9 void visit(ASTIncludeNode node); 10 void visit(ASTElementNode node); 11 void visit(ASTListNode node); 12 void visit(ASTIdentifierNode node); 13 } 14 15 class ASTTemplateNode : ASTNode 16 { 17 string file; 18 ASTNode[] children; 19 20 override void accept(ASTVisitor visitor) 21 { 22 visitor.visit(this); 23 } 24 } 25 26 class ASTHTMLNode : ASTNode 27 { 28 string html; 29 30 override void accept(ASTVisitor visitor) 31 { 32 visitor.visit(this); 33 } 34 } 35 36 class ASTIncludeNode : ASTNode 37 { 38 string file; 39 40 override void accept(ASTVisitor visitor) 41 { 42 visitor.visit(this); 43 } 44 } 45 46 class ASTElementNode : ASTNode 47 { 48 ASTIdentifierNode identifier; 49 50 override void accept(ASTVisitor visitor) 51 { 52 visitor.visit(this); 53 } 54 } 55 56 class ASTListNode : ASTNode 57 { 58 ASTIdentifierNode identifier; 59 ASTNode[] children; 60 61 override void accept(ASTVisitor visitor) 62 { 63 visitor.visit(this); 64 } 65 } 66 67 class ASTIdentifierNode : ASTNode 68 { 69 string namespace; 70 string[] callChain; 71 72 override void accept(ASTVisitor visitor) 73 { 74 visitor.visit(this); 75 } 76 } 77 78 abstract class ASTNode 79 { 80 ASTNode parent; 81 SourceLocation sourceLocation; 82 83 abstract void accept(ASTVisitor visitor); 84 } 85 86 87 class SourceLocation 88 { 89 size_t colunm, line; 90 string file; 91 92 this(string file, size_t line, size_t colunm) 93 { 94 this.file = file; 95 this.line = line; 96 this.colunm = colunm; 97 } 98 99 string getErrorMessage() 100 { 101 return format("at line %s, colunm %s, in file '%s'", line, colunm, file); 102 } 103 }