Clean up %define and %code implementation in M4 some. Most

importantly, rename all related macros to be in the b4_percent_define
and b4_percent_code namespaces.  Also, complete support for `.' in
%define variable names and %code qualifiers.
* data/bison.m4 (b4_check_user_names): Check for special
"SKELETON-NAMESPACE(name)" macros instead of using two nested
m4_foreach loops.
(b4_get_percent_define, b4_get_percent_code): Rename to...
(b4_percent_define_get, b4_percent_code_get): ... these.
Extend documentation with examples.
For SKELETON-NAMESPACE (as documented for b4_check_user_names), use
b4_percent_define_skeleton_variables and
b4_percent_code_skeleton_qualifiers.
Expect any value for the %define variable `foo' to be stored in the
macro named `b4_percent_define(foo)'; expect any %code blocks for the
qualifier `foo' to be stored in a macro named `b4_percent_code(foo)';
expect any unqualified %code blocks to be stored in a macro named
`b4_percent_code_unqualified'.
Use m4_indir so that %define variable names and %code qualifiers can
contain `.', which is allowed by the grammar parser.
(b4_percent_define_default): New macro to set a default value for a
%define variable.
(m4_wrap): Update wrapped code, and fix some underquoting.
(b4_check_user_names_wrap): Update and define outside the m4_wrap.
Expect grammar uses of %define variables and %code qualifiers to be
defined in b4_percent_define_user_variables and
b4_percent_code_user_qualifiers.
* data/c++.m4: Use b4_percent_define_default rather than
m4_define_default.  Fix some underquoting.  Skeleton usage of %define
variable define_location_comparison now implies skeleton usage of
%define variable filename_type.
* data/glr.c, data/glr.cc, data/lalr1.cc, data/location.cc,
data/push.c, data/yacc.c: Update macro names.
* src/parse-gram.y (prologue_declaration, grammar_declaration): Update
muscle names.
This commit is contained in:
Joel E. Denny
2007-01-16 06:16:04 +00:00
parent e37c665c41
commit a4e25e1dec
11 changed files with 269 additions and 214 deletions

View File

@@ -235,15 +235,17 @@ prologue_declaration:
| "%debug" { debug_flag = true; }
| "%define" variable content.opt
{
char const name_prefix[] = "percent_define_";
char *name = xmalloc (sizeof name_prefix + strlen ($2));
char const name_prefix[] = "percent_define(";
size_t length = strlen ($2);
char *name = xmalloc (sizeof name_prefix + length + 1);
strcpy (name, name_prefix);
strcpy (name + sizeof name_prefix - 1, $2);
strcpy (name + sizeof name_prefix - 1 + length, ")");
if (muscle_find_const (name))
warn_at (@2, _("%s `%s' redefined"), "%define variable", $2);
MUSCLE_INSERT_STRING (uniqstr_new (name), $3);
free (name);
muscle_grow_user_name_list ("user_percent_define_variables", $2, @2);
muscle_grow_user_name_list ("percent_define_user_variables", $2, @2);
}
| "%defines" { defines_flag = true; }
| "%defines" STRING
@@ -322,19 +324,21 @@ grammar_declaration:
}
| "%code" braceless
{
muscle_code_grow ("percent_code", $2, @2);
muscle_code_grow ("percent_code_unqualified", $2, @2);
code_scanner_last_string_free ();
}
| "%code" ID braceless
{
char const name_prefix[] = "percent_code_";
char *name = xmalloc (sizeof name_prefix + strlen ($2));
char const name_prefix[] = "percent_code(";
size_t length = strlen ($2);
char *name = xmalloc (sizeof name_prefix + length + 1);
strcpy (name, name_prefix);
strcpy (name + sizeof name_prefix - 1, $2);
strcpy (name + sizeof name_prefix - 1 + length, ")");
muscle_code_grow (uniqstr_new (name), $3, @3);
free (name);
code_scanner_last_string_free ();
muscle_grow_user_name_list ("user_percent_code_qualifiers", $2, @2);
muscle_grow_user_name_list ("percent_code_user_qualifiers", $2, @2);
}
;