forked from cel-expr/cel-cpp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvisitor.h
More file actions
117 lines (105 loc) · 4.9 KB
/
Copy pathvisitor.h
File metadata and controls
117 lines (105 loc) · 4.9 KB
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
#ifndef THIRD_PARTY_CEL_CPP_PARSER_VISITOR_H_
#define THIRD_PARTY_CEL_CPP_PARSER_VISITOR_H_
#include "google/api/expr/v1alpha1/syntax.pb.h"
#include "absl/types/optional.h"
#include "parser/cel_grammar.inc/cel_grammar/CelBaseVisitor.h"
#include "parser/macro.h"
#include "parser/source_factory.h"
namespace google {
namespace api {
namespace expr {
namespace parser {
class SourceFactory;
class ParserVisitor : public ::cel_grammar::CelBaseVisitor,
public antlr4::BaseErrorListener {
public:
ParserVisitor(const std::string& description, const std::string& expression,
const int max_recursion_depth,
const std::vector<Macro>& macros = {});
virtual ~ParserVisitor();
antlrcpp::Any visit(antlr4::tree::ParseTree* tree) override;
antlrcpp::Any visitStart(
::cel_grammar::CelParser::StartContext* ctx) override;
antlrcpp::Any visitExpr(::cel_grammar::CelParser::ExprContext* ctx) override;
antlrcpp::Any visitConditionalOr(
::cel_grammar::CelParser::ConditionalOrContext* ctx) override;
antlrcpp::Any visitConditionalAnd(
::cel_grammar::CelParser::ConditionalAndContext* ctx) override;
antlrcpp::Any visitRelation(
::cel_grammar::CelParser::RelationContext* ctx) override;
antlrcpp::Any visitCalc(::cel_grammar::CelParser::CalcContext* ctx) override;
antlrcpp::Any visitUnary(::cel_grammar::CelParser::UnaryContext* ctx);
antlrcpp::Any visitLogicalNot(
::cel_grammar::CelParser::LogicalNotContext* ctx) override;
antlrcpp::Any visitNegate(
::cel_grammar::CelParser::NegateContext* ctx) override;
antlrcpp::Any visitSelectOrCall(
::cel_grammar::CelParser::SelectOrCallContext* ctx) override;
antlrcpp::Any visitIndex(
::cel_grammar::CelParser::IndexContext* ctx) override;
antlrcpp::Any visitCreateMessage(
::cel_grammar::CelParser::CreateMessageContext* ctx) override;
antlrcpp::Any visitFieldInitializerList(
::cel_grammar::CelParser::FieldInitializerListContext* ctx) override;
antlrcpp::Any visitIdentOrGlobalCall(
::cel_grammar::CelParser::IdentOrGlobalCallContext* ctx) override;
antlrcpp::Any visitNested(
::cel_grammar::CelParser::NestedContext* ctx) override;
antlrcpp::Any visitCreateList(
::cel_grammar::CelParser::CreateListContext* ctx) override;
std::vector<google::api::expr::v1alpha1::Expr> visitList(
::cel_grammar::CelParser::ExprListContext* ctx);
antlrcpp::Any visitCreateStruct(
::cel_grammar::CelParser::CreateStructContext* ctx) override;
antlrcpp::Any visitConstantLiteral(
::cel_grammar::CelParser::ConstantLiteralContext* ctx) override;
antlrcpp::Any visitPrimaryExpr(
::cel_grammar::CelParser::PrimaryExprContext* ctx) override;
antlrcpp::Any visitMemberExpr(
::cel_grammar::CelParser::MemberExprContext* ctx) override;
antlrcpp::Any visitMapInitializerList(
::cel_grammar::CelParser::MapInitializerListContext* ctx) override;
antlrcpp::Any visitInt(::cel_grammar::CelParser::IntContext* ctx) override;
antlrcpp::Any visitUint(::cel_grammar::CelParser::UintContext* ctx) override;
antlrcpp::Any visitDouble(
::cel_grammar::CelParser::DoubleContext* ctx) override;
antlrcpp::Any visitString(
::cel_grammar::CelParser::StringContext* ctx) override;
antlrcpp::Any visitBytes(
::cel_grammar::CelParser::BytesContext* ctx) override;
antlrcpp::Any visitBoolTrue(
::cel_grammar::CelParser::BoolTrueContext* ctx) override;
antlrcpp::Any visitBoolFalse(
::cel_grammar::CelParser::BoolFalseContext* ctx) override;
antlrcpp::Any visitNull(::cel_grammar::CelParser::NullContext* ctx) override;
google::api::expr::v1alpha1::SourceInfo sourceInfo() const;
EnrichedSourceInfo enrichedSourceInfo() const;
void syntaxError(antlr4::Recognizer* recognizer,
antlr4::Token* offending_symbol, size_t line, size_t col,
const std::string& msg, std::exception_ptr e) override;
bool hasErrored() const;
std::string errorMessage() const;
private:
Expr globalCallOrMacro(int64_t expr_id, std::string function,
std::vector<Expr> args);
Expr receiverCallOrMacro(int64_t expr_id, std::string function, Expr target,
std::vector<Expr> args);
bool expandMacro(int64_t expr_id, std::string function, Expr* target,
std::vector<Expr> args, Expr* macro_expr);
std::string unquote(antlr4::ParserRuleContext* ctx, const std::string& s,
bool is_bytes);
std::string extractQualifiedName(antlr4::ParserRuleContext* ctx,
const Expr* e);
private:
std::string description_;
std::string expression_;
std::shared_ptr<SourceFactory> sf_;
std::map<std::string, Macro> macros_;
int recursion_depth_;
const int max_recursion_depth_;
};
} // namespace parser
} // namespace expr
} // namespace api
} // namespace google
#endif // THIRD_PARTY_CEL_CPP_PARSER_VISITOR_H_