bison-patches
[Top][All Lists]
Advanced

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

Re: Push parsing for java...


From: Akim Demaille
Subject: Re: Push parsing for java...
Date: Mon, 24 Sep 2012 09:26:55 +0200

Hi Dennis,

Le 23 sept. 2012 à 21:01, Dennis Heimbigner a écrit :

>> This is an unfortunate choice, as we used to be less quoted,
>> but it was decided to play it safe and consistent, and to
>> use quotation where we do not want macros to fire unexpectedly.
> 
> I think you are making a serious mistake in adding extraneous escapes.
> As far as I can tell, there are only three things that need to be
> handled with extra escaping and they all have simple solutions.
> 
> 1. Array references (e.g. x[y]); this is easily handled where they occur
>   by using extra escaping.
> 2. Commas in macro arguments; again a single level of escaping works fine.
> 3. Occurrences of e.g. $1 in test case .y files. This only occurs
>   in test cases (e.g. java.m4). This is more easily handled with
>   single escaping plus converting $1 => $[]1.
> 
> WRT #3, it seems to me that your tests cases like java.m4 are way too 
> complicated
> because of the way you chose to deal with embedded $1.  I may be missing 
> something,
> but using $[]1 and single level escaping seems to work fine (see javapush.m4)
> and is way less complicated.

I have been bitten on several occasions on this regard, and
I much prefer having something slightly more complex around
and a clear content, than the converse.

> I assume there must have been some specific situation that drove you to
> adding the extra escapes. Can you describe that use case?

I don't know how to avoid such a trick when trying to define
a macro that defines macros.  For instance, how would you
implement a function "define_swap" that takes a name, and defines
a macro of that name that would return its first two arguments
reversed?

Something like this:

changequote([, ])
define([define_swap],
[define([$1], [$[]2, $[]1])])
define_swap([swap])
swap(1, 2)

Well, I would do it this way.

changequote([, ])
define([define_swap_],
[define([$3], [$2, $1])])
define([define_swap],
[define_swap_($[1], $[2], [$1])])

define_swap([swap])
swap(1, 2)
define([A], [a])
define([B], [b])
swap([[A]], [[B]])

As I already reported, the coding style for M4 pieces used to
be more like the one you said, but it slowly migrated to the
current scheme because the authors felt better this way.  And
I can understand why: it's consistent and you don't have to wait
to be bitten by a missing level of quotation to fix your code
– even though I used to promote the style you now support.

Today we have a coding style, and there is no reason for us to
change it.  Your detailed list above shows you do know how to
program M4, so I don't take your opinion lightly; yet the point
here is more that a choice was made, and see no benefit in
changing.

It does happen that code is contributed with a more relaxed
quotation scheme, it also happens that I spot places where
the old scheme is still used, and then I fix it.  No big
deal, I can accept patches that will be normalized later,
but I won't accept patches that relax the rules where they
are properly followed.


reply via email to

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