Avoid treating labels and macros differently in column 1 (#1515)

Fixes #1512
This commit is contained in:
Sylvie
2024-09-22 19:26:25 -04:00
committed by GitHub
parent 15919e550f
commit 6b89938da7
9 changed files with 75 additions and 39 deletions

View File

@@ -1849,7 +1849,19 @@ static Token yylex_NORMAL() {
}
}
if (token.type == T_(ID) && (lexerState->atLineStart || peek() == ':'))
// This is a "lexer hack"! We need it to distinguish between label definitions
// (which start with `LABEL`) and macro invocations (which start with `ID`).
//
// If we had one `IDENTIFIER` token, the parser would need to perform "lookahead"
// to determine which rule applies. But since macros need to enter "raw" mode to
// parse their arguments, which may not even be valid tokens in "normal" mode, we
// cannot use lookahead to check for the presence of a `COLON`.
//
// Instead, we have separate `ID` and `LABEL` tokens, lexing as a `LABEL` if a ':'
// character *immediately* follows the identifier. Thus, at the beginning of a line,
// "Label:" and "mac:" are treated as label definitions, but "Label :" and "mac :"
// are treated as macro invocations.
if (token.type == T_(ID) && peek() == ':')
token.type = T_(LABEL);
return token;

View File

@@ -433,22 +433,6 @@ line:
fstk_StopRept();
yyerrok;
}
// Hint about unindented macros parsed as labels
| LABEL error {
lexer_SetMode(LEXER_NORMAL);
lexer_ToggleStringExpansion(true);
} endofline {
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.c_str()
);
fstk_StopRept();
yyerrok;
}
;
endofline: NEWLINE | EOB;