X-Git-Url: https://git.saurik.com/bison.git/blobdiff_plain/e9690142325711b320ef444768fdd40a087d02f7..6c05543cb03b40b9728f7073c4073ce993d796c6:/src/scan-gram.l diff --git a/src/scan-gram.l b/src/scan-gram.l index 3c38906f..2275d022 100644 --- a/src/scan-gram.l +++ b/src/scan-gram.l @@ -1,6 +1,6 @@ /* Bison Grammar Scanner -*- C -*- - Copyright (C) 2002-2011 Free Software Foundation, Inc. + Copyright (C) 2002-2012 Free Software Foundation, Inc. This file is part of Bison, the GNU Compiler Compiler. @@ -36,7 +36,7 @@ #include #include -#include +#include #include #include @@ -100,16 +100,16 @@ static void unexpected_newline (boundary, char const *); /* Strings and characters in directives/rules. */ %x SC_ESCAPED_STRING SC_ESCAPED_CHARACTER /* A identifier was just read in directives/rules. Special state - to capture the sequence `identifier :'. */ + to capture the sequence 'identifier :'. */ %x SC_AFTER_IDENTIFIER /* A complex tag, with nested angles brackets. */ %x SC_TAG /* Four types of user code: - - prologue (code between `%{' `%}' in the first section, before %%); + - prologue (code between '%{' '%}' in the first section, before %%); - actions, printers, union, etc, (between braced in the middle section); - - epilogue (everything after the second %%). - - predicate (code between `%?{' and `{' in middle section); */ + - epilogue (everything after the second %%). + - predicate (code between '%?{' and '{' in middle section); */ %x SC_PROLOGUE SC_BRACED_CODE SC_EPILOGUE SC_PREDICATE /* C and C++ comments in code. */ %x SC_COMMENT SC_LINE_COMMENT @@ -164,7 +164,9 @@ splice (\\[ \f\t\v]*\n)* { /* Comments and white space. */ - "," warn_at (*loc, _("stray `,' treated as white space")); + "," { + complain_at (*loc, Wother, _("stray ',' treated as white space")); + } [ \f\n\t\v] | "//".* ; "/*" { @@ -239,7 +241,7 @@ splice (\\[ \f\t\v]*\n)* "%yacc" return PERCENT_YACC; {directive} { - complain_at (*loc, _("invalid directive: %s"), quote (yytext)); + complain_at (*loc, complaint, _("invalid directive: %s"), quote (yytext)); } "=" return EQUAL; @@ -265,7 +267,7 @@ splice (\\[ \f\t\v]*\n)* /* Identifiers may not start with a digit. Yet, don't silently accept "1FOO" as "1 FOO". */ {int}{id} { - complain_at (*loc, _("invalid identifier: %s"), quote (yytext)); + complain_at (*loc, complaint, _("invalid identifier: %s"), quote (yytext)); } /* Characters. */ @@ -323,7 +325,7 @@ splice (\\[ \f\t\v]*\n)* } . { - complain_at (*loc, _("invalid character: %s"), quote (yytext)); + complain_at (*loc, complaint, _("invalid character: %s"), quote (yytext)); } <> { @@ -340,7 +342,7 @@ splice (\\[ \f\t\v]*\n)* { - \0 complain_at (*loc, _("invalid null character")); + \0 complain_at (*loc, complaint, _("invalid null character")); } @@ -392,7 +394,8 @@ splice (\\[ \f\t\v]*\n)* {id} { if (bracketed_id_str) { - complain_at (*loc, _("unexpected identifier in bracketed name: %s"), + complain_at (*loc, complaint, + _("unexpected identifier in bracketed name: %s"), quote (yytext)); } else @@ -414,10 +417,10 @@ splice (\\[ \f\t\v]*\n)* } } else - complain_at (*loc, _("an identifier expected")); + complain_at (*loc, complaint, _("an identifier expected")); } . { - complain_at (*loc, _("invalid character in bracketed name: %s"), + complain_at (*loc, complaint, _("invalid character in bracketed name: %s"), quote (yytext)); } <> { @@ -440,7 +443,7 @@ splice (\\[ \f\t\v]*\n)* /*---------------------------------------------------------------. - | Scanning a Yacc comment. The initial `/ *' is already eaten. | + | Scanning a Yacc comment. The initial '/ *' is already eaten. | `---------------------------------------------------------------*/ @@ -452,7 +455,7 @@ splice (\\[ \f\t\v]*\n)* /*------------------------------------------------------------. - | Scanning a C comment. The initial `/ *' is already eaten. | + | Scanning a C comment. The initial '/ *' is already eaten. | `------------------------------------------------------------*/ @@ -463,7 +466,7 @@ splice (\\[ \f\t\v]*\n)* /*--------------------------------------------------------------. - | Scanning a line comment. The initial `//' is already eaten. | + | Scanning a line comment. The initial '//' is already eaten. | `--------------------------------------------------------------*/ @@ -515,12 +518,13 @@ splice (\\[ \f\t\v]*\n)* /* FIXME: Eventually, make these errors. */ if (last_string[0] == '\0') { - warn_at (*loc, _("empty character literal")); + complain_at (*loc, Wother, _("empty character literal")); /* '\0' seems dangerous even if we are about to complain. */ val->character = '\''; } else if (last_string[1] != '\0') - warn_at (*loc, _("extra characters in character literal")); + complain_at (*loc, Wother, + _("extra characters in character literal")); } if (yytext[0] == '\n') unexpected_newline (token_start, "'"); @@ -536,12 +540,13 @@ splice (\\[ \f\t\v]*\n)* /* FIXME: Eventually, make these errors. */ if (last_string[0] == '\0') { - warn_at (*loc, _("empty character literal")); + complain_at (*loc, Wother, _("empty character literal")); /* '\0' seems dangerous even if we are about to complain. */ val->character = '\''; } else if (last_string[1] != '\0') - warn_at (*loc, _("extra characters in character literal")); + complain_at (*loc, Wother, + _("extra characters in character literal")); } unexpected_eof (token_start, "'"); STRING_FREE; @@ -594,7 +599,7 @@ splice (\\[ \f\t\v]*\n)* \\[0-7]{1,3} { unsigned long int c = strtoul (yytext + 1, NULL, 8); if (!c || UCHAR_MAX < c) - complain_at (*loc, _("invalid number after \\-escape: %s"), + complain_at (*loc, complaint, _("invalid number after \\-escape: %s"), yytext+1); else obstack_1grow (&obstack_for_string, c); @@ -604,7 +609,7 @@ splice (\\[ \f\t\v]*\n)* verify (UCHAR_MAX < ULONG_MAX); unsigned long int c = strtoul (yytext + 2, NULL, 16); if (!c || UCHAR_MAX < c) - complain_at (*loc, _("invalid number after \\-escape: %s"), + complain_at (*loc, complaint, _("invalid number after \\-escape: %s"), yytext+1); else obstack_1grow (&obstack_for_string, c); @@ -624,7 +629,7 @@ 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 number after \\-escape: %s"), + complain_at (*loc, complaint, _("invalid number after \\-escape: %s"), yytext+1); else obstack_1grow (&obstack_for_string, c); @@ -632,11 +637,12 @@ splice (\\[ \f\t\v]*\n)* \\(.|\n) { char const *p = yytext + 1; /* Quote only if escaping won't make the character visible. */ - if (isspace ((unsigned char) *p) && isprint ((unsigned char) *p)) + if (c_isspace ((unsigned char) *p) && c_isprint ((unsigned char) *p)) p = quote (p); else p = quotearg_style_mem (escape_quoting_style, p, 1); - complain_at (*loc, _("invalid character after \\-escape: %s"), p); + complain_at (*loc, complaint, _("invalid character after \\-escape: %s"), + p); } } @@ -707,8 +713,8 @@ splice (\\[ \f\t\v]*\n)* "{"|"<"{splice}"%" STRING_GROW; nesting++; "%"{splice}">" STRING_GROW; nesting--; - /* Tokenize `<<%' correctly (as `<<' `%') rather than incorrrectly - (as `<' `<%'). */ + /* Tokenize '<<%' correctly (as '<<' '%') rather than incorrrectly + (as '<' '<%'). */ "<"{splice}"<" STRING_GROW; <> { @@ -867,7 +873,8 @@ scan_integer (char const *number, int base, location loc) if (INT_MAX < num) { - complain_at (loc, _("integer out of range: %s"), quote (number)); + complain_at (loc, complaint, _("integer out of range: %s"), + quote (number)); num = INT_MAX; } @@ -933,7 +940,7 @@ convert_ucn_to_byte (char const *ucn) /*----------------------------------------------------------------. -| Handle `#line INT "FILE"'. ARGS has already skipped `#line '. | +| Handle '#line INT "FILE"'. ARGS has already skipped '#line '. | `----------------------------------------------------------------*/ static void @@ -941,11 +948,11 @@ handle_syncline (char *args, location loc) { char *after_num; unsigned long int lineno = strtoul (args, &after_num, 10); - char *file = mbschr (after_num, '"') + 1; - *mbschr (file, '"') = '\0'; + char *file = strchr (after_num, '"') + 1; + *strchr (file, '"') = '\0'; if (INT_MAX <= lineno) { - warn_at (loc, _("line number overflow")); + complain_at (loc, Wother, _("line number overflow")); lineno = INT_MAX; } current_file = uniqstr_new (file); @@ -965,7 +972,11 @@ unexpected_end (boundary start, char const *msgid, char const *token_end) location loc; loc.start = start; loc.end = scanner_cursor; - complain_at (loc, _(msgid), token_end); + token_end = quote (token_end); + // Instead of '\'', display "'". + if (STREQ (token_end, "'\\''")) + token_end = "\"'\""; + complain_at (loc, complaint, _(msgid), token_end); } @@ -977,7 +988,7 @@ unexpected_end (boundary start, char const *msgid, char const *token_end) static void unexpected_eof (boundary start, char const *token_end) { - unexpected_end (start, N_("missing `%s' at end of file"), token_end); + unexpected_end (start, N_("missing %s at end of file"), token_end); } @@ -988,7 +999,7 @@ unexpected_eof (boundary start, char const *token_end) static void unexpected_newline (boundary start, char const *token_end) { - unexpected_end (start, N_("missing `%s' at end of line"), token_end); + unexpected_end (start, N_("missing %s at end of line"), token_end); }