mirror of
https://github.com/gbdev/rgbds.git
synced 2025-11-20 18:22:07 +00:00
Syntax errors resets the lexer right away
`DEF`, `REDEF`, etc disable EQUS expansion, and reading macro or OPT arguments sets the lexer to raw mode. Syntax errors resume normal parsing at the line's end, but should resume normal tokenization even before that.
This commit is contained in:
@@ -684,11 +684,19 @@ plain_directive : label
|
|||||||
|
|
||||||
line : plain_directive endofline
|
line : plain_directive endofline
|
||||||
| line_directive /* Directives that manage newlines themselves */
|
| line_directive /* Directives that manage newlines themselves */
|
||||||
| error endofline { /* Continue parsing the next line on a syntax error */
|
/* Continue parsing the next line on a syntax error */
|
||||||
|
| error {
|
||||||
|
lexer_SetMode(LEXER_NORMAL);
|
||||||
|
lexer_ToggleStringExpansion(true);
|
||||||
|
} endofline {
|
||||||
fstk_StopRept();
|
fstk_StopRept();
|
||||||
yyerrok;
|
yyerrok;
|
||||||
}
|
}
|
||||||
| T_LABEL error endofline { /* Hint about unindented macros parsed as labels */
|
/* Hint about unindented macros parsed as labels */
|
||||||
|
| T_LABEL error {
|
||||||
|
lexer_SetMode(LEXER_NORMAL);
|
||||||
|
lexer_ToggleStringExpansion(true);
|
||||||
|
} endofline {
|
||||||
struct Symbol *macro = sym_FindExactSymbol($1);
|
struct Symbol *macro = sym_FindExactSymbol($1);
|
||||||
|
|
||||||
if (macro && macro->type == SYM_MACRO)
|
if (macro && macro->type == SYM_MACRO)
|
||||||
|
|||||||
12
test/asm/syntax-error-lexer-mode.asm
Normal file
12
test/asm/syntax-error-lexer-mode.asm
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
newline equs "\n"
|
||||||
|
|
||||||
|
def x = 1 newline def y = 2
|
||||||
|
println "x={d:x}, y={d:y}"
|
||||||
|
|
||||||
|
; the lexer is already in normal mode at the `AF`, so `newline` gets expanded
|
||||||
|
def m = AF newline def n = 2
|
||||||
|
println "n={d:n}"
|
||||||
|
|
||||||
|
; the lexer is in raw mode at the `AF`, but the parser resets it to normal
|
||||||
|
def AF = 1 newline def q = 2
|
||||||
|
println "q={d:q}"
|
||||||
5
test/asm/syntax-error-lexer-mode.err
Normal file
5
test/asm/syntax-error-lexer-mode.err
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
ERROR: syntax-error-lexer-mode.asm(7):
|
||||||
|
syntax error, unexpected af
|
||||||
|
ERROR: syntax-error-lexer-mode.asm(11):
|
||||||
|
syntax error, unexpected af, expecting identifier
|
||||||
|
error: Assembly aborted (2 errors)!
|
||||||
3
test/asm/syntax-error-lexer-mode.out
Normal file
3
test/asm/syntax-error-lexer-mode.out
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
x=1, y=2
|
||||||
|
n=2
|
||||||
|
q=2
|
||||||
Reference in New Issue
Block a user