mirror of
https://github.com/gbdev/rgbds.git
synced 2025-11-20 18:22:07 +00:00
@@ -366,6 +366,12 @@ static void initState(struct LexerState *state)
|
|||||||
state->expansionOfs = 0;
|
state->expansionOfs = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void nextLine(void)
|
||||||
|
{
|
||||||
|
lexerState->lineNo++;
|
||||||
|
lexerState->colNo = 1;
|
||||||
|
}
|
||||||
|
|
||||||
struct LexerState *lexer_OpenFile(char const *path)
|
struct LexerState *lexer_OpenFile(char const *path)
|
||||||
{
|
{
|
||||||
dbgPrint("Opening file \"%s\"\n", path);
|
dbgPrint("Opening file \"%s\"\n", path);
|
||||||
@@ -900,11 +906,12 @@ nextExpansion:
|
|||||||
/* Now, `distance` is how many bytes to move forward **in the file** */
|
/* Now, `distance` is how many bytes to move forward **in the file** */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
lexerState->colNo += distance;
|
||||||
|
|
||||||
if (lexerState->isMmapped) {
|
if (lexerState->isMmapped) {
|
||||||
lexerState->offset += distance;
|
lexerState->offset += distance;
|
||||||
} else {
|
} else {
|
||||||
lexerState->index += distance;
|
lexerState->index += distance;
|
||||||
lexerState->colNo += distance;
|
|
||||||
/* Wrap around if necessary */
|
/* Wrap around if necessary */
|
||||||
if (lexerState->index >= LEXER_BUF_SIZE)
|
if (lexerState->index >= LEXER_BUF_SIZE)
|
||||||
lexerState->index %= LEXER_BUF_SIZE;
|
lexerState->index %= LEXER_BUF_SIZE;
|
||||||
@@ -1030,11 +1037,12 @@ static void readLineContinuation(void)
|
|||||||
shiftChars(1);
|
shiftChars(1);
|
||||||
} else if (c == '\r' || c == '\n') {
|
} else if (c == '\r' || c == '\n') {
|
||||||
shiftChars(1);
|
shiftChars(1);
|
||||||
|
/* Handle CRLF before nextLine() since shiftChars updates colNo */
|
||||||
if (c == '\r' && peek(0) == '\n')
|
if (c == '\r' && peek(0) == '\n')
|
||||||
shiftChars(1);
|
shiftChars(1);
|
||||||
if (!lexerState->expansions
|
if (!lexerState->expansions
|
||||||
|| lexerState->expansions->distance)
|
|| lexerState->expansions->distance)
|
||||||
lexerState->lineNo++;
|
nextLine();
|
||||||
return;
|
return;
|
||||||
} else if (c == ';') {
|
} else if (c == ';') {
|
||||||
discardComment();
|
discardComment();
|
||||||
@@ -2007,12 +2015,13 @@ static int skipIfBlock(bool toEndc)
|
|||||||
atLineStart = true;
|
atLineStart = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (c == '\r' || c == '\n')
|
if (c == '\r' || c == '\n') {
|
||||||
/* Do this both on line continuations and plain EOLs */
|
/* Handle CRLF before nextLine() since shiftChars updates colNo */
|
||||||
lexerState->lineNo++;
|
|
||||||
/* Handle CRLF */
|
|
||||||
if (c == '\r' && peek(0) == '\n')
|
if (c == '\r' && peek(0) == '\n')
|
||||||
shiftChars(1);
|
shiftChars(1);
|
||||||
|
/* Do this both on line continuations and plain EOLs */
|
||||||
|
nextLine();
|
||||||
|
}
|
||||||
} while (!atLineStart);
|
} while (!atLineStart);
|
||||||
}
|
}
|
||||||
finish:
|
finish:
|
||||||
@@ -2043,10 +2052,8 @@ restart:
|
|||||||
}
|
}
|
||||||
if (lexerState->atLineStart) {
|
if (lexerState->atLineStart) {
|
||||||
/* Newlines read within an expansion should not increase the line count */
|
/* Newlines read within an expansion should not increase the line count */
|
||||||
if (!lexerState->expansions || lexerState->expansions->distance) {
|
if (!lexerState->expansions || lexerState->expansions->distance)
|
||||||
lexerState->lineNo++;
|
nextLine();
|
||||||
lexerState->colNo = 0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int (* const lexerModeFuncs[])(void) = {
|
static int (* const lexerModeFuncs[])(void) = {
|
||||||
@@ -2111,7 +2118,7 @@ void lexer_CaptureRept(char **capture, size_t *size)
|
|||||||
*/
|
*/
|
||||||
assert(lexerState->atLineStart);
|
assert(lexerState->atLineStart);
|
||||||
for (;;) {
|
for (;;) {
|
||||||
lexerState->lineNo++;
|
nextLine();
|
||||||
/* We're at line start, so attempt to match a `REPT` or `ENDR` token */
|
/* We're at line start, so attempt to match a `REPT` or `ENDR` token */
|
||||||
do { /* Discard initial whitespace */
|
do { /* Discard initial whitespace */
|
||||||
c = nextChar();
|
c = nextChar();
|
||||||
@@ -2224,7 +2231,7 @@ void lexer_CaptureMacroBody(char **capture, size_t *size)
|
|||||||
goto finish;
|
goto finish;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
lexerState->lineNo++;
|
nextLine();
|
||||||
}
|
}
|
||||||
|
|
||||||
finish:
|
finish:
|
||||||
|
|||||||
Reference in New Issue
Block a user