Skip to content

Commit

Permalink
Syntax error message hints to indent macro invocations
Browse files Browse the repository at this point in the history
This message is only printed for identifiers parsed as
`T_LABEL` (since they're at the start of a line) but
already defined as macros. Otherwise it may not be
relevant, e.g. for `MyLabel;:` or `My Label::`.
  • Loading branch information
Rangi42 authored and ISSOtm committed May 22, 2021
1 parent 872af9c commit 0068c13
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/asm/parser.y
Original file line number Diff line number Diff line change
Expand Up @@ -688,6 +688,15 @@ line : plain_directive endofline
fstk_StopRept();
yyerrok;
}
| T_LABEL error endofline { /* Hint about unindented macros parsed as labels */
struct Symbol *macro = sym_FindExactSymbol($1);

if (macro && macro->type == SYM_MACRO)
fprintf(stderr,
" To invoke `%s` as a macro it must be indented\n", $1);
fstk_StopRept();
yyerrok;
}
;

/*
Expand Down
2 changes: 2 additions & 0 deletions test/asm/syntax-error-after-syntax-error.err
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ ERROR: syntax-error-after-syntax-error.asm(6):
syntax error, unexpected newline
ERROR: syntax-error-after-syntax-error.asm(7):
syntax error, unexpected newline
To invoke `mac` as a macro it must be indented
ERROR: syntax-error-after-syntax-error.asm(8):
syntax error, unexpected number
To invoke `mac` as a macro it must be indented
ERROR: syntax-error-after-syntax-error.asm(9):
'mac' already defined at syntax-error-after-syntax-error.asm(1)
ERROR: syntax-error-after-syntax-error.asm(10):
Expand Down
2 changes: 2 additions & 0 deletions test/asm/syntax-error-after-syntax-error.simple.err
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ ERROR: syntax-error-after-syntax-error.asm(6):
syntax error
ERROR: syntax-error-after-syntax-error.asm(7):
syntax error
To invoke `mac` as a macro it must be indented
ERROR: syntax-error-after-syntax-error.asm(8):
syntax error
To invoke `mac` as a macro it must be indented
ERROR: syntax-error-after-syntax-error.asm(9):
'mac' already defined at syntax-error-after-syntax-error.asm(1)
ERROR: syntax-error-after-syntax-error.asm(10):
Expand Down

0 comments on commit 0068c13

Please sign in to comment.