X-Git-Url: https://git.saurik.com/bison.git/blobdiff_plain/ac060e78a3978ecef96ad68a2136f7f07e298cd1..4344c500b54542364f554342626ee476a0d6abeb:/src/scan-gram.l diff --git a/src/scan-gram.l b/src/scan-gram.l index 8f18c355..caad580f 100644 --- a/src/scan-gram.l +++ b/src/scan-gram.l @@ -27,6 +27,7 @@ #include "mbswidth.h" #include "complain.h" #include "quote.h" +#include "struniq.h" #include "getargs.h" #include "gram.h" #include "reader.h" @@ -35,7 +36,7 @@ #define YY_USER_INIT \ do { \ LOCATION_RESET (*yylloc); \ - yylloc->file = infile; \ + yylloc->file = current_file; \ /* This is only to avoid GCC warnings. */ \ if (yycontrol) {;}; \ } while (0) @@ -141,6 +142,10 @@ extend_location (location_t *loc, char const *token, int size) static struct obstack string_obstack; +/* A string representing the most recently saved token. */ +static char *last_string; + + #define YY_OBS_GROW \ obstack_grow (&string_obstack, yytext, yyleng) @@ -153,6 +158,11 @@ static struct obstack string_obstack; #define YY_OBS_FREE \ obstack_free (&string_obstack, last_string) +void +scanner_last_string_free (void) +{ + YY_OBS_FREE; +} /* Within well-formed rules, RULE_LENGTH is the number of values in the current rule so far, which says where to find `$0' with respect @@ -198,9 +208,6 @@ splice (\\[ \f\t\v]*\n)* /* Scanner context when scanning C code. */ int c_context IF_LINT (= 0); - /* A string representing the most recently saved token. */ - char *last_string; - /* At each yylex invocation, mark the current position as the start of the next token. */ YY_STEP; @@ -252,7 +259,10 @@ splice (\\[ \f\t\v]*\n)* YY_STEP; } - ^"#line "{int}" \""[^\"]*"\"\n" handle_syncline (yytext + strlen ("#line "), yylloc); YY_STEP; + ^"#line "{int}" \"".*"\"\n" { + handle_syncline (yytext + sizeof "#line " - 1, yylloc); + YY_STEP; + } "=" return EQUAL; ":" rule_length = 0; return COLON; @@ -301,7 +311,8 @@ splice (\\[ \f\t\v]*\n)* "<"{tag}">" { obstack_grow (&string_obstack, yytext + 1, yyleng - 2); YY_OBS_FINISH; - yylval->string = last_string; + yylval->struniq = struniq_new (last_string); + YY_OBS_FREE; return TYPE; } @@ -442,7 +453,10 @@ splice (\\[ \f\t\v]*\n)* \\r obstack_1grow (&string_obstack, '\r'); \\t obstack_1grow (&string_obstack, '\t'); \\v obstack_1grow (&string_obstack, '\v'); - \\[\"\'?\\] obstack_1grow (&string_obstack, yytext[1]); + + /* \\[\"\'?\\] would be shorter, but it confuses xgettext. */ + \\("\""|"'"|"?"|"\\") obstack_1grow (&string_obstack, yytext[1]); + \\(u|U[0-9a-fA-F]{4})[0-9a-fA-F]{4} { int c = convert_ucn_to_byte (yytext); if (c < 0) @@ -469,9 +483,9 @@ splice (\\[ \f\t\v]*\n)* { - "'" YY_OBS_GROW; BEGIN c_context; - \\{splice}[\'\\] YY_OBS_GROW; - <> unexpected_end_of_file (yylloc, "'"); + "'" YY_OBS_GROW; BEGIN c_context; + \\{splice}[^$@\[\]] YY_OBS_GROW; + <> unexpected_end_of_file (yylloc, "'"); } @@ -482,9 +496,9 @@ splice (\\[ \f\t\v]*\n)* { - "\"" YY_OBS_GROW; BEGIN c_context; - \\{splice}[\"\\] YY_OBS_GROW; - <> unexpected_end_of_file (yylloc, "\""); + "\"" YY_OBS_GROW; BEGIN c_context; + \\{splice}[^$@\[\]] YY_OBS_GROW; + <> unexpected_end_of_file (yylloc, "\""); } @@ -827,10 +841,8 @@ handle_syncline (char *args, location_t *location) const char *file = NULL; file = strchr (args, '"') + 1; *strchr (file, '"') = 0; - /* FIXME: Leaking... Can't free, as some locations are still - pointing to the old file name. */ - infile = xstrdup (file); - location->file = infile; + current_file = xstrdup (file); + location->file = current_file; location->last_line = lineno; }