mirror of
https://github.com/gbdev/rgbds.git
synced 2025-11-21 18:52:07 +00:00
Implement ++ operator for string concatenation (#1698)
This commit is contained in:
@@ -1774,12 +1774,17 @@ static Token yylex_NORMAL() {
|
||||
|
||||
// Handle ambiguous 1- or 2-char tokens
|
||||
|
||||
case '+': // Either += or ADD
|
||||
if (peek() == '=') {
|
||||
case '+': // Either +=, ADD, or CAT
|
||||
switch (peek()) {
|
||||
case '=':
|
||||
shiftChar();
|
||||
return Token(T_(POP_ADDEQ));
|
||||
case '+':
|
||||
shiftChar();
|
||||
return Token(T_(OP_CAT));
|
||||
default:
|
||||
return Token(T_(OP_ADD));
|
||||
}
|
||||
return Token(T_(OP_ADD));
|
||||
|
||||
case '-': // Either -= or SUB
|
||||
if (peek() == '=') {
|
||||
|
||||
@@ -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");
|
||||
|
||||
Reference in New Issue
Block a user