diff --git a/parser/parser.cpp b/parser/parser.cpp index ab2b8726..3b504ee9 100644 --- a/parser/parser.cpp +++ b/parser/parser.cpp @@ -95,6 +95,7 @@ struct ParserState { std::vector predicate_stack; Predicate *current() { return predicate_stack.back(); } + bool negate_next; void addExpression(Expression exp) { @@ -106,6 +107,10 @@ struct ParserState Predicate p; p.type = Predicate::Type::Comparison; p.sub_expressions.emplace_back(std::move(exp)); + if (negate_next) { + p.negate = true; + negate_next = false; + } current()->sub_predicates.emplace_back(std::move(p)); predicate_stack.push_back(¤t()->sub_predicates.back()); } @@ -244,6 +249,11 @@ template<> struct action< one< '(' > > Predicate group; group.type = Predicate::Type::And; + if (state.negate_next) { + group.negate = true; + state.negate_next = false; + } + state.current()->sub_predicates.emplace_back(std::move(group)); state.predicate_stack.push_back(&state.current()->sub_predicates.back()); } @@ -264,6 +274,8 @@ template<> struct action< not_pre > static void apply( const input & in, ParserState & state ) { std::cout << "" << std::endl; + + state.negate_next = true; } }; diff --git a/parser/parser.hpp b/parser/parser.hpp index 416faa2e..149f12ff 100644 --- a/parser/parser.hpp +++ b/parser/parser.hpp @@ -69,6 +69,8 @@ namespace realm { // for compounds std::vector sub_predicates; + + bool negate; }; Predicate parse(const std::string &query);