From 5c3ba79c6f9ded60930670d2b03d42d3840c731e Mon Sep 17 00:00:00 2001 From: bubnikv Date: Sun, 26 Nov 2017 11:16:28 +0100 Subject: [PATCH] PlaceholderParser - added an unary not operator. --- xs/src/libslic3r/PlaceholderParser.cpp | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/xs/src/libslic3r/PlaceholderParser.cpp b/xs/src/libslic3r/PlaceholderParser.cpp index 7b5469dc3..39d775e89 100644 --- a/xs/src/libslic3r/PlaceholderParser.cpp +++ b/xs/src/libslic3r/PlaceholderParser.cpp @@ -250,6 +250,19 @@ namespace client return expr(); } + expr unary_not(const Iterator start_pos) const + { + switch (this->type) { + case TYPE_BOOL : + return expr(! this->b(), start_pos, this->it_range.end()); + default: + this->throw_exception("Cannot apply a not operator."); + } + assert(false); + // Suppress compiler warnings. + return expr(); + } + expr &operator+=(const expr &rhs) { const char *err_msg = "Cannot multiply with non-numeric type."; @@ -715,12 +728,15 @@ namespace client { out = expr(std::move(value), out.it_range.begin(), end_pos); } static void minus_(expr &value, expr &out) { out = value.unary_minus(out.it_range.begin()); } + static void not_(expr &value, expr &out) + { out = value.unary_not(out.it_range.begin()); } }; factor = iter_pos[px::bind(&FactorActions::set_start_pos, _1, _val)] >> ( scalar_variable_reference(_r1) [ _val = _1 ] | (lit('(') > expression(_r1) > ')' > iter_pos) [ px::bind(&FactorActions::expr_, _1, _2, _val) ] | (lit('-') > factor(_r1) ) [ px::bind(&FactorActions::minus_, _1, _val) ] | (lit('+') > factor(_r1) > iter_pos) [ px::bind(&FactorActions::expr_, _1, _2, _val) ] + | ((kw["not"] | '!') > factor(_r1) > iter_pos) [ px::bind(&FactorActions::not_, _1, _val) ] | (strict_double > iter_pos) [ px::bind(&FactorActions::double_, _1, _2, _val) ] | (int_ > iter_pos) [ px::bind(&FactorActions::int_, _1, _2, _val) ] | (kw[bool_] > iter_pos) [ px::bind(&FactorActions::bool_, _1, _2, _val) ] @@ -753,12 +769,15 @@ namespace client */ keywords.add + ("and") ("if") //("inf") ("else") ("elsif") ("endif") ("false") + ("not") + ("or") ("true"); if (0) {