From 5ce4eb8cfc37fc64166570649ec6944778f944a9 Mon Sep 17 00:00:00 2001 From: Martin Michelsen Date: Fri, 31 May 2024 23:05:19 -0700 Subject: [PATCH] fix unary operator bind order in integral tree parser --- src/ChatCommands.cc | 6 ++++-- src/Client.cc | 2 +- src/IntegralExpression.cc | 24 ++++++++++++------------ 3 files changed, 17 insertions(+), 15 deletions(-) diff --git a/src/ChatCommands.cc b/src/ChatCommands.cc index 166303cf..6729f751 100644 --- a/src/ChatCommands.cc +++ b/src/ChatCommands.cc @@ -482,8 +482,10 @@ static void server_command_qset_qclear(shared_ptr c, const std::string& } else { 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) { p->quest_flags.set(l->difficulty, flag_num); } else { diff --git a/src/Client.cc b/src/Client.cc index 0a755e1c..af53ec15 100644 --- a/src/Client.cc +++ b/src/Client.cc @@ -386,7 +386,7 @@ bool Client::evaluate_quest_availability_expression( int64_t ret = expr->evaluate(env); if (this->log.should_log(LogLevel::INFO)) { 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; } diff --git a/src/IntegralExpression.cc b/src/IntegralExpression.cc index bd12bc67..8f71cb46 100644 --- a/src/IntegralExpression.cc +++ b/src/IntegralExpression.cc @@ -337,18 +337,6 @@ unique_ptr IntegralExpression::parse_expr(string throw runtime_error("invalid expression"); } - // Check for unary operators - if (text[0] == '!') { - return make_unique(UnaryOperatorNode::Type::LOGICAL_NOT, - IntegralExpression::parse_expr(text.substr(1))); - } else if (text[0] == '~') { - return make_unique(UnaryOperatorNode::Type::BITWISE_NOT, - IntegralExpression::parse_expr(text.substr(1))); - } else if (text[0] == '-') { - return make_unique(UnaryOperatorNode::Type::NEGATIVE, - IntegralExpression::parse_expr(text.substr(1))); - } - // Check for binary operators at the root level using BinType = BinaryOperatorNode::Type; static const vector>> binary_operator_levels = { @@ -392,6 +380,18 @@ unique_ptr IntegralExpression::parse_expr(string } } + // Check for unary operators + if (text[0] == '!') { + return make_unique(UnaryOperatorNode::Type::LOGICAL_NOT, + IntegralExpression::parse_expr(text.substr(1))); + } else if (text[0] == '~') { + return make_unique(UnaryOperatorNode::Type::BITWISE_NOT, + IntegralExpression::parse_expr(text.substr(1))); + } else if (text[0] == '-') { + return make_unique(UnaryOperatorNode::Type::NEGATIVE, + IntegralExpression::parse_expr(text.substr(1))); + } + // Check for env lookups if (text.starts_with("F_")) { char* endptr = nullptr;