mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-09 20:33:03 +00:00
POSIX: warn if %prec's token was not defined.
Reported by Florian Krohm at
<http://lists.gnu.org/archive/html/bug-bison/2009-12/msg00005.html>.
* NEWS (2.4.2): Document.
* src/reader.c (grammar_rule_check): Implement.
(grammar_current_rule_prec_set): Add comments explaining that we
here assume a %prec identifier is a token, but we still manage
to support POSIX.
* tests/input.at (%prec's token must be defined): New test
group.
(cherry picked from commit f1ceed0774)
This commit is contained in:
19
src/reader.c
19
src/reader.c
@@ -320,6 +320,15 @@ grammar_rule_check (const symbol_list *r)
|
||||
warn_at (r->location, _("unset value: $$"));
|
||||
}
|
||||
}
|
||||
|
||||
/* See comments in grammar_current_rule_prec_set for how POSIX
|
||||
mandates this complaint. It's only for identifiers, so skip
|
||||
it for char literals and strings, which are always tokens. */
|
||||
if (r->ruleprec
|
||||
&& r->ruleprec->tag[0] != '\'' && r->ruleprec->tag[0] != '"'
|
||||
&& !r->ruleprec->declared && !r->ruleprec->prec)
|
||||
warn_at (r->location, _("token for %%prec is not defined: %s"),
|
||||
r->ruleprec->tag);
|
||||
}
|
||||
|
||||
|
||||
@@ -396,6 +405,16 @@ grammar_midrule_action (void)
|
||||
void
|
||||
grammar_current_rule_prec_set (symbol *precsym, location loc)
|
||||
{
|
||||
/* POSIX says that any identifier is a nonterminal if it does not
|
||||
appear on the LHS of a grammar rule and is not defined by %token
|
||||
or by one of the directives that assigns precedence to a token. We
|
||||
ignore this here because the only kind of identifier that POSIX
|
||||
allows to follow a %prec is a token and because assuming it's a
|
||||
token now can produce more logical error messages. Nevertheless,
|
||||
grammar_rule_check does obey what we believe is the real intent of
|
||||
POSIX here: that an error be reported for any identifier that
|
||||
appears after %prec but that is not defined separately as a
|
||||
token. */
|
||||
symbol_class_set (precsym, token_sym, loc, false);
|
||||
if (current_rule->ruleprec)
|
||||
complain_at (loc, _("only one %s allowed per rule"), "%prec");
|
||||
|
||||
Reference in New Issue
Block a user