Joel Grunbaum
2021-07-14 592993dcbb6ab134991836734eb68ebbd31c9946
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
#ifndef AST_H
#define AST_H
#include <vector>
#include <string>
 
//class ast_node;
class ast_visitor;
//class Document;
// class Block;
// class Block_Table;
// class Block_Code;
// class Block_Line;
// class Line;
// class Word;
// class Heading;
// class List;
// class MathDisp;
// class Line_Word;
// class Link;
// class MathInline;
// class Format;
// class Format_Bold;
// class Format_Italic;
// class Format_Verbatim;
// class Text;
 
class ast_node {
public:
    virtual ~ast_node()=default;
    virtual void* visit(ast_visitor *v)=0;
};
 
class Word: public ast_node {};
 
class MathInline: public Word {
    std::string *expr;
public:
    MathInline(std::string *e);
    ~MathInline();
    std::string* get_expr();
    void* visit(ast_visitor *v);
};
 
class Link: public Word {
    std::string *link, *text;
public:
    Link(std::string *l, std::string *t);
    ~Link();
    std::string* get_link();
    std::string* get_text();
    void* visit(ast_visitor *v);
};
 
class Format: public Word {};
 
class Text: public Format {
    std::string t;
public:
    Text(std::string tt);
    std::string* get_text();
    void* visit(ast_visitor *v);
};
 
class Format_Bold: public Format {
    Format *f;
public:
    Format_Bold(Format* ff);
    ~Format_Bold();
    Format* get_f();
    void* visit(ast_visitor *v);
};
 
class Format_Italic: public Format {
    Format *f;
public:
    Format_Italic(Format* ff);
    ~Format_Italic();
    Format* get_f();
    void* visit(ast_visitor *v);
};
 
class Format_Verbatim: public Format {
    Format *f;
public:
    Format_Verbatim(Format* ff);
    ~Format_Verbatim();
    Format* get_f();
    void* visit(ast_visitor *v);
};
class Line: public ast_node {};
 
class Heading: public Line {
    int level;
    std::vector<Word*> words;
public:
    Heading(int l, std::vector<Word*> w);
    ~Heading();
    int get_level();
    std::vector<Word*>* get_words();
    void* visit(ast_visitor *v);
};
 
class List: public Line {
    int level, number;
    std::vector<Word*> words;
public:
    List(int l, int n, std::vector<Word*> w);
    ~List();
    int get_level();
    int get_number();
    std::vector<Word*>* get_words();
    void* visit(ast_visitor *v);
};
 
class MathDisp: public Line {
    std::string *expr;
public:
    MathDisp(std::string *e);
    ~MathDisp();
    std::string* get_expr();
    void* visit(ast_visitor *v);
};
 
class Line_Word: public Line {
    std::vector<Word*> words;
public:
    ~Line_Word();
    int add_word(Word *w);
    std::vector<Word*>* get_words();
    void* visit(ast_visitor *v);
};
 
class Block: public ast_node {};
 
class Block_Table: public Block {
    std::vector<std::vector<Line_Word*>> table;
public:
    ~Block_Table();
    std::vector<std::vector<Line_Word*>> get_table();
    int add_row(std::vector<Line_Word*> row);
    void* visit(ast_visitor *v);
};
 
class Block_Code: public Block {
    std::string *c;
    std::string *lang;
public:
    Block_Code(std::string *l);
    ~Block_Code();
    int add_line(std::string *add);
    std::string* get_lang();
    std::string* get_code();
    void* visit(ast_visitor *v);
};
 
class Block_Line: public Block {
    std::vector<Line*> lines;
public:
    ~Block_Line();
    std::vector<Line*>* get_lines();
    int add_line(Line* l);
    void* visit(ast_visitor *v);
};
 
class Document: public ast_node {
    std::string *title, *author, *date;
    std::vector<Block*> blocks;
public:
    Document(std::string *t, std::string *a, std::string *d);
    ~Document();
    std::string* get_title();
    std::string* get_author();
    std::string* get_date();
    std::vector<Block*>* get_blocks();
    int add_block(Block *b);
    void* visit(ast_visitor *v);
};
 
class ast_visitor {
public:
    virtual void* visit_Document(Document *d)=0;
    virtual void* visit_Block_Table(Block_Table *bt)=0;
    virtual void* visit_Block_Code(Block_Code *bc)=0;
    virtual void* visit_Block_Line(Block_Line *bl)=0;
    virtual void* visit_Heading(Heading *h)=0;
    virtual void* visit_List(List *l)=0;
    virtual void* visit_MathDisp(MathDisp *md)=0;
    virtual void* visit_Line_Word(Line_Word *lw)=0;
    virtual void* visit_Link(Link *l)=0;
    virtual void* visit_MathInline(MathInline *mi)=0;
    virtual void* visit_Format_Bold(Format_Bold *fb)=0;
    virtual void* visit_Format_Italic(Format_Italic *fi)=0;
    virtual void* visit_Format_Verbatim(Format_Verbatim *fv)=0;
    virtual void* visit_Text(Text *t)=0;
};
#endif