diff options
-rw-r--r-- | src/lexer.l | 25 | ||||
-rw-r--r-- | src/main.c | 9 |
2 files changed, 24 insertions, 10 deletions
diff --git a/src/lexer.l b/src/lexer.l index 39c9443..5317966 100644 --- a/src/lexer.l +++ b/src/lexer.l @@ -25,7 +25,7 @@ yylloc.last_column = 1; \ } while (false) \ -extern bool interactive; +extern bool interactive, utf8; extern const char *current_file; %} @@ -77,12 +77,27 @@ ws [ \t] offending token but instead on the next line typed by the user. */ . { char ch = *yytext; + + static const char *quotes[][2] = { + {"`", "'"}, + {"‘", "’"}, + }; + + const char *lquot = quotes[utf8][0], + *rquot = quotes[utf8][1]; + if (ch == '&') { - user_error("%s:%d:%d: Unrecognized character ‘%c’, did you mean ‘%c%c’?", - current_file, yylloc.first_line, yylloc.first_column, ch, ch, ch); + user_error("%s:%d:%d: Unrecognized character %s&%s, did you mean %s&&%s?", + current_file, yylloc.first_line, yylloc.first_column, + lquot, rquot, lquot, rquot); + } else if (ch == '^') { + user_error("%s:%d:%d: Unrecognized character %s^%s, did you mean %s~%s?", + current_file, yylloc.first_line, yylloc.first_column, + lquot, rquot, lquot, rquot); } else { - user_error("%s:%d:%d: Unrecognized character ‘%c’", - current_file, yylloc.first_line, yylloc.first_column, ch); + user_error("%s:%d:%d: Unrecognized character %s%c%s", + current_file, yylloc.first_line, yylloc.first_column, + lquot, ch, rquot); } BEGIN(error); return YYerror; @@ -43,7 +43,7 @@ static int rv; static bool_style_t bflag = BS_BINARY; static tbl_style_t tflag = TS_UNSET; -bool interactive; +bool interactive, utf8; const char *current_file; static void astprocess_cli(asts_t); @@ -119,10 +119,9 @@ usage: } } - if (tflag == TS_UNSET) { - tflag = streq(nl_langinfo(CODESET), "UTF-8") - ? TS_UTF8 : TS_ASCII; - } + utf8 = streq(nl_langinfo(CODESET), "UTF-8"); + if (tflag == TS_UNSET) + tflag = utf8 ? TS_UTF8 : TS_ASCII; argc -= optind; argv += optind; |