From 0a9b3727bb246db12eaa22e6081358dde43318b5 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Fri, 1 Apr 2016 06:42:09 -0700 Subject: Revamp bad character messages in lexer. * parser.l (grammar): Drop colon from unrecognized escape message. "bad character in directive" handles various cases to avoid printing junk to the terminal. Basic message harmonizes with the one in the yybadtoken function in the parser. Non-UTF-8 byte printed as TXR hex integer literal. --- parser.l | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) (limited to 'parser.l') diff --git a/parser.l b/parser.l index 7c856274..32e90eff 100644 --- a/parser.l +++ b/parser.l @@ -767,7 +767,7 @@ UONLY {U2}{U}|{U3}{U}{U}|{U4}{U}{U}{U} } [\\]. { - yyerrorf(yyg, lit("unrecognized escape: \\~a"), chr(yytext[1]), nao); + yyerrorf(yyg, lit("unrecognized escape \\~a"), chr(yytext[1]), nao); } [;][^\n\r]* { @@ -775,13 +775,24 @@ UONLY {U2}{U}|{U3}{U}{U}|{U4}{U}{U}{U} } {UANYN} { - yyerrprepf(yyg, lit("bad character in directive: '~a'"), - string_utf8(yytext), nao); + val ch = chr_str(string_utf8(yytext), zero); + if (chr_isspace(ch)) + yyerrprepf(yyg, lit("unexpected whitespace character #\\x~02x"), + ch, nao); + else if (chr_isunisp(ch)) + yyerrprepf(yyg, lit("unexpected Unicode space character #\\x~02x"), + ch, nao); + else if (chr_iscntrl(ch)) + yyerrprepf(yyg, lit("unexpected control character #\\x~02x"), + ch, nao); + else + yyerrprepf(yyg, lit("unexpected character #\\~a"), + ch, nao); return ERRTOK; } . { - yyerrprepf(yyg, lit("non-UTF-8 byte in directive: '\\x~02x'"), + yyerrprepf(yyg, lit("non-UTF-8 byte #x~02x in directive"), num(convert(unsigned char, yytext[0])), nao); return ERRTOK; } -- cgit v1.2.3