-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathAstBuilderInt.h
87 lines (62 loc) · 2.02 KB
/
AstBuilderInt.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
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
/*
* AstBuilderInt.h
*
* Created on: Sep 13, 2020
* Author: ballance
*/
#pragma once
#include <memory>
#include <istream>
#include "pssp/IMarkerListener.h"
#include "PSSParserBaseVisitor.h"
#include "BaseErrorListener.h"
#include "pssp/ast/IExprId.h"
#include "pssp/ast/IFactory.h"
#include "pssp/ast/IGlobalScope.h"
#include "pssp/ast/IScope.h"
using namespace antlr4;
using namespace antlrcpp;
namespace pssp {
class AstBuilderInt :
public PSSParserBaseVisitor,
public BaseErrorListener {
public:
AstBuilderInt(
ast::IFactory *factory,
IMarkerListener *marker_l);
virtual ~AstBuilderInt();
void build(
ast::IGlobalScope *global,
std::istream *in);
virtual antlrcpp::Any visitPackage_declaration(PSSParser::Package_declarationContext *ctx) override;
virtual antlrcpp::Any visitImport_stmt(PSSParser::Import_stmtContext *ctx) override;
// virtual antlrcpp::Any visitAction_declaration(PSSParser::Action_declarationContext *ctx) override;
virtual void syntaxError(
Recognizer *recognizer,
Token * offendingSymbol,
size_t line,
size_t charPositionInLine,
const std::string &msg,
std::exception_ptr e) override;
private:
void addChild(ast::IScopeChild *c);
void addChild(ast::INamedScopeChild *c);
void addChild(ast::INamedScope *c);
void addDocstring(ast::IScopeChild *c, Token *t);
std::string processDocStringMultiLineComment(
const std::vector<Token *> &mlc_tokens,
const std::vector<Token *> &ws_tokens);
std::string processDocStringSingleLineComment(
const std::vector<Token *> &slc_tokens,
const std::vector<Token *> &ws_tokens);
ast::IScope *scope() const { return m_scopes.back(); }
void push_scope(ast::IScope *s) { m_scopes.push_back(s); }
void pop_scope() { m_scopes.pop_back(); }
ast::IExprId *mkId(PSSParser::IdentifierContext *ctx);
private:
IMarkerListener *m_marker_l;
ast::IFactory *m_factory;
std::vector<ast::IScope *> m_scopes;
std::unique_ptr<CommonTokenStream> m_tokens;
};
}