Consolidate the 4 prologue alternative directives (%code, %requires,

%provides, and %code-top) into a single %code directive with an
optional qualifier field.  Discussed at
<http://lists.gnu.org/archive/html/bison-patches/2007-01/msg00012.html>.
* NEWS (2.3a+): Rewrite the existing entry for the prologue
alternatives.
* doc/bison.texinfo (Prologue Alternatives): Update.
(Decl Summary): Update to %code "requires" and %code "provides".
(Calc++ Parser): Update to %code "requires".
(Bison Symbols): Remove entries for %requires, %provides, and
%code-top.  Rewrite %code entry, and add a %code "QUALIFIER" entry.
* data/bison.m4 (b4_user_provides, b4_user_requires): Remove as these
are replaced by b4_percent_code_provides and b4_percent_code_requires,
which are skeleton-specific.
(b4_check_percent_code_qualifiers): New.  A skeleton can use this to
declare what %code qualifiers it supports and to complain if any other
qualifiers were used in the grammar.
* data/glr.cc: Update to use b4_user_code([b4_percent_code_requires])
and b4_user_code([b4_percent_code_provides]) in place of
b4_user_requires and b4_user_provides.
* data/glr.c, data/lalr1.cc, data/push.c, data/yacc.c: Likewise.
Add b4_user_code([b4_percent_code_top]) and
b4_user_code([b4_percent_code]).
Invoke b4_check_percent_code_qualifiers.
* src/parse-gram.y (PERCENT_CODE_TOP, PERCENT_PROVIDES,
PERCENT_REQUIRES): Remove.
(grammar_declaration): Remove RHS's for %code-top, %provides, and
%requires.  Rewrite the %code RHS as the unqualified form defining the
muscle b4_percent_code.  Add another RHS for the qualified %code form,
which defines muscles of the form b4_percent_code_QUALIFIER and the
b4_used_percent_code_qualifiers muscle.
* src/scan-gram.l (PERCENT_CODE_TOP, PERCENT_PROVIDES,
PERCENT_REQUIRES): Remove.
* tests/actions.at (_AT_CHECK_PRINTER_AND_DESTRUCTOR): Update to use
%code "requires" and %code "provides".
* tests/input.at (Reject bad %code qualifiers): New.
This commit is contained in:
Joel E. Denny
2007-01-05 08:14:45 +00:00
parent 95021767a1
commit 8e0a5e9e73
15 changed files with 1060 additions and 983 deletions

View File

@@ -133,7 +133,6 @@ static int current_prec = 0;
%token
PERCENT_CODE "%code"
PERCENT_CODE_TOP "%code-top"
PERCENT_DEBUG "%debug"
PERCENT_DEFAULT_PREC "%default-prec"
PERCENT_DEFINE "%define"
@@ -154,13 +153,11 @@ static int current_prec = 0;
"%nondeterministic-parser"
PERCENT_OUTPUT "%output"
PERCENT_PARSE_PARAM "%parse-param"
PERCENT_PROVIDES "%provides"
PERCENT_PURE_PARSER "%pure-parser"
PERCENT_PUSH_PARSER "%push-parser"
PERCENT_PUSH_PULL_PARSER
"%push-pull-parser"
PERCENT_REQUIRE "%require"
PERCENT_REQUIRES "%requires"
PERCENT_SKELETON "%skeleton"
PERCENT_START "%start"
PERCENT_TOKEN_TABLE "%token-table"
@@ -312,10 +309,22 @@ grammar_declaration:
{
default_prec = false;
}
| "%code" braceless { prologue_augment ($2, @2, true); }
| "%code-top" braceless { prologue_augment ($2, @2, false); }
| "%provides" braceless { muscle_code_grow ("provides", $2, @2); }
| "%requires" braceless { muscle_code_grow ("requires", $2, @2); }
| "%code" braceless
{
muscle_code_grow ("percent_code", $2, @2);
code_scanner_last_string_free ();
}
| "%code" STRING braceless
{
char const name_prefix[] = "percent_code_";
char *name = xmalloc (sizeof name_prefix + strlen ($2));
strcpy (name, name_prefix);
strcpy (name + sizeof name_prefix - 1, $2);
muscle_code_grow (uniqstr_new (name), $3, @3);
free (name);
code_scanner_last_string_free ();
muscle_grow ("used_percent_code_qualifiers", $2, ",");
}
;