summaryrefslogtreecommitdiffstats
path: root/parser.l
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2016-04-01 06:42:09 -0700
committerKaz Kylheku <kaz@kylheku.com>2016-04-01 06:42:09 -0700
commit0a9b3727bb246db12eaa22e6081358dde43318b5 (patch)
tree1b32e33b99ff04345de2d1547c2c248bba4fde79 /parser.l
parentb9a7ca98b2e154ec2e3a7490f9838e1fddd72f52 (diff)
downloadtxr-0a9b3727bb246db12eaa22e6081358dde43318b5.tar.gz
txr-0a9b3727bb246db12eaa22e6081358dde43318b5.tar.bz2
txr-0a9b3727bb246db12eaa22e6081358dde43318b5.zip
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.
Diffstat (limited to 'parser.l')
-rw-r--r--parser.l19
1 files changed, 15 insertions, 4 deletions
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}
}
<SPECIAL>[\\]. {
- yyerrorf(yyg, lit("unrecognized escape: \\~a"), chr(yytext[1]), nao);
+ yyerrorf(yyg, lit("unrecognized escape \\~a"), chr(yytext[1]), nao);
}
<SPECIAL,QSPECIAL,NESTED,BRACED>[;][^\n\r]* {
@@ -775,13 +775,24 @@ UONLY {U2}{U}|{U3}{U}{U}|{U4}{U}{U}{U}
}
<SPECIAL,QSPECIAL,NESTED,BRACED>{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;
}
<SPECIAL,QSPECIAL,NESTED,BRACED>. {
- 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;
}