@@ -150,6 +150,7 @@ struct ExprBinaryArithmetic : ExprBase
150
150
minus,
151
151
times,
152
152
div,
153
+ concat,
153
154
154
155
bit_and,
155
156
bit_or,
@@ -171,6 +172,8 @@ struct ExprBinaryArithmetic : ExprBase
171
172
return " *" ;
172
173
case div:
173
174
return " /" ;
175
+ case concat:
176
+ return " .." ;
174
177
case bit_and:
175
178
return " &" ;
176
179
case bit_or:
@@ -276,6 +279,12 @@ struct ExprBinaryArithmetic : ExprBase
276
279
{
277
280
return Any (lhs_v.cast <std::string>() + rhs_v.cast <std::string>());
278
281
}
282
+ else if (op == concat && ((rhs_v.isString () && lhs_v.isString ()) ||
283
+ (rhs_v.isString () && lhs_v.isNumber ()) ||
284
+ (rhs_v.isNumber () && lhs_v.isString ())))
285
+ {
286
+ return Any (lhs_v.cast <std::string>() + rhs_v.cast <std::string>());
287
+ }
279
288
else
280
289
{
281
290
throw RuntimeError (" Operation not permitted" );
@@ -726,6 +735,16 @@ struct Expression : lexy::expression_production
726
735
using operand = math_product;
727
736
};
728
737
738
+ // x .. y
739
+ struct string_concat : dsl::infix_op_left
740
+ {
741
+ static constexpr auto op = [] {
742
+ return dsl::op<Ast::ExprBinaryArithmetic::concat>(LEXY_LIT (" .." ));
743
+ }();
744
+
745
+ using operand = math_sum;
746
+ };
747
+
729
748
// ~x
730
749
struct bit_prefix : dsl::prefix_op
731
750
{
@@ -789,7 +808,7 @@ struct Expression : lexy::expression_production
789
808
dsl::op<Ast::ExprBinaryArithmetic::logic_or>(LEXY_LIT(" ||" )) /
790
809
dsl::op<Ast::ExprBinaryArithmetic::logic_and>(LEXY_LIT(" &&" ));
791
810
792
- using operand = comparison;
811
+ using operand = dsl::groups<string_concat, comparison> ;
793
812
};
794
813
795
814
// x ? y : z
0 commit comments