diff --git a/include/behaviortree_cpp/scripting/operators.hpp b/include/behaviortree_cpp/scripting/operators.hpp index 3b1f323f7..46adfe23f 100644 --- a/include/behaviortree_cpp/scripting/operators.hpp +++ b/include/behaviortree_cpp/scripting/operators.hpp @@ -130,6 +130,7 @@ struct ExprBinaryArithmetic : ExprBase minus, times, div, + concat, bit_and, bit_or, @@ -151,6 +152,8 @@ struct ExprBinaryArithmetic : ExprBase return "*"; case div: return "/"; + case concat: + return ".."; case bit_and: return "&"; case bit_or: @@ -256,6 +259,12 @@ struct ExprBinaryArithmetic : ExprBase { return Any(lhs_v.cast() + rhs_v.cast()); } + else if (op == concat && ((rhs_v.isString() && lhs_v.isString()) || + (rhs_v.isString() && lhs_v.isNumber()) || + (rhs_v.isNumber() && lhs_v.isString()))) + { + return Any(lhs_v.cast() + rhs_v.cast()); + } else { throw RuntimeError("Operation not permitted"); @@ -694,6 +703,16 @@ struct Expression : lexy::expression_production using operand = math_product; }; + // x .. y + struct string_concat : dsl::infix_op_left + { + static constexpr auto op = [] { + return dsl::op(LEXY_LIT("..")); + }(); + + using operand = math_sum; + }; + // ~x struct bit_prefix : dsl::prefix_op { @@ -757,7 +776,7 @@ struct Expression : lexy::expression_production dsl::op(LEXY_LIT("||")) / dsl::op(LEXY_LIT("&&")); - using operand = comparison; + using operand = dsl::groups; }; // x ? y : z