Implement ++ operator for string concatenation (#1698)

This commit is contained in:
Rangi
2025-06-12 16:52:00 -04:00
committed by GitHub
parent fa3d83a3d1
commit fa9e29e4ce
7 changed files with 58 additions and 17 deletions

View File

@@ -125,6 +125,9 @@
%token OP_MUL "*" OP_DIV "/" OP_MOD "%"
%token OP_EXP "**"
// String operators
%token OP_CAT "++"
// Comparison operators
%token OP_LOGICEQU "==" OP_LOGICNE "!="
%token OP_LOGICLT "<" OP_LOGICGT ">"
@@ -147,6 +150,7 @@
%left OP_AND OP_OR OP_XOR
%left OP_SHL OP_SHR OP_USHR
%left OP_MUL OP_DIV OP_MOD
%left OP_CAT
%precedence NEG // applies to unary OP_LOGICNOT, OP_ADD, OP_SUB, OP_NOT
%right OP_EXP
@@ -1613,6 +1617,10 @@ string_literal:
STRING {
$$ = std::move($1);
}
| string OP_CAT string {
$$ = std::move($1);
$$.append($3);
}
| OP_STRSLICE LPAREN string COMMA iconst COMMA iconst RPAREN {
size_t len = strlenUTF8($3, false);
uint32_t start = adjustNegativeIndex($5, len, "STRSLICE");