Fix complaints about escape sequences.

Discussed starting at
<http://lists.gnu.org/archive/html/bison-patches/2009-08/msg00036.html>.
* src/scan-gram.l (SC_ESCAPED_STRING, SC_ESCAPED_CHARACTER):
For a \0 and similar escape sequences meaning the null
character, report an invalid escape sequence instead of an
invalid null character because the latter does not actually
appear in the user's input.
In all escape sequence complaints, don't escape the initial
backslash, and don't quote when the sequence appears at the end
of the complaint line unless there's whitespace that quotearg
won't escape.
Consistently say "invalid" not "unrecognized".
* tests/input.at (Bad escapes in literals): New.
(cherry picked from commit c2724603c9)

Conflicts:

	tests/input.at
This commit is contained in:
Joel E. Denny
2009-08-19 20:37:28 -04:00
parent a022ff4186
commit b1a4261e6d
3 changed files with 70 additions and 14 deletions

View File

@@ -37,6 +37,7 @@
#include "reader.h"
#include "uniqstr.h"
#include <ctype.h>
#include <mbswidth.h>
#include <quote.h>
@@ -399,10 +400,9 @@ splice (\\[ \f\t\v]*\n)*
{
\\[0-7]{1,3} {
unsigned long int c = strtoul (yytext + 1, NULL, 8);
if (UCHAR_MAX < c)
complain_at (*loc, _("invalid escape sequence: %s"), quote (yytext));
else if (! c)
complain_at (*loc, _("invalid null character: %s"), quote (yytext));
if (!c || UCHAR_MAX < c)
complain_at (*loc, _("invalid number after \\-escape: %s"),
yytext+1);
else
obstack_1grow (&obstack_for_string, c);
}
@@ -410,10 +410,9 @@ splice (\\[ \f\t\v]*\n)*
\\x[0-9abcdefABCDEF]+ {
verify (UCHAR_MAX < ULONG_MAX);
unsigned long int c = strtoul (yytext + 2, NULL, 16);
if (UCHAR_MAX < c)
complain_at (*loc, _("invalid escape sequence: %s"), quote (yytext));
else if (! c)
complain_at (*loc, _("invalid null character: %s"), quote (yytext));
if (!c || UCHAR_MAX < c)
complain_at (*loc, _("invalid number after \\-escape: %s"),
yytext+1);
else
obstack_1grow (&obstack_for_string, c);
}
@@ -431,16 +430,23 @@ splice (\\[ \f\t\v]*\n)*
\\(u|U[0-9abcdefABCDEF]{4})[0-9abcdefABCDEF]{4} {
int c = convert_ucn_to_byte (yytext);
if (c < 0)
complain_at (*loc, _("invalid escape sequence: %s"), quote (yytext));
else if (! c)
complain_at (*loc, _("invalid null character: %s"), quote (yytext));
if (c <= 0)
complain_at (*loc, _("invalid number after \\-escape: %s"),
yytext+1);
else
obstack_1grow (&obstack_for_string, c);
}
\\(.|\n) {
complain_at (*loc, _("unrecognized escape sequence: %s"), quote (yytext));
STRING_GROW;
char const *p = yytext + 1;
char quoted_ws[] = "` '";
if (isspace (*p) && isprint (*p))
{
quoted_ws[1] = *p;
p = quoted_ws;
}
else
p = quotearg_style_mem (escape_quoting_style, p, 1);
complain_at (*loc, _("invalid character after \\-escape: %s"), p);
}
}