@@ -13,18 +13,18 @@ class Expression {
13
13
public:
14
14
const Value& eval () { return *callEval ().second ; }
15
15
void assign (const Value& v) { (this ->*assign_)(v); }
16
- Expression () {}
16
+ Expression ();
17
17
Expression (Value v);
18
18
Expression (Variable* variable, std::vector<Expression> idx);
19
19
Expression (const antlr4::Token* literal);
20
20
Expression (const antlr4::Token* binop, Expression a, Expression b);
21
21
Expression (const antlr4::Token* unop, Expression e);
22
+ // UNIQUE, STRLEN, INARRAY functions
22
23
Expression (const antlr4::Token* function, std::vector<Expression> arguments);
23
- template <typename F,
24
- typename _ = std::enable_if_t <std::is_invocable_v<F>, void >>
25
- Expression (F f)
26
- : eval_(&Expression::foldConst<&Expression::backdoorEval<F>>),
27
- context_ (std::move(f)) {}
24
+ // ISEOF function
25
+ Expression (std::string_view** input);
26
+ // MATCH function
27
+ Expression (std::string_view** input, Expression match);
28
28
29
29
private:
30
30
auto idx () {
@@ -36,15 +36,7 @@ class Expression {
36
36
std::pair<bool , const Value*> constEval ();
37
37
using EvalFn = decltype (&Expression::constEval);
38
38
template <EvalFn inner>
39
- std::pair<bool , const Value*> foldConst () {
40
- auto result = (this ->*inner)();
41
- if (result.first ) {
42
- *this = Expression{std::move (*result.second )};
43
- } else {
44
- eval_ = inner;
45
- }
46
- return callEval ();
47
- }
39
+ std::pair<bool , const Value*> foldConst ();
48
40
template <int op>
49
41
std::pair<bool , const Value*> binopEval ();
50
42
std::pair<bool , const Value*> unaryMinusEval ();
@@ -56,10 +48,8 @@ class Expression {
56
48
std::pair<bool , const Value*> uniqueEval ();
57
49
std::pair<bool , const Value*> inarrayEval ();
58
50
std::pair<bool , const Value*> strlenEval ();
59
- template <typename F>
60
- std::pair<bool , const Value*> backdoorEval () {
61
- return (*std::any_cast<F>(&context_))();
62
- }
51
+ std::pair<bool , const Value*> iseofEval ();
52
+ std::pair<bool , const Value*> matchEval ();
63
53
template <size_t size>
64
54
void variableArrayAssignment (const Value& value) {
65
55
variable_->set <size>(idx (), value);
@@ -76,10 +66,10 @@ class Expression {
76
66
AssignFn getVariableAssignment (size_t i);
77
67
78
68
Value value_;
79
- Variable* variable_;
69
+ Variable* variable_ = nullptr ;
80
70
std::vector<const Variable*> variables_;
81
71
EvalFn eval_ = &Expression::invalid;
82
72
AssignFn assign_ = &Expression::invalidAssignment;
83
73
std::vector<Expression> children_;
84
- std::any context_ ;
74
+ std::string_view** input_ = nullptr ;
85
75
};
0 commit comments