bison-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: %define boolean variables


From: Paolo Bonzini
Subject: Re: %define boolean variables
Date: Tue, 30 Jan 2007 08:23:01 +0100
User-agent: Thunderbird 1.5.0.9 (Macintosh/20061207)


Why do you want to mimic cpp anyway?

To be more clear, I just want to mimic the common CPP idiom "#define FOO". Other common CPP idioms are "#define FOO 1" (which we support with "true" instead of 1), "#define FOO 0" (less common, as is %define with "false" instead of 0). So:

  cpp:   #define PUBLIC
  Bison: %define PUBLIC

  cpp:   #define PUBLIC 1
  Bison: %define PUBLIC "true"

  cpp:   #define PUBLIC 0
  Bison: %define PUBLIC "false"

Finally, as in cpp, the default is "false" for all other macros (but since we want warnings on unused %define, we take care of that with b4_percent_define_default). That's where my mimicking of cpp ends.

I attach an updated patch, with the indications you gave in the other message.

Paolo
2007-01-29  Paolo Bonzini  <address@hidden>

        * data/bison.m4 (b4_percent_define_flag_if): Don't treat 0 as false.
        Complain if the value does not match empty, "true" or "false".
        * data/c++.m4: Adjust default definitions of %define variables.
        * data/java.m4: Adjust default definitions of %define variables.
        * doc/bison.texinfo (%define): Adjust according to above behavior.
        * tests/input.at (Boolean %define variables): Test new behavior.

Index: data/bison.m4
===================================================================
RCS file: /sources/bison/bison/data/bison.m4,v
retrieving revision 1.15
diff -u -p -r1.15 bison.m4
--- data/bison.m4       23 Jan 2007 12:24:27 -0000      1.15
+++ data/bison.m4       30 Jan 2007 07:05:44 -0000
@@ -369,9 +369,11 @@ m4_define([b4_percent_define_ifdef],
 m4_define([b4_percent_define_flag_if],
 [b4_percent_define_ifdef([$1],
                         [m4_case(b4_percent_define_get([$1]),
-                                 [0], [$3], [false], [$3],
-                                 [$2])],
-                        [m4_fatal([invalid %define variable passed to 
b4_percent_define_flag_if: ]$1)])])
+                                 [], [$2], [true], [$2], [false], [$3],
+                                 [m4_expand_once(
+                                  [b4_complain([[invalid value for %%define 
variable `%s']], [$1])],
+                                  [[b4_percent_define_flag_if($1)]])])],
+                        [b4_fatal([[invalid %%define variable `%s' passed to 
b4_percent_define_flag_if]], [$1])])])
 
 # b4_percent_define_default(VARIABLE, DEFAULT)
 # --------------------------------------------
Index: data/c++.m4
===================================================================
RCS file: /sources/bison/bison/data/c++.m4,v
retrieving revision 1.14
diff -u -p -r1.14 c++.m4
--- data/c++.m4 23 Jan 2007 12:24:27 -0000      1.14
+++ data/c++.m4 30 Jan 2007 07:05:44 -0000
@@ -31,10 +31,10 @@ b4_percent_define_default([[parser_class
 b4_percent_define_default([[location_type]], [[location]])
 b4_percent_define_default([[filename_type]], [[std::string]])
 b4_percent_define_default([[namespace]], m4_defn([b4_prefix]))
-b4_percent_define_default([[global_tokens_and_yystype]], [[0]])
+b4_percent_define_default([[global_tokens_and_yystype]], [[false]])
 b4_percent_define_default([[define_location_comparison]],
                           [m4_if(b4_percent_define_get([[filename_type]]),
-                                 [std::string], [[1]], [[0]])])
+                                 [std::string], [[true]], [[false]])])
 
 
 # b4_token_enums(LIST-OF-PAIRS-TOKEN-NAME-TOKEN-NUMBER)
Index: data/java.m4
===================================================================
RCS file: /sources/bison/bison/data/java.m4,v
retrieving revision 1.1
diff -u -p -r1.1 java.m4
--- data/java.m4        29 Jan 2007 10:54:42 -0000      1.1
+++ data/java.m4        30 Jan 2007 07:05:44 -0000
@@ -34,13 +34,13 @@ m4_define([b4_flag_value], [b4_flag_if([
 
 # b4_public_if(TRUE, FALSE)
 # -------------------------
-b4_percent_define_default([public], 0)
+b4_percent_define_default([[public]], [[false]])
 m4_define([b4_public_if],
 [b4_percent_define_flag_if([public], [$1], [$2])])
 
 # b4_single_class_if(TRUE, FALSE)
 # -------------------------------
-b4_percent_define_default([single_class], 0)
+b4_percent_define_default([[single_class]], [[false]])
 m4_define([b4_single_class_if],
 [b4_percent_define_flag_if([single_class], [$1], [$2])])
 
Index: doc/bison.texinfo
===================================================================
RCS file: /sources/bison/bison/doc/bison.texinfo,v
retrieving revision 1.225
diff -u -p -r1.225 bison.texinfo
--- doc/bison.texinfo   29 Jan 2007 10:54:42 -0000      1.225
+++ doc/bison.texinfo   30 Jan 2007 07:05:50 -0000
@@ -4691,15 +4691,16 @@ already defined, so that the debugging f
 @end deffn
 @xref{Tracing, ,Tracing Your Parser}.
 
address@hidden {Directive} %define @var{define-variable}
address@hidden {Directive} %define @var{define-variable} @var{value}
-Define a variable to adjust Bison's behavior.
-The list of available variables and their meanings depends on the selected
-target language and/or the parser skeleton (@pxref{Decl Summary,,%language}).
-The @var{value} can be omitted for boolean variables; for
-boolean variables, the skeletons will treat a @var{value} of @samp{0}
-or @samp{false} as the boolean variable being false, and anything else
-as true.
address@hidden {Directive} %define @var{variable}
address@hidden {Directive} %define @var{variable} "@var{value}"
+Define a variable to adjust Bison's behavior.  The possible choices for
address@hidden, as well as their meanings, depends on the selected target
+language and/or the parser skeleton (@pxref{Decl Summary,,%language}).
+
+Some @var{variable}s may be used as boolean values: in this case, the
+skeleton will conventionally treat a @var{value} of @samp{false} as the
+boolean variable being false; a @var{value} of @samp{true}, or @var{value}
+being omitted altogether, will conversely define the variable as true.
 @end deffn
 
 @deffn {Directive} %defines
Index: tests/input.at
===================================================================
RCS file: /sources/bison/bison/tests/input.at,v
retrieving revision 1.76
diff -u -p -r1.76 input.at
--- tests/input.at      29 Jan 2007 10:54:42 -0000      1.76
+++ tests/input.at      30 Jan 2007 07:05:50 -0000
@@ -820,3 +820,23 @@ input.y:5.9-16: warning: %define variabl
 ]])
 
 AT_CLEANUP
+
+## --------------------------- ##
+## Boolean %define variables.  ##
+## --------------------------- ##
+
+AT_SETUP([Boolean %define variables])
+
+AT_DATA([Input.y],
+[[%language "Java"
+%define public "maybe"
+%define parser_class_name "Input"
+%%
+start: ;
+]])
+
+AT_CHECK([[bison Input.y]], [1], [],
+[[Input.y: invalid value for %define variable `public'
+]])
+
+AT_CLEANUP

reply via email to

[Prev in Thread] Current Thread [Next in Thread]