@@ -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" );
@@ -722,6 +731,16 @@ struct Expression : lexy::expression_production
722
731
using operand = math_product;
723
732
};
724
733
734
+ // x .. y
735
+ struct string_concat : dsl::infix_op_left
736
+ {
737
+ static constexpr auto op = [] {
738
+ return dsl::op<Ast::ExprBinaryArithmetic::concat>(LEXY_LIT (" .." ));
739
+ }();
740
+
741
+ using operand = math_sum;
742
+ };
743
+
725
744
// ~x
726
745
struct bit_prefix : dsl::prefix_op
727
746
{
@@ -785,7 +804,7 @@ struct Expression : lexy::expression_production
785
804
dsl::op<Ast::ExprBinaryArithmetic::logic_or>(LEXY_LIT(" ||" )) /
786
805
dsl::op<Ast::ExprBinaryArithmetic::logic_and>(LEXY_LIT(" &&" ));
787
806
788
- using operand = comparison;
807
+ using operand = dsl::groups<string_concat, comparison> ;
789
808
};
790
809
791
810
// x ? y : z
0 commit comments