mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-09 04:13:03 +00:00
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:
@@ -184,8 +184,6 @@ m4_define([b4_define_user_code],
|
||||
# b4_user_initial_action
|
||||
# b4_user_post_prologue
|
||||
# b4_user_pre_prologue
|
||||
# b4_user_provides
|
||||
# b4_user_requires
|
||||
# b4_user_stype
|
||||
# ----------------------
|
||||
# Macros that issue user code, ending with synclines.
|
||||
@@ -193,8 +191,38 @@ b4_define_user_code([actions])
|
||||
b4_define_user_code([initial_action])
|
||||
b4_define_user_code([post_prologue])
|
||||
b4_define_user_code([pre_prologue])
|
||||
b4_define_user_code([provides])
|
||||
b4_define_user_code([requires])
|
||||
b4_define_user_code([stype])
|
||||
|
||||
|
||||
# b4_check_percent_code_qualifiers([VAILD_QUALIFIER], [VALID_QUALIFIER], ...)
|
||||
# ---------------------------------------------------------------------------
|
||||
# Complain if any %code qualifier used in the grammar is not a valid qualifier.
|
||||
#
|
||||
# b4_used_percent_code_qualifiers must expand to a comma-delimited list of the
|
||||
# %code qualifiers used in the grammar. The list as a whole must be quoted,
|
||||
# but individual qualifiers in it must not be. Qualifiers will not be
|
||||
# M4-expanded. Whitespace will not be stripped from the qualifiers. Any
|
||||
# qualifier that is the empty string will be correctly parsed as such. If
|
||||
# b4_used_percent_code_qualifiers expands to the empty string, then the list
|
||||
# contains one qualifier that is the empty string. If
|
||||
# b4_used_percent_code_qualifiers is undefined, then the list contains no
|
||||
# qualifiers. Multiple occurrences of the same qualifier are fine.
|
||||
#
|
||||
# Each VALID_QUALIFIER will be M4-expanded once to define a valid qualifier. A
|
||||
# VALID_QUALIFIER that expands to the empty string will correctly define the
|
||||
# empty string as a valid qualifier. If b4_used_percent_code_qualifiers is
|
||||
# invoked with empty parens, then there is one valid qualifier and it is the
|
||||
# empty string. To specify that there are no valid qualifiers, invoke
|
||||
# b4_check_percent_code_qualifiers without parens. Multiple occurrences of the
|
||||
# same valid qualifier are fine.
|
||||
#
|
||||
# Qualifiers and valid qualifiers must not contain the characters `,' or `&'.
|
||||
m4_define([b4_check_percent_code_qualifiers],
|
||||
[m4_ifdef([b4_used_percent_code_qualifiers], [
|
||||
m4_foreach([b4_qualifier],
|
||||
m4_dquote(m4_substr(m4_split(m4_translit(m4_dquote([,]b4_used_percent_code_qualifiers), [,], [&]), [[&]]), 4)),
|
||||
[m4_if(m4_index(m4_if($#, 0, [], [[,]m4_quote($*)[,]]),
|
||||
[,]m4_defn([b4_qualifier])[,]),
|
||||
[-1],
|
||||
[m4_fatal([`]m4_defn([b4_qualifier])[' is not a recognized %code qualifier.])])
|
||||
])
|
||||
])])
|
||||
|
||||
24
data/glr.c
24
data/glr.c
@@ -20,6 +20,7 @@ m4_divert(-1) -*- C -*-
|
||||
|
||||
|
||||
m4_include(b4_pkgdatadir/[c.m4])
|
||||
b4_check_percent_code_qualifiers([[requires]], [[provides]], [[top]])
|
||||
|
||||
b4_push_if([
|
||||
m4_fatal([Non-deterministic push parsers are not yet supported])])
|
||||
@@ -153,6 +154,9 @@ b4_copyright([Skeleton implementation for Bison GLR parsers in C],
|
||||
|
||||
]b4_identification
|
||||
|
||||
m4_ifdef([b4_percent_code_top],
|
||||
[[/* Copy the %code "top" blocks. */
|
||||
]b4_user_code([b4_percent_code_top])])[]dnl
|
||||
m4_if(b4_prefix, [yy], [],
|
||||
[/* Substitute the variable and function names. */
|
||||
#define yyparse b4_prefix[]parse
|
||||
@@ -172,9 +176,9 @@ dnl # ----------------------
|
||||
dnl # Declaration that might either go into the header (if --defines)
|
||||
dnl # or open coded in the parser body.
|
||||
m4_define([b4_shared_declarations],
|
||||
[m4_ifdef([b4_requires],
|
||||
[[/* Copy the %requires blocks. */
|
||||
]b4_user_requires])[]dnl
|
||||
[m4_ifdef([b4_percent_code_requires],
|
||||
[[/* Copy the %code "requires" blocks. */
|
||||
]b4_user_code([b4_percent_code_requires])])[]dnl
|
||||
|
||||
b4_token_enums(b4_tokens)
|
||||
|
||||
@@ -205,9 +209,9 @@ typedef struct YYLTYPE
|
||||
# define YYLTYPE_IS_TRIVIAL 1
|
||||
#endif
|
||||
|
||||
]m4_ifdef([b4_provides],
|
||||
[[/* Copy the %provides blocks. */
|
||||
]b4_user_provides])[]dnl
|
||||
]m4_ifdef([b4_percent_code_provides],
|
||||
[[/* Copy the %code "provides" blocks. */
|
||||
]b4_user_code([b4_percent_code_provides])])[]dnl
|
||||
])
|
||||
|
||||
b4_defines_if([[#include "@basename(]b4_spec_defines_file[@)"]],
|
||||
@@ -239,9 +243,13 @@ b4_defines_if([[#include "@basename(]b4_spec_defines_file[@)"]],
|
||||
static YYSTYPE yyval_default;
|
||||
|
||||
/* Copy the second part of user declarations. */
|
||||
]b4_user_post_prologue[
|
||||
]b4_user_post_prologue
|
||||
m4_ifdef([b4_percent_code],
|
||||
[[/* Copy the unqualified %code blocks. */
|
||||
]b4_user_code([b4_percent_code])
|
||||
])[]dnl
|
||||
|
||||
#include <stdio.h>
|
||||
[#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
|
||||
12
data/glr.cc
12
data/glr.cc
@@ -225,9 +225,9 @@ b4_copyright([Skeleton interface for Bison GLR parsers in C++],
|
||||
#ifndef PARSER_HEADER_H
|
||||
# define PARSER_HEADER_H
|
||||
|
||||
]m4_ifdef([b4_requires],
|
||||
[[/* Copy the %requires blocks. */
|
||||
]b4_user_requires])[
|
||||
]m4_ifdef([b4_percent_code_requires],
|
||||
[[/* Copy the %code "requires" blocks. */
|
||||
]b4_user_code([b4_percent_code_requires])])[
|
||||
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
@@ -373,8 +373,8 @@ m4_ifset([b4_global_tokens_and_yystype],
|
||||
|
||||
}
|
||||
|
||||
]m4_ifdef([b4_provides],
|
||||
[[/* Copy the %provides blocks. */
|
||||
]b4_user_provides])[]dnl
|
||||
]m4_ifdef([b4_percent_code_provides],
|
||||
[[/* Copy the %code "provides" blocks. */
|
||||
]b4_user_code([b4_percent_code_provides])])[]dnl
|
||||
|
||||
[#endif /* ! defined PARSER_HEADER_H */]
|
||||
|
||||
@@ -20,6 +20,7 @@ m4_divert(-1)
|
||||
# 02110-1301 USA
|
||||
|
||||
m4_include(b4_pkgdatadir/[c++.m4])
|
||||
b4_check_percent_code_qualifiers([[requires]], [[provides]], [[top]])
|
||||
|
||||
# The header is mandatory.
|
||||
b4_defines_if([],
|
||||
@@ -43,9 +44,9 @@ dnl FIXME: This is wrong, we want computed header guards.
|
||||
#ifndef PARSER_HEADER_H
|
||||
# define PARSER_HEADER_H
|
||||
|
||||
]m4_ifdef([b4_requires],
|
||||
[[/* Copy the %requires blocks. */
|
||||
]b4_user_requires])[
|
||||
]m4_ifdef([b4_percent_code_requires],
|
||||
[[/* Copy the %code "requires" blocks. */
|
||||
]b4_user_code([b4_percent_code_requires])])[
|
||||
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
@@ -295,15 +296,18 @@ b4_error_verbose_if([, int tok])[);
|
||||
# define YYSTYPE b4_namespace::b4_parser_class_name::semantic_type
|
||||
#endif
|
||||
])
|
||||
m4_ifdef([b4_provides],
|
||||
[[/* Copy the %provides blocks. */
|
||||
]b4_user_provides])[]dnl
|
||||
m4_ifdef([b4_percent_code_provides],
|
||||
[[/* Copy the %code "provides" blocks. */
|
||||
]b4_user_code([b4_percent_code_provides])])[]dnl
|
||||
|
||||
[#endif /* ! defined PARSER_HEADER_H */]
|
||||
])dnl
|
||||
@output b4_parser_file_name
|
||||
b4_copyright([Skeleton implementation for Bison LALR(1) parsers in C++],
|
||||
[2002, 2003, 2004, 2005, 2006])
|
||||
m4_ifdef([b4_percent_code_top],
|
||||
[[/* Copy the %code "top" blocks. */
|
||||
]b4_user_code([b4_percent_code_top])])[]dnl
|
||||
m4_if(b4_prefix, [yy], [],
|
||||
[
|
||||
// Take the name prefix into account.
|
||||
@@ -316,9 +320,13 @@ b4_defines_if([[
|
||||
#include "@basename(]b4_spec_defines_file[@)"]])[
|
||||
|
||||
/* User implementation prologue. */
|
||||
]b4_user_post_prologue[
|
||||
]b4_user_post_prologue
|
||||
m4_ifdef([b4_percent_code],
|
||||
[[/* Copy the unqualified %code blocks. */
|
||||
]b4_user_code([b4_percent_code])
|
||||
])[]dnl
|
||||
|
||||
#ifndef YY_
|
||||
[#ifndef YY_
|
||||
# if YYENABLE_NLS
|
||||
# if ENABLE_NLS
|
||||
# include <libintl.h> /* FIXME: INFRINGES ON USER NAME SPACE */
|
||||
|
||||
36
data/push.c
36
data/push.c
@@ -33,6 +33,7 @@ b4_use_push_for_pull_if([
|
||||
])])
|
||||
|
||||
m4_include(b4_pkgdatadir/[c.m4])
|
||||
b4_check_percent_code_qualifiers([[requires]], [[provides]], [[top]])
|
||||
|
||||
## ---------------- ##
|
||||
## Default values. ##
|
||||
@@ -160,6 +161,9 @@ b4_copyright([Skeleton implementation for Bison's Yacc-like parsers in C],dnl '
|
||||
USER NAME SPACE" below. */
|
||||
|
||||
]b4_identification
|
||||
m4_ifdef([b4_percent_code_top],
|
||||
[[/* Copy the %code "top" blocks. */
|
||||
]b4_user_code([b4_percent_code_top])])[]dnl
|
||||
m4_if(b4_prefix, [yy], [],
|
||||
[[/* Substitute the variable and function names. */
|
||||
]b4_pull_if([[#define yyparse ]b4_prefix[parse
|
||||
@@ -197,9 +201,9 @@ m4_if(b4_prefix, [yy], [],
|
||||
# define YYTOKEN_TABLE ]b4_token_table[
|
||||
#endif
|
||||
|
||||
]m4_ifdef([b4_requires],
|
||||
[[/* Copy the %requires blocks. */
|
||||
]b4_user_requires])[]dnl
|
||||
]m4_ifdef([b4_percent_code_requires],
|
||||
[[/* Copy the %code "requires" blocks. */
|
||||
]b4_user_code([b4_percent_code_requires])])[]dnl
|
||||
|
||||
b4_token_enums_defines(b4_tokens)[
|
||||
|
||||
@@ -250,14 +254,18 @@ b4_c_function_decl([[yypstate_delete]], [[void]],
|
||||
[[[yypstate *yyps]], [[yyps]]])[
|
||||
#endif
|
||||
]])
|
||||
m4_ifdef([b4_provides],
|
||||
[[/* Copy the %provides blocks. */
|
||||
]b4_user_provides])[]dnl
|
||||
m4_ifdef([b4_percent_code_provides],
|
||||
[[/* Copy the %code "provides" blocks. */
|
||||
]b4_user_code([b4_percent_code_provides])])[]dnl
|
||||
|
||||
[/* Copy the second part of user declarations. */
|
||||
]b4_user_post_prologue[
|
||||
]b4_user_post_prologue
|
||||
m4_ifdef([b4_percent_code],
|
||||
[[/* Copy the unqualified %code blocks. */
|
||||
]b4_user_code([b4_percent_code])
|
||||
])[]dnl
|
||||
|
||||
#ifdef short
|
||||
[#ifdef short
|
||||
# undef short
|
||||
#endif
|
||||
|
||||
@@ -1655,9 +1663,9 @@ b4_defines_if(
|
||||
b4_copyright([Skeleton interface for Bison's Yacc-like parsers in C],dnl '
|
||||
[1984, 1989, 1990, 2000, 2001, 2002, 2003, 2004, 2005, 2006])
|
||||
|
||||
m4_ifdef([b4_requires],
|
||||
[[/* Copy the %requires blocks. */
|
||||
]b4_user_requires])[]dnl
|
||||
m4_ifdef([b4_percent_code_requires],
|
||||
[[/* Copy the %code "requires" blocks. */
|
||||
]b4_user_code([b4_percent_code_requires])])[]dnl
|
||||
|
||||
b4_token_enums_defines(b4_tokens)
|
||||
|
||||
@@ -1714,7 +1722,7 @@ b4_c_function_decl([b4_prefix[pstate_delete]], [[void]],
|
||||
[[b4_prefix[pstate *yyps]], [[yyps]]])[
|
||||
#endif
|
||||
]])
|
||||
m4_ifdef([b4_provides],
|
||||
[[/* Copy the %provides blocks. */
|
||||
]b4_user_provides])[]
|
||||
m4_ifdef([b4_percent_code_provides],
|
||||
[[/* Copy the %code "provides" blocks. */
|
||||
]b4_user_code([b4_percent_code_provides])])[]
|
||||
])dnl b4_defines_if
|
||||
|
||||
36
data/yacc.c
36
data/yacc.c
@@ -24,6 +24,7 @@ m4_divert(-1) -*- C -*-
|
||||
b4_use_push_for_pull_if([m4_include(b4_pkgdatadir/[push.c])m4_exit])
|
||||
|
||||
m4_include(b4_pkgdatadir/[c.m4])
|
||||
b4_check_percent_code_qualifiers([[requires]], [[provides]], [[top]])
|
||||
|
||||
## ---------------- ##
|
||||
## Default values. ##
|
||||
@@ -152,6 +153,9 @@ b4_copyright([Skeleton implementation for Bison's Yacc-like parsers in C],dnl '
|
||||
USER NAME SPACE" below. */
|
||||
|
||||
]b4_identification
|
||||
m4_ifdef([b4_percent_code_top],
|
||||
[[/* Copy the %code "top" blocks. */
|
||||
]b4_user_code([b4_percent_code_top])])[]dnl
|
||||
m4_if(b4_prefix, [yy], [],
|
||||
[/* Substitute the variable and function names. */
|
||||
#define yyparse b4_prefix[]parse
|
||||
@@ -184,9 +188,9 @@ b4_locations_if([#define yylloc b4_prefix[]lloc])])[
|
||||
# define YYTOKEN_TABLE ]b4_token_table[
|
||||
#endif
|
||||
|
||||
]m4_ifdef([b4_requires],
|
||||
[[/* Copy the %requires blocks. */
|
||||
]b4_user_requires])[]dnl
|
||||
]m4_ifdef([b4_percent_code_requires],
|
||||
[[/* Copy the %code "requires" blocks. */
|
||||
]b4_user_code([b4_percent_code_requires])])[]dnl
|
||||
|
||||
b4_token_enums_defines(b4_tokens)[
|
||||
|
||||
@@ -216,14 +220,18 @@ typedef struct YYLTYPE
|
||||
# define YYLTYPE_IS_TRIVIAL 1
|
||||
#endif])
|
||||
|
||||
m4_ifdef([b4_provides],
|
||||
[[/* Copy the %provides blocks. */
|
||||
]b4_user_provides])[]dnl
|
||||
m4_ifdef([b4_percent_code_provides],
|
||||
[[/* Copy the %code "provides" blocks. */
|
||||
]b4_user_code([b4_percent_code_provides])])[]dnl
|
||||
|
||||
[/* Copy the second part of user declarations. */
|
||||
]b4_user_post_prologue[
|
||||
]b4_user_post_prologue
|
||||
m4_ifdef([b4_percent_code],
|
||||
[[/* Copy the unqualified %code blocks. */
|
||||
]b4_user_code([b4_percent_code])
|
||||
])[]dnl
|
||||
|
||||
#ifdef short
|
||||
[#ifdef short
|
||||
# undef short
|
||||
#endif
|
||||
|
||||
@@ -1492,9 +1500,9 @@ b4_defines_if(
|
||||
b4_copyright([Skeleton interface for Bison's Yacc-like parsers in C],dnl '
|
||||
[1984, 1989, 1990, 2000, 2001, 2002, 2003, 2004, 2005, 2006])
|
||||
|
||||
m4_ifdef([b4_requires],
|
||||
[[/* Copy the %requires blocks. */
|
||||
]b4_user_requires])[]dnl
|
||||
m4_ifdef([b4_percent_code_requires],
|
||||
[[/* Copy the %code "requires" blocks. */
|
||||
]b4_user_code([b4_percent_code_requires])])[]dnl
|
||||
|
||||
b4_token_enums_defines(b4_tokens)
|
||||
|
||||
@@ -1532,7 +1540,7 @@ typedef struct YYLTYPE
|
||||
[extern YYLTYPE b4_prefix[]lloc;])
|
||||
)dnl b4_locations_if
|
||||
|
||||
m4_ifdef([b4_provides],
|
||||
[[/* Copy the %provides blocks. */
|
||||
]b4_user_provides])[]
|
||||
m4_ifdef([b4_percent_code_provides],
|
||||
[[/* Copy the %code "provides" blocks. */
|
||||
]b4_user_code([b4_percent_code_provides])])[]
|
||||
])dnl b4_defines_if
|
||||
|
||||
Reference in New Issue
Block a user