-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAst.h
56 lines (53 loc) · 1.12 KB
/
Ast.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#pragma once
#include<string>
#include<vector>
#include "Log.h"
using namespace std;
#define AstNodeVector vector<AstNode*>
#define AstNodeVectorItr vector<AstNode*>::iterator
#define AstNodeVectorFor(vec) for(AstNodeVectorItr it = vec.begin();it != vec.end(); ++it)
namespace yfpeg {
class Ctx;
class OneScope;
class AstNode {
public :
AstNode():parent(nullptr),scope(nullptr) {};
AstNode* parent;
OneScope* scope;
vector<AstNode*> children;
string path;
string tag;
string captured;
string meta;
void add_child(AstNode* child) {
child->parent = this;
children.push_back(child);
}
string& add_path(string parentPath,string tag) {
path = parentPath + "." + tag;
return path;
}
void add_tag(string tag) {
this->tag = tag;
}
void add_meta(string meta) {
this->meta= meta;
}
//DEBUG
string getIndent(int level) {
string ret = "";
for (int i = 0; i < level; ++i) {
ret += " ";
}
return ret;
};
void walk(Ctx* ctx,int level = 0) ;
};
class Ast
{
public:
Ast() {};
AstNode root;
string matched;
};
}