fix unary operator bind order in integral tree parser

This commit is contained in:
Martin Michelsen
2024-05-31 23:05:19 -07:00
parent 64082fa872
commit 5ce4eb8cfc
3 changed files with 17 additions and 15 deletions
+4 -2
View File
@@ -482,8 +482,10 @@ static void server_command_qset_qclear(shared_ptr<Client> c, const std::string&
} else { } else {
l->quest_flag_values->clear(l->difficulty, flag_num); l->quest_flag_values->clear(l->difficulty, flag_num);
} }
} else if (c->version() == Version::BB_V4) { }
auto p = c->character();
auto p = c->character(false);
if (p) {
if (should_set) { if (should_set) {
p->quest_flags.set(l->difficulty, flag_num); p->quest_flags.set(l->difficulty, flag_num);
} else { } else {
+1 -1
View File
@@ -386,7 +386,7 @@ bool Client::evaluate_quest_availability_expression(
int64_t ret = expr->evaluate(env); int64_t ret = expr->evaluate(env);
if (this->log.should_log(LogLevel::INFO)) { if (this->log.should_log(LogLevel::INFO)) {
string expr_str = expr->str(); string expr_str = expr->str();
this->log.info("Evaluated quest availability expression %s => %s", expr_str.c_str(), ret ? "TRUE" : "FALSE"); this->log.info("Evaluated integral expression %s => %s", expr_str.c_str(), ret ? "TRUE" : "FALSE");
} }
return ret; return ret;
} }
+12 -12
View File
@@ -337,18 +337,6 @@ unique_ptr<const IntegralExpression::Node> IntegralExpression::parse_expr(string
throw runtime_error("invalid expression"); throw runtime_error("invalid expression");
} }
// Check for unary operators
if (text[0] == '!') {
return make_unique<UnaryOperatorNode>(UnaryOperatorNode::Type::LOGICAL_NOT,
IntegralExpression::parse_expr(text.substr(1)));
} else if (text[0] == '~') {
return make_unique<UnaryOperatorNode>(UnaryOperatorNode::Type::BITWISE_NOT,
IntegralExpression::parse_expr(text.substr(1)));
} else if (text[0] == '-') {
return make_unique<UnaryOperatorNode>(UnaryOperatorNode::Type::NEGATIVE,
IntegralExpression::parse_expr(text.substr(1)));
}
// Check for binary operators at the root level // Check for binary operators at the root level
using BinType = BinaryOperatorNode::Type; using BinType = BinaryOperatorNode::Type;
static const vector<vector<pair<std::string, BinaryOperatorNode::Type>>> binary_operator_levels = { static const vector<vector<pair<std::string, BinaryOperatorNode::Type>>> binary_operator_levels = {
@@ -392,6 +380,18 @@ unique_ptr<const IntegralExpression::Node> IntegralExpression::parse_expr(string
} }
} }
// Check for unary operators
if (text[0] == '!') {
return make_unique<UnaryOperatorNode>(UnaryOperatorNode::Type::LOGICAL_NOT,
IntegralExpression::parse_expr(text.substr(1)));
} else if (text[0] == '~') {
return make_unique<UnaryOperatorNode>(UnaryOperatorNode::Type::BITWISE_NOT,
IntegralExpression::parse_expr(text.substr(1)));
} else if (text[0] == '-') {
return make_unique<UnaryOperatorNode>(UnaryOperatorNode::Type::NEGATIVE,
IntegralExpression::parse_expr(text.substr(1)));
}
// Check for env lookups // Check for env lookups
if (text.starts_with("F_")) { if (text.starts_with("F_")) {
char* endptr = nullptr; char* endptr = nullptr;