mirror of
https://github.com/gbdev/rgbds.git
synced 2025-11-20 10:12:06 +00:00
Implement === and !== string comparison operators (#1832)
This commit is contained in:
@@ -1750,14 +1750,22 @@ static Token yylex_NORMAL() {
|
||||
case '^': // Either ^= or XOR
|
||||
return oneOrTwo('=', T_(POP_XOREQ), T_(OP_XOR));
|
||||
|
||||
case '=': // Either assignment or EQ
|
||||
return oneOrTwo('=', T_(OP_LOGICEQU), T_(POP_EQUAL));
|
||||
|
||||
case '!': // Either a NEQ or negation
|
||||
return oneOrTwo('=', T_(OP_LOGICNE), T_(OP_LOGICNOT));
|
||||
|
||||
// Handle ambiguous 1-, 2-, or 3-char tokens
|
||||
|
||||
case '=': // Either assignment, EQ or string EQ
|
||||
if (peek() == '=') {
|
||||
shiftChar();
|
||||
return oneOrTwo('=', T_(OP_STREQU), T_(OP_LOGICEQU));
|
||||
}
|
||||
return Token(T_(POP_EQUAL));
|
||||
|
||||
case '!': // Either negation, NEQ, or string NEQ
|
||||
if (peek() == '=') {
|
||||
shiftChar();
|
||||
return oneOrTwo('=', T_(OP_STRNE), T_(OP_LOGICNE));
|
||||
}
|
||||
return Token(T_(OP_LOGICNOT));
|
||||
|
||||
case '<': // Either <<=, LT, LTE, or left shift
|
||||
if (peek() == '<') {
|
||||
shiftChar();
|
||||
|
||||
@@ -107,6 +107,7 @@
|
||||
|
||||
// String operators
|
||||
%token OP_CAT "++"
|
||||
%token OP_STREQU "===" OP_STRNE "!=="
|
||||
|
||||
// Comparison operators
|
||||
%token OP_LOGICEQU "==" OP_LOGICNE "!="
|
||||
@@ -1287,6 +1288,12 @@ relocexpr_no_str:
|
||||
| CHARACTER {
|
||||
$$.makeNumber(act_CharToNum($1));
|
||||
}
|
||||
| string OP_STREQU string {
|
||||
$$.makeNumber($1.compare($3) == 0);
|
||||
}
|
||||
| string OP_STRNE string {
|
||||
$$.makeNumber($1.compare($3) != 0);
|
||||
}
|
||||
| OP_LOGICNOT relocexpr %prec NEG {
|
||||
$$.makeUnaryOp(RPN_LOGNOT, std::move($2));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user