mirror of
https://github.com/pantor/inja.git
synced 2026-02-17 09:03:58 +00:00
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:
@@ -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 {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user