mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-11 13:23:04 +00:00
grammar: introduce %empty
Provide a means to explicitly denote empty right-hand sides of rules:
instead of
exp: { ... }
allow
exp: %empty { ... }
Make sure that %empty is properly used.
With help from Joel E. Denny and Gabriel Rassoul.
http://lists.gnu.org/archive/html/bison-patches/2013-01/msg00142.html
* src/reader.h, src/reader.c (grammar_current_rule_empty_set): New.
* src/parse-gram.y (%empty): New token.
Use it.
* src/scan-gram.l (%empty): Scan it.
* src/reader.c (grammar_rule_check): Check that %empty is properly used.
* tests/actions.at (Invalid uses of %empty, Valid uses of %empty): New.
This commit is contained in:
17
src/reader.c
17
src/reader.c
@@ -333,6 +333,12 @@ grammar_rule_check (const symbol_list *r)
|
||||
}
|
||||
}
|
||||
|
||||
/* Check that %empty => empty rule. */
|
||||
if (r->percent_empty_loc.start.file
|
||||
&& r->next && r->next->content.sym)
|
||||
complain (&r->percent_empty_loc, complaint,
|
||||
_("%%empty on non-empty rule"));
|
||||
|
||||
/* 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. */
|
||||
@@ -434,6 +440,17 @@ grammar_current_rule_prec_set (symbol *precsym, location loc)
|
||||
current_rule->ruleprec = precsym;
|
||||
}
|
||||
|
||||
/* Set %empty for the current rule. */
|
||||
|
||||
void
|
||||
grammar_current_rule_empty_set (location loc)
|
||||
{
|
||||
if (current_rule->percent_empty_loc.start.file)
|
||||
complain (&loc, complaint, _("only one %s allowed per rule"), "%empty");
|
||||
else
|
||||
current_rule->percent_empty_loc = loc;
|
||||
}
|
||||
|
||||
/* Attach dynamic precedence DPREC to the current rule. */
|
||||
|
||||
void
|
||||
|
||||
Reference in New Issue
Block a user