Switched order in token::kind::id of function and operator behavior (#155)

* switched order in token::kind::id of function and operator behavior

* add tests

Co-authored-by: pantor <lars.berscheid@online.de>
This commit is contained in:
DeiRex75
2020-08-02 19:01:38 +02:00
committed by GitHub
parent 02394683b1
commit 44c473538b
3 changed files with 13 additions and 10 deletions

View File

@@ -139,14 +139,14 @@ class Parser {
add_json_literal(tmpl.content.c_str());
}
// Operator
} else if (tok.text == "and" || tok.text == "or" || tok.text == "in" || tok.text == "not") {
goto parse_operator;
// Functions
} else if (peek_tok.kind == Token::Kind::LeftParen) {
operator_stack.emplace(std::make_shared<FunctionNode>(static_cast<std::string>(tok.text), tok.text.data() - tmpl.content.c_str()));
function_stack.emplace(operator_stack.top().get(), current_paren_level);
// Operator
} else if (tok.text == "and" || tok.text == "or" || tok.text == "in" || tok.text == "not") {
goto parse_operator;
function_stack.emplace(operator_stack.top().get(), current_paren_level);
// Variables
} else {

View File

@@ -2835,14 +2835,14 @@ class Parser {
add_json_literal(tmpl.content.c_str());
}
// Operator
} else if (tok.text == "and" || tok.text == "or" || tok.text == "in" || tok.text == "not") {
goto parse_operator;
// Functions
} else if (peek_tok.kind == Token::Kind::LeftParen) {
operator_stack.emplace(std::make_shared<FunctionNode>(static_cast<std::string>(tok.text), tok.text.data() - tmpl.content.c_str()));
function_stack.emplace(operator_stack.top().get(), current_paren_level);
// Operator
} else if (tok.text == "and" || tok.text == "or" || tok.text == "in" || tok.text == "not") {
goto parse_operator;
function_stack.emplace(operator_stack.top().get(), current_paren_level);
// Variables
} else {

View File

@@ -268,4 +268,7 @@ TEST_CASE("combinations") {
CHECK(env.render("{{ last(list_of_objects).d * 2}}", data) == "10");
CHECK(env.render("{{ last(range(5)) * 2 }}", data) == "8");
CHECK(env.render("{{ last(range(5 * 2)) }}", data) == "9");
CHECK(env.render("{{ not true }}", data) == "false");
CHECK(env.render("{{ not (true) }}", data) == "false");
CHECK(env.render("{{ true or (true or true) }}", data) == "true");
}