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:
Rangi
2021-05-22 16:08:55 -04:00
parent 0068c1375c
commit 80a376f045
4 changed files with 30 additions and 2 deletions

View File

@@ -684,11 +684,19 @@ plain_directive : label
line : plain_directive endofline
| 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();
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);
if (macro && macro->type == SYM_MACRO)

View 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}"

View 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)!

View File

@@ -0,0 +1,3 @@
x=1, y=2
n=2
q=2