mirror of
https://github.com/gbdev/rgbds.git
synced 2025-11-20 10:12:06 +00:00
Fix interpolation after empty string literal
This commit is contained in:
@@ -1219,7 +1219,9 @@ static std::shared_ptr<std::string> readInterpolation(size_t depth) {
|
||||
// `lexerState->peekChar()` lets `readInterpolation()` handle its own nested expansions,
|
||||
// increasing `depth` each time.
|
||||
if (lexerState->peekChar() == '{') {
|
||||
++lexerState->expansionScanDistance; // Prevent `shiftChar()` from calling `peek()`
|
||||
// Increment `lexerState->expansionScanDistance` to prevent `shiftChar()` from calling
|
||||
// `peek()` and to balance its decrement.
|
||||
++lexerState->expansionScanDistance;
|
||||
shiftChar();
|
||||
if (std::shared_ptr<std::string> str = readInterpolation(depth + 1); str) {
|
||||
beginExpansion(str, *str);
|
||||
@@ -1425,12 +1427,19 @@ static void readString(std::string &str, bool rawString) {
|
||||
if (rawMode) {
|
||||
str += '"';
|
||||
}
|
||||
if (nextChar() != '"') {
|
||||
shiftChar();
|
||||
// `peek()` would mark the third character here as "painted blue" whether or not it is a
|
||||
// third quote, which would incorrectly prevent expansions right after an empty string "".
|
||||
// `lexerState->peekChar()` avoids this, and is okay since expansions are disabled here.
|
||||
if (lexerState->peekChar() != '"') {
|
||||
// "" is an empty string, skip the loop
|
||||
return;
|
||||
}
|
||||
// """ begins a multi-line string
|
||||
// Increment `lexerState->expansionScanDistance` to prevent `shiftChar()` from calling
|
||||
// `peek()` and to balance its decrement.
|
||||
++lexerState->expansionScanDistance;
|
||||
shiftChar();
|
||||
// """ begins a multi-line string
|
||||
if (rawMode) {
|
||||
str += '"';
|
||||
}
|
||||
|
||||
@@ -1,18 +1,8 @@
|
||||
error: interpolation-after-string.asm(2):
|
||||
Unknown character '{'
|
||||
error: interpolation-after-string.asm(2):
|
||||
Unknown character '}'
|
||||
error: interpolation-after-string.asm(5):
|
||||
Unknown character '{'
|
||||
error: interpolation-after-string.asm(5):
|
||||
syntax error, unexpected symbol
|
||||
while expanding symbol "greeting"
|
||||
error: interpolation-after-string.asm(5):
|
||||
Unknown character '}'
|
||||
while expanding symbol "hello"
|
||||
error: interpolation-after-string.asm(8):
|
||||
Unknown character '{'
|
||||
Interpolated symbol "goodbye" does not exist
|
||||
error: interpolation-after-string.asm(8):
|
||||
syntax error, unexpected symbol
|
||||
error: interpolation-after-string.asm(8):
|
||||
Unknown character '}'
|
||||
Assembly aborted with 8 errors!
|
||||
syntax error, unexpected string
|
||||
Assembly aborted with 3 errors!
|
||||
|
||||
Reference in New Issue
Block a user