/* 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;
%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_]
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. */
<SC_AFTER_IDENTIFIER>
{
"[" {
- 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);
<SC_BRACKETED_ID>
{
{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;
}
}
"]" {
}
}
else
- complain_at (*loc, _("a non empty identifier expected"));
+ complain_at (*loc, _("an identifier expected"));
}
. {
complain_at (*loc, _("invalid character in bracketed name: %s"),
<SC_ESCAPED_CHARACTER>
{
"'"|"\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;
}
<<EOF>> {
- 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;