X-Git-Url: https://git.saurik.com/bison.git/blobdiff_plain/a2bc9dbc7b577c891811dd96f66a8e0daa66bf93..916708d59e02812675ce2d85597b7e1f2d677213:/src/scan-gram.l diff --git a/src/scan-gram.l b/src/scan-gram.l index a31cd02e..337f9db1 100644 --- a/src/scan-gram.l +++ b/src/scan-gram.l @@ -20,7 +20,7 @@ 02111-1307 USA */ -%option debug nodefault noyywrap never-interactive +%option debug nodefault nounput noyywrap never-interactive %option prefix="gram_" outfile="lex.yy.c" %{ @@ -43,6 +43,7 @@ scanner_cursor.file = current_file; \ scanner_cursor.line = 1; \ scanner_cursor.column = 1; \ + code_start = scanner_cursor; \ } \ while (0) @@ -101,7 +102,7 @@ static void handle_dollar (int token_type, char *cp, location loc); static void handle_at (int token_type, char *cp, location loc); static void handle_syncline (char *args); static int convert_ucn_to_byte (char const *hex_text); -static void unexpected_end_of_file (boundary, char const *); +static void unexpected_eof (boundary, char const *); %} %x SC_COMMENT SC_LINE_COMMENT SC_YACC_COMMENT @@ -197,6 +198,7 @@ splice (\\[ \f\t\v]*\n)* "%name"[-_]"prefix" return PERCENT_NAME_PREFIX; "%no"[-_]"lines" return PERCENT_NO_LINES; "%nonassoc" return PERCENT_NONASSOC; + "%nondeterministic-parser" return PERCENT_NONDETERMINISTIC_PARSER; "%nterm" return PERCENT_NTERM; "%output" return PERCENT_OUTPUT; "%parse-param" token_type = PERCENT_PARSE_PARAM; BEGIN SC_PRE_CODE; @@ -279,6 +281,11 @@ splice (\\[ \f\t\v]*\n)* . { complain_at (*loc, _("invalid character: %s"), quote (yytext)); } + + <> { + loc->start = loc->end = scanner_cursor; + yyterminate (); + } } @@ -317,7 +324,7 @@ splice (\\[ \f\t\v]*\n)* { "*/" BEGIN context_state; .|\n ; - <> unexpected_end_of_file (token_start, "*/"); + <> unexpected_eof (token_start, "*/"); BEGIN context_state; } @@ -328,7 +335,7 @@ splice (\\[ \f\t\v]*\n)* { "*"{splice}"/" STRING_GROW; BEGIN context_state; - <> unexpected_end_of_file (token_start, "*/"); + <> unexpected_eof (token_start, "*/"); BEGIN context_state; } @@ -362,7 +369,7 @@ splice (\\[ \f\t\v]*\n)* } .|\n STRING_GROW; - <> unexpected_end_of_file (token_start, "\""); + <> unexpected_eof (token_start, "\""); BEGIN INITIAL; } /*---------------------------------------------------------------. @@ -388,7 +395,7 @@ splice (\\[ \f\t\v]*\n)* } .|\n STRING_GROW; - <> unexpected_end_of_file (token_start, "'"); + <> unexpected_eof (token_start, "'"); BEGIN INITIAL; } @@ -450,7 +457,7 @@ splice (\\[ \f\t\v]*\n)* { "'" STRING_GROW; BEGIN context_state; \\{splice}[^$@\[\]] STRING_GROW; - <> unexpected_end_of_file (token_start, "'"); + <> unexpected_eof (token_start, "'"); BEGIN context_state; } @@ -463,7 +470,10 @@ splice (\\[ \f\t\v]*\n)* { "\"" STRING_GROW; BEGIN context_state; \\{splice}[^$@\[\]] STRING_GROW; - <> unexpected_end_of_file (token_start, "\""); + <> { + unexpected_eof (token_start, "\""); + BEGIN context_state; + } } @@ -529,6 +539,8 @@ splice (\\[ \f\t\v]*\n)* return token_type; } } + + <> unexpected_eof (scanner_cursor, "{}"); BEGIN INITIAL; } @@ -581,7 +593,7 @@ splice (\\[ \f\t\v]*\n)* "$"("<"{tag}">")?(-?[0-9]+|"$") handle_dollar (token_type, yytext, *loc); "@"(-?[0-9]+|"$") handle_at (token_type, yytext, *loc); - <> unexpected_end_of_file (code_start, "}"); + <> unexpected_eof (code_start, "}"); BEGIN INITIAL; } @@ -599,7 +611,7 @@ splice (\\[ \f\t\v]*\n)* return PROLOGUE; } - <> unexpected_end_of_file (code_start, "%}"); + <> unexpected_eof (code_start, "%}"); BEGIN INITIAL; } @@ -963,25 +975,15 @@ handle_syncline (char *args) /*------------------------------------------------------------------------. | Report an unexpected EOF in a token or comment starting at START. | | An end of file was encountered and the expected TOKEN_END was missing. | -| After reporting the problem, pretend that TOKEN_END was found. | `------------------------------------------------------------------------*/ static void -unexpected_end_of_file (boundary start, char const *token_end) +unexpected_eof (boundary start, char const *token_end) { - size_t i = strlen (token_end); - location loc; loc.start = start; loc.end = scanner_cursor; complain_at (loc, _("missing `%s' at end of file"), token_end); - - /* Adjust scanner cursor so that any later message does not count - the characters about to be inserted. */ - scanner_cursor.column -= i; - - while (i != 0) - unput (token_end[--i]); }