diff --git a/include/behaviortree_cpp/scripting/operators.hpp b/include/behaviortree_cpp/scripting/operators.hpp index 176fa2df0..14cf04f43 100644 --- a/include/behaviortree_cpp/scripting/operators.hpp +++ b/include/behaviortree_cpp/scripting/operators.hpp @@ -150,6 +150,7 @@ struct ExprBinaryArithmetic : ExprBase minus, times, div, + concat, bit_and, bit_or, @@ -171,6 +172,8 @@ struct ExprBinaryArithmetic : ExprBase return "*"; case div: return "/"; + case concat: + return ".."; case bit_and: return "&"; case bit_or: @@ -276,6 +279,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"); @@ -722,6 +731,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 { @@ -785,7 +804,7 @@ struct Expression : lexy::expression_production dsl::op(LEXY_LIT("||")) / dsl::op(LEXY_LIT("&&")); - using operand = comparison; + using operand = dsl::groups; }; // x ? y : z