Skip to content

Commit 7fcf4ba

Browse files
authored
Correctly recover from syntax errors at the first token of a line (#1549)
1 parent f048cbb commit 7fcf4ba

File tree

5 files changed

+16
-11
lines changed

5 files changed

+16
-11
lines changed

src/asm/parser.y

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,14 @@ asm_file: lines;
404404
lines:
405405
%empty
406406
| lines diff_mark line
407+
// Continue parsing the next line on a syntax error
408+
| error {
409+
lexer_SetMode(LEXER_NORMAL);
410+
lexer_ToggleStringExpansion(true);
411+
} endofline {
412+
fstk_StopRept();
413+
yyerrok;
414+
}
407415
;
408416

409417
diff_mark:
@@ -425,14 +433,6 @@ diff_mark:
425433
line:
426434
plain_directive endofline
427435
| line_directive // Directives that manage newlines themselves
428-
// Continue parsing the next line on a syntax error
429-
| error {
430-
lexer_SetMode(LEXER_NORMAL);
431-
lexer_ToggleStringExpansion(true);
432-
} endofline {
433-
fstk_StopRept();
434-
yyerrok;
435-
}
436436
;
437437

438438
endofline: NEWLINE | EOB;

test/asm/macro-syntax.err

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,6 @@ error: macro-syntax.asm(8):
66
'\1' cannot be used outside of a macro
77
error: macro-syntax.asm(9):
88
syntax error, unexpected ENDM
9-
error: Assembly aborted (4 errors)!
9+
error: macro-syntax.asm(11):
10+
"old" is not a macro
11+
error: Assembly aborted (5 errors)!

test/asm/skip-expansions.asm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,4 @@ ENDM
2828
mac2 elif, 6 * 7 ; this prints "it's $2A" because it skips the `\1` line and takes the `else`
2929
mac2 elif, 6 * 9
3030
mac2 elif
31-
mac2
31+
mac2 ; this prints "args:" *and* "forty-two!" since it doesn't create an `elif`

test/asm/skip-expansions.err

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,6 @@ error: skip-expansions.asm(31) -> skip-expansions.asm::mac2(21):
22
Macro argument '\1' not defined
33
error: skip-expansions.asm(31) -> skip-expansions.asm::mac2(21):
44
syntax error, unexpected (
5-
error: Assembly aborted (2 errors)!
5+
error: skip-expansions.asm(31) -> skip-expansions.asm::mac2(21):
6+
Macro argument '\2' not defined
7+
error: Assembly aborted (3 errors)!

test/asm/skip-expansions.out

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ it's $2A
66
it's $36
77
args: elif
88
args:
9+
forty-two!

0 commit comments

Comments
 (0)