Skip to content

Commit 558d3ca

Browse files
committed
Disallow labels before ENDC
1 parent df5162e commit 558d3ca

File tree

5 files changed

+24
-8
lines changed

5 files changed

+24
-8
lines changed

src/asm/parser.y

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -455,12 +455,13 @@ endofline: NEWLINE | EOB | EOL;
455455
// and to avoid causing some grammar conflicts (token reducing is finicky).
456456
// This is DEFINITELY one of the more FRAGILE parts of the codebase, handle with care.
457457
line_directive:
458-
def_macro
458+
macro_def
459459
| rept
460460
| for
461461
| break
462462
| include
463463
| if
464+
| endc
464465
// It's important that all of these require being at line start for `skipIfBlock`
465466
| elif
466467
| else
@@ -489,12 +490,12 @@ else:
489490
plain_directive:
490491
label
491492
| label data
492-
| label macro
493+
| label macro_invocation
493494
| label directive
494495
;
495496
496497
endc:
497-
POP_ENDC {
498+
POP_ENDC endofline {
498499
act_Endc();
499500
}
500501
;
@@ -545,7 +546,7 @@ label:
545546
}
546547
;
547548
548-
macro:
549+
macro_invocation:
549550
SYMBOL {
550551
// Parsing 'macro_args' will restore the lexer's normal mode
551552
lexer_SetMode(LEXER_RAW);
@@ -571,8 +572,7 @@ macro_args:
571572
;
572573

573574
directive:
574-
endc
575-
| print
575+
print
576576
| println
577577
| export
578578
| export_def
@@ -853,7 +853,7 @@ break:
853853
}
854854
;
855855

856-
def_macro:
856+
macro_def:
857857
POP_MACRO {
858858
lexer_ToggleStringExpansion(false);
859859
} maybe_quiet SYMBOL {

test/asm/code-after-endm-endr-endc.err

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,5 @@ error: syntax error, unexpected PRINTLN, expecting end of line
1212
at code-after-endm-endr-endc.asm(23)
1313
error: syntax error, unexpected PRINTLN, expecting end of line or end of buffer or end of fragment literal
1414
at code-after-endm-endr-endc.asm(25)
15-
Assembly aborted with 7 errors!
15+
FATAL: Ended block with 2 unterminated conditionals (`IF`/`ELIF`/`ELSE` blocks)
16+
at code-after-endm-endr-endc.asm(28)

test/asm/label-before-endc.asm

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
section "test", rom0
2+
if 1
3+
println "one"
4+
label0: endc
5+
if 2
6+
println "two"
7+
label1: endc

test/asm/label-before-endc.err

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
error: syntax error, unexpected ENDC
2+
at label-before-endc.asm(4)
3+
error: syntax error, unexpected ENDC
4+
at label-before-endc.asm(7)
5+
FATAL: Ended block with 2 unterminated conditionals (`IF`/`ELIF`/`ELSE` blocks)
6+
at label-before-endc.asm(8)

test/asm/label-before-endc.out

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
one
2+
two

0 commit comments

Comments
 (0)