shithub: rgbds

Download patch

ref: 80a376f045aaf06d705221886b30251137312c71
parent: 0068c1375ca08a633c61c5c70201331a4fe15540
author: Rangi <[email protected]>
date: Sat May 22 12:08:55 EDT 2021

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.

--- a/src/asm/parser.y
+++ b/src/asm/parser.y
@@ -684,11 +684,19 @@
 
 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)
--- /dev/null
+++ b/test/asm/syntax-error-lexer-mode.asm
@@ -1,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}"
--- /dev/null
+++ b/test/asm/syntax-error-lexer-mode.err
@@ -1,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)!
--- /dev/null
+++ b/test/asm/syntax-error-lexer-mode.out
@@ -1,0 +1,3 @@
+x=1, y=2
+n=2
+q=2