@@ -13,18 +13,18 @@ class Expression {
1313 public:
1414 const Value& eval () { return *callEval ().second ; }
1515 void assign (const Value& v) { (this ->*assign_)(v); }
16- Expression () {}
16+ Expression ();
1717 Expression (Value v);
1818 Expression (Variable* variable, std::vector<Expression> idx);
1919 Expression (const antlr4::Token* literal);
2020 Expression (const antlr4::Token* binop, Expression a, Expression b);
2121 Expression (const antlr4::Token* unop, Expression e);
22+ // UNIQUE, STRLEN, INARRAY functions
2223 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);
2828
2929 private:
3030 auto idx () {
@@ -36,15 +36,7 @@ class Expression {
3636 std::pair<bool , const Value*> constEval ();
3737 using EvalFn = decltype (&Expression::constEval);
3838 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 ();
4840 template <int op>
4941 std::pair<bool , const Value*> binopEval ();
5042 std::pair<bool , const Value*> unaryMinusEval ();
@@ -56,10 +48,8 @@ class Expression {
5648 std::pair<bool , const Value*> uniqueEval ();
5749 std::pair<bool , const Value*> inarrayEval ();
5850 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 ();
6353 template <size_t size>
6454 void variableArrayAssignment (const Value& value) {
6555 variable_->set <size>(idx (), value);
@@ -76,10 +66,10 @@ class Expression {
7666 AssignFn getVariableAssignment (size_t i);
7767
7868 Value value_;
79- Variable* variable_;
69+ Variable* variable_ = nullptr ;
8070 std::vector<const Variable*> variables_;
8171 EvalFn eval_ = &Expression::invalid;
8272 AssignFn assign_ = &Expression::invalidAssignment;
8373 std::vector<Expression> children_;
84- std::any context_ ;
74+ std::string_view** input_ = nullptr ;
8575};
0 commit comments