On 18/06/2020 00:44, Akim Demaille wrote:
> There is no way to rename it, and it wouldn't make sense as the error
> token is never presented as an "expected token". The error token never
> shows to the (end) user. It appears in the debug traces, but that's
> for the developer.
What about YYEOF and YYUNDEF? Those appear in error messages.
I use a function like this to get token names to used to print a dump of
the token stream of a lexer:
const char* token_name(int token)
{
return yysymbol_name(YYTRANSLATE(token));
}
However I have a ton of tests that expect the lexer to emit a
"LEX_ERROR" token on error and I am considering to use YYerror special
token to report errors instead. Thus the question if I can rename
YYerror from "error" to "LEX_ERROR".
The fix is rather easy:
const char* token_name(int token)
{
if (token == YYerror)
return "LEX_ERROR";
return yysymbol_name(YYTRANSLATE(token));
}
I just anted to check if there is a built in mechanism to achieve the
same. However, to support renaming YYEOF and YYUNDEF (which appear in
ereor messages, if I am not mistaken) would probably be something good
to have.
Cheers,
Dan