X-Git-Url: https://git.saurik.com/bison.git/blobdiff_plain/31b850d2d433aff80a6cc31fef79ada95dab0153..3208e3f4d9aff080a546685560536336f0852bcb:/src/scan-gram.l diff --git a/src/scan-gram.l b/src/scan-gram.l index 279bba97..5c0418c6 100644 --- a/src/scan-gram.l +++ b/src/scan-gram.l @@ -70,7 +70,7 @@ static size_t no_cr_read (FILE *, char *, size_t); /* A string representing the most recently saved token. */ static char *last_string; -/* Bracketed identifier */ +/* Bracketed identifier. */ static uniqstr bracketed_id_str = 0; static location bracketed_id_loc; static boundary bracketed_id_start; @@ -108,7 +108,7 @@ static void unexpected_newline (boundary, char const *); %x SC_COMMENT SC_LINE_COMMENT /* Strings and characters in code. */ %x SC_STRING SC_CHARACTER - /* Bracketed identifiers support */ + /* Bracketed identifiers support. */ %x SC_BRACKETED_ID SC_RETURN_BRACKETED_ID letter [-.abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_] @@ -260,7 +260,7 @@ splice (\\[ \f\t\v]*\n)* complain_at (*loc, _("invalid identifier: %s"), quote (yytext)); } - /* Characters. We don't check there is only one. */ + /* Characters. */ "'" STRING_GROW; token_start = loc->start; BEGIN SC_ESCAPED_CHARACTER; /* Strings. */ @@ -336,19 +336,19 @@ splice (\\[ \f\t\v]*\n)* { "[" { - if (!bracketed_id_str) - { - bracketed_id_start = loc->start; - bracketed_id_context_state = YY_START; - BEGIN SC_BRACKETED_ID; - } - else + if (bracketed_id_str) { ROLLBACK_CURRENT_TOKEN; BEGIN SC_RETURN_BRACKETED_ID; *loc = id_loc; return ID; } + else + { + bracketed_id_start = loc->start; + bracketed_id_context_state = YY_START; + BEGIN SC_BRACKETED_ID; + } } ":" { BEGIN (bracketed_id_str ? SC_RETURN_BRACKETED_ID : INITIAL); @@ -375,15 +375,15 @@ splice (\\[ \f\t\v]*\n)* { {id} { - if (!bracketed_id_str) + if (bracketed_id_str) { - bracketed_id_str = uniqstr_new (yytext); - bracketed_id_loc = *loc; + complain_at (*loc, _("unexpected identifier in bracketed name: %s"), + quote (yytext)); } else { - complain_at (*loc, _("redundant identifier in bracketed name: %s"), - quote (yytext)); + bracketed_id_str = uniqstr_new (yytext); + bracketed_id_loc = *loc; } } "]" { @@ -399,7 +399,7 @@ splice (\\[ \f\t\v]*\n)* } } else - complain_at (*loc, _("a non empty identifier expected")); + complain_at (*loc, _("an identifier expected")); } . { complain_at (*loc, _("invalid character in bracketed name: %s"), @@ -493,24 +493,40 @@ splice (\\[ \f\t\v]*\n)* { "'"|"\n" { - if (yytext[0] == '\n') - unexpected_newline (token_start, "'"); STRING_GROW; STRING_FINISH; loc->start = token_start; val->character = last_string[1]; + { + /* FIXME: Eventually, make these errors. */ + size_t length = strlen (last_string); + if (strlen (last_string) < 3) + warn_at (*loc, _("empty character literal")); + else if (strlen (last_string) > 3) + warn_at (*loc, _("extra characters in character literal")); + } + if (yytext[0] == '\n') + unexpected_newline (token_start, "'"); STRING_FREE; BEGIN INITIAL; return CHAR; } <> { - unexpected_eof (token_start, "'"); STRING_FINISH; loc->start = token_start; - if (strlen (last_string) > 1) - val->character = last_string[1]; - else - val->character = last_string[0]; + { + size_t length = strlen (last_string); + /* FIXME: Eventually, make these errors. */ + if (length < 2) + warn_at (*loc, _("empty character literal")); + else if (length > 2) + warn_at (*loc, _("extra characters in character literal")); + if (length > 1) + val->character = last_string[1]; + else + val->character = last_string[0]; + } + unexpected_eof (token_start, "'"); STRING_FREE; BEGIN INITIAL; return CHAR;