bison-patches
[Top][All Lists]
Advanced

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

Re: [PATCH] More %define/%code encapsulation


From: Paolo Bonzini
Subject: Re: [PATCH] More %define/%code encapsulation
Date: Wed, 17 Jan 2007 07:41:49 +0100
User-agent: Thunderbird 1.5.0.9 (Macintosh/20061207)

This patch defines the conditional macros for %define and %code.

Just out of curiosity, are you actually using all these new macros, or are you just anticipating that someone might find them useful?

I'm mostly anticipating the need, but I have use cases.

- for _if, I have "%define single_class" in Java if you want lexer and parser to reside in the same class. And actually it would be better to extend it to accept "true" or "false" too, hence the _case.

- for _ifval, I'm thinking of

m4_define([b4_class_name], [b4_get_percent_code([package])dnl
b4_get_percent_code_ifval([package], [.])$1])

I ended up not adding the _ifdef's in my previous patch because I wasn't sure what I'd ever use them for. Thinking about it now, I guess some skeletons might want to require certain %define's or %code's and warn/complain when the grammar doesn't define them. Is that what you're thinking? Anything else?

- for _ifdef, that's it.

- for _case, I'm thinking of a multi-value flag.

+# b4_percent_define_ifdef(VARIABLE, IF-TRUE, IF-FALSE)
+# ----------------------------------------------------
+# If the %define variable VARIABLE is defined, expand IF-TRUE, else expand
+# IF-EMPTY.  Also, record the skeleton's usage of VARIABLE by defining

s/IF-EMPTY/IF-FALSE/

Yes, my bad.

+# b4_percent_define_if(VARIABLE, IF-TRUE, IF-FALSE)
+# -------------------------------------------------
+# If the %define variable VARIABLE is defined to anything but 0, evaluate 
IF-TRUE.
+# If it is defined to 0, evaluate IF-FALSE.

In my experience, an empty string also means false.

Except that I wanted to make the default of %define become empty rather than 1 in a follow-up patch (disconnected from the Java skeleton).

+# b4_percent_define_case(VARIABLE, [VALUE1, THEN1]..., ELSE)
+# ----------------------------------------------------------
+# If the %define variable VARIABLE is defined to VALUE1, evaluate THEN1, and
+# so on.  If none of the values match, expaand ELSE.

Isn't the ELSE argument optional? In the other macros, isn't IF-FALSE optional?

Right.

Paolo




reply via email to

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