[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH] overquoting in implementation of %code and %defines
From: |
Joel E. Denny |
Subject: |
Re: [PATCH] overquoting in implementation of %code and %defines |
Date: |
Sat, 13 Jan 2007 14:29:50 -0500 (EST) |
On Sat, 13 Jan 2007, Paolo Bonzini wrote:
> > > Here's my version of your patch plus the `.' fix. What do you think?
>
> That's fine, except that I'd turn
>
> m4_pushdef([b4_check_user_names_wrap]
>
> into a m4_define.
That's fine.
> As for the default issue, I was doing something like this in the Java
> skeleton:
>
> m4_define([b4_prefix], [b4_get_percent_define([[prefix]], [[YY]])])
I don't want to encourage skeleton authors to define such an abbreviation
just in order to define a variable's default value. It can suppress
helpful warnings about a variable that's sometimes unused. In other
words, a skeleton should usually only use b4_get_percent_define([[NAME]])
where NAME's value will actually affect the output.
> since this does not work:
>
> m4_define([b4_prefix], [b4_get_percent_define([[prefix]])])
> m4_define_default([b4_prefix], [[YY]])])
This should work:
m4_define_default([b4_percent_define_prefix], [[YY]])
And when you're sure prefix is always used:
m4_define([b4_prefix], [b4_get_percent_define([[prefix]])])
Here's an updated patch with notes about the above issues in the
b4_get_percent_define and b4_get_percent_code documentation. Does this
look ok to you?
Index: ChangeLog
===================================================================
RCS file: /sources/bison/bison/ChangeLog,v
retrieving revision 1.1660
diff -p -u -r1.1660 ChangeLog
--- ChangeLog 10 Jan 2007 03:47:50 -0000 1.1660
+++ ChangeLog 13 Jan 2007 19:24:19 -0000
@@ -1,3 +1,16 @@
+2007-01-13 Paolo Bonzini <address@hidden>
+ and Joel E. Denny <address@hidden>
+
+ * 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): Update. Also, use m4_indir so that %define
+ variable names can contain `.', which is allowed by the grammar parser.
+ Extend documentation to talk about defining defaults and abbreviations.
+ (b4_get_percent_code): Likewise.
+ (m4_wrap): Update wrapped code, and fix some underquoting.
+ (b4_check_user_names_wrap): Define outside the m4_wrap.
+
2007-01-09 Joel E. Denny <address@hidden>
* tests/glr-regression.at: Use AT_PARSER_CHECK rather than AT_CHECK to
Index: data/bison.m4
===================================================================
RCS file: /sources/bison/bison/data/bison.m4,v
retrieving revision 1.11
diff -p -u -r1.11 bison.m4
--- data/bison.m4 9 Jan 2007 05:24:11 -0000 1.11
+++ data/bison.m4 13 Jan 2007 19:24:19 -0000
@@ -285,13 +285,14 @@ b4_define_user_code([pre_prologue])
b4_define_user_code([stype])
-# b4_check_user_names(WHAT, USER-LIST, SKELETON-LIST)
-# ---------------------------------------------------
+# b4_check_user_names(WHAT, USER-LIST, SKELETON-NAMESPACE)
+# --------------------------------------------------------
# Warn if any name of type WHAT is used by the user (as recorded in USER-LIST)
-# but is not used by the skeleton (as recorded in SKELETON-LIST).
+# but is not used by the skeleton (as recorded by macros in the namespace
+# SKELETON-NAMESPACE).
#
# USER-LIST must expand to a list specifying all grammar occurrences of all
-# names of type WHAT. Each item in the list is a triplet specifying one
+# names of type WHAT. Each item in the list must be a triplet specifying one
# occurrence: name, start boundary, and end boundary. Empty string names are
# fine. An empty list is fine.
#
@@ -303,37 +304,32 @@ b4_define_user_code([stype])
# [[[[bar]], [[parser.y:5.7]], [[parser.y:5.16]]]],
# [[[[baz]], [[parser.y:8.7]], [[parser.y:8.16]]]]]])
#
-# SKELETON-LIST must expand to a list specifying all names of type WHAT that
-# are used by the skeleton. Multiple occurrences of the same name are fine.
-# Empty string names are fine, but it would be ugly for a Bison skeleton to
-# actually use one. An empty list is fine.
+# The macro SKELETON-NAMESPACE(bar) must be defined iff the name bar of type
+# WHAT is used in the skeleton. Empty string names are fine, but it would be
+# ugly for a Bison skeleton to actually use one.
#
-# For example, to define b4_skeleton_foo_names to be used for SKELETON-LIST
-# with two names and with correct quoting:
+# For example, to use b4_skeleton_foo_names for SKELETON-NAMESPACE and define
+# that the names bar and baz are used in the skeleton:
#
-# m4_define([b4_skeleton_foo_names],
-# [[[[bar]], [[baz]]]])
+# m4_define([b4_skeleton_foo_names(bar)])
+# m4_define([b4_skeleton_foo_names(baz)])
#
# To invoke b4_check_user_names with TYPE foo, with USER-LIST
-# b4_user_foo_names, with SKELETON-LIST b4_skeleton_foo_names, and with correct
-# quoting:
+# b4_user_foo_names, with SKELETON-NAMESPACE b4_skeleton_foo_names, and with
+# correct quoting:
#
-# b4_check_user_names([[foo]], [b4_user_foo_names], [b4_skeleton_foo_names])
+# b4_check_user_names([[foo]], [b4_user_foo_names],
+# [[b4_skeleton_foo_names]])
m4_define([b4_check_user_names],
[m4_foreach([b4_occurrence], $2,
[m4_pushdef([b4_occurrence], b4_occurrence)dnl
m4_pushdef([b4_user_name], m4_car(b4_occurrence))dnl
m4_pushdef([b4_start], m4_car(m4_shift(b4_occurrence)))dnl
m4_pushdef([b4_end], m4_shift(m4_shift(b4_occurrence)))dnl
-m4_pushdef([b4_found], [[0]])dnl
-m4_foreach([b4_skeleton_name], $3,
- [m4_if(m4_quote(b4_user_name),
- m4_quote(b4_skeleton_name),
- [m4_define([b4_found], [[1]])])])dnl
-m4_if(b4_found, [0], [b4_warn_at([b4_start], [b4_end],
- [[%s `%s' is not used]],
- [$1], [b4_user_name])])[]dnl
-m4_popdef([b4_found])dnl
+m4_ifndef($3[(]m4_quote(b4_user_name)[)],
+ [b4_warn_at([b4_start], [b4_end],
+ [[%s `%s' is not used]],
+ [$1], [b4_user_name])])[]dnl
m4_popdef([b4_occurrence])dnl
m4_popdef([b4_user_name])dnl
m4_popdef([b4_start])dnl
@@ -341,28 +337,50 @@ m4_popdef([b4_end])dnl
])])
# b4_get_percent_define(VARIABLE)
-# --------------------------------
-# If the %define variable VARIABLE is defined, emit it. Also, record VARIABLE
-# in b4_skeleton_percent_define_variables.
+# -------------------------------
+# If the %define variable VARIABLE is defined, emit it. Also, record the
+# skeleton's usage of VARIABLE by defining
+# b4_skeleton_percent_define_variables(VARIABLE).
+#
+# For example, to define a default value for the variable foo and then retrieve
+# the resulting value:
+#
+# m4_define_default([b4_percent_define_foo], [[default value for foo]])
+# b4_get_percent_define([[foo]])
+#
+# Defining an abbreviation like the following may suppress a helpful warning
+# about foo being defined in the grammar file when it will have no effect on
+# the output:
+#
+# m4_define([b4_foo], [b4_get_percent_define_foo([[foo]])])
+#
+# That is, a skeleton should only invoke b4_get_percent_define_foo([[foo]])
+# when foo will always affect the output. Usually this means a skeleton should
+# invoke it only *where* it will affect the output.
m4_define([b4_get_percent_define],
-[m4_append([b4_skeleton_percent_define_variables], [[$1]], [[, ]])dnl
-m4_ifdef([b4_percent_define_]$1, [b4_percent_define_]$1)])
+[m4_define([b4_skeleton_percent_define_variables(]$1[)])dnl
+m4_ifdef([b4_percent_define_]$1, [m4_indir([b4_percent_define_]$1)])])
# b4_get_percent_code([QUALIFIER])
# --------------------------------
# If any %code blocks for QUALIFIER are defined, emit them beginning with a
# comment and ending with synclines and a newline. If QUALIFIER is not
# specified (thus, b4_get_percent_code is invoked without parens), do this for
-# the unqualified %code blocks. Also, record QUALIFIER (if specified) in
-# b4_skeleton_percent_code_qualifiers.
+# the unqualified %code blocks. Also, record the skeleton's usage of QUALIFIER
+# (if specified) by defining b4_skeleton_percent_code_qualifiers(VARIABLE).
+#
+# See the b4_get_percent_define documentation for a discussion about defining
+# defaults and abbreviations. In place of the example b4_percent_define_foo,
+# use b4_percent_code_foo. For the unqualified %code blocks, use
+# b4_percent_code.
m4_define([b4_get_percent_code],
[m4_pushdef([b4_macro_name], [[b4_percent_code]]m4_if([$#], [1], [[[_]$1]]))dnl
-m4_if([$#], [1],
- [m4_append([b4_skeleton_percent_code_qualifiers], [[$1]], [[, ]])])dnl
+m4_if([$#], [1], [m4_define([b4_skeleton_percent_code_qualifiers(]$1[)])])dnl
m4_ifdef(b4_macro_name,
[b4_comment([m4_if([$#], [0], [[Unqualified %code]],
[[%code "]$1["]])[ blocks.]])
-b4_user_code(b4_macro_name)])dnl
+b4_user_code([m4_indir(b4_macro_name)])
+])dnl
m4_popdef([b4_macro_name])])
@@ -371,21 +389,13 @@ m4_popdef([b4_macro_name])])
## %define variables and %code qualifiers were used. ##
## --------------------------------------------------------- ##
-m4_wrap([
-m4_pushdef([b4_check_user_names_wrap],
-[m4_ifdef([b4_skeleton_percent_$1],
- [m4_define([b4_skeleton_percent_$1],
- m4_dquote(m4_dquote(b4_skeleton_percent_$1)))],
- [m4_define([b4_skeleton_percent_$1], [[]])])
-
-m4_ifdef([b4_user_percent_$1],
- [b4_check_user_names([$2],
- [b4_user_percent_$1],
- [b4_skeleton_percent_$1])])
-])
-
-b4_check_user_names_wrap([define_variables], [[%define variable]])
-b4_check_user_names_wrap([code_qualifiers], [[%code qualifier]])
+m4_define([b4_check_user_names_wrap],
+[m4_ifdef([b4_user_percent_]$1,
+ [b4_check_user_names([$2],
+ [b4_user_percent_]$1,
+ [[b4_skeleton_percent_]$1])])])
-m4_popdef([b4_check_user_names_wrap])
+m4_wrap([
+b4_check_user_names_wrap([[define_variables]], [[%define variable]])
+b4_check_user_names_wrap([[code_qualifiers]], [[%code qualifier]])
])
- [PATCH] overquoting in implementation of %code and %defines, Paolo Bonzini, 2007/01/09
- Message not available
- Message not available
- Message not available
- Re: [PATCH] overquoting in implementation of %code and %defines, Joel E. Denny, 2007/01/12
- Re: [PATCH] overquoting in implementation of %code and %defines, Paolo Bonzini, 2007/01/13
- Re: [PATCH] overquoting in implementation of %code and %defines,
Joel E. Denny <=
- Re: [PATCH] overquoting in implementation of %code and %defines, Paolo Bonzini, 2007/01/14
- Re: [PATCH] overquoting in implementation of %code and %defines, Joel E. Denny, 2007/01/14
- Re: [PATCH] overquoting in implementation of %code and %defines, Paolo Bonzini, 2007/01/15
- Re: [PATCH] overquoting in implementation of %code and %defines, Joel E. Denny, 2007/01/15
- Re: [PATCH] overquoting in implementation of %code and %defines, Paolo Bonzini, 2007/01/15
- Re: [PATCH] overquoting in implementation of %code and %defines, Joel E. Denny, 2007/01/15
- Re: [PATCH] overquoting in implementation of %code and %defines, Paolo Bonzini, 2007/01/15
- Re: [PATCH] overquoting in implementation of %code and %defines, Joel E. Denny, 2007/01/15
- Re: [PATCH] overquoting in implementation of %code and %defines, Paolo Bonzini, 2007/01/15
- Re: [PATCH] overquoting in implementation of %code and %defines, Joel E. Denny, 2007/01/15