bison-patches
[Top][All Lists]
Advanced

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

Re: [WIP PATCH for Dlang support] d: token constructors


From: Akim Demaille
Subject: Re: [WIP PATCH for Dlang support] d: token constructors
Date: Wed, 20 Jan 2021 07:08:46 +0100

Hi Adela,

> Le 19 janv. 2021 à 23:54, Adela Vais <adela.vais99@gmail.com> a écrit :
> 
> Hello,
> 
> I need some help with the patches I am writing.
> I talked today with Akim and I am sending the WIP patches I have as 
> attachments. If it is easier, here is a Github link [1].
> 
> Thank you, Akim, in advance, for your help. 

Could you please provide a branch where the example is using variants?  I know 
it will fail, but that's the point: I'd like to have exactly the problem to 
solve.

Thanks in advance!

PS/  Please, *all* the macros in tests/ should be named AT_*.  And it should 
not be very hard to fuse these two macros:

# YYLEX_RETURN_WITH_VALUE
m4_define([YYLEX_RETURN_WITH_VALUE],
[AT_TOKEN_CTOR_IF([[return Symbol.]AT_TOKEN_PREFIX[$1]($2 AT_LOCATION_IF([[, 
location]])[);]],
                  [[return Symbol(TokenKind.]AT_TOKEN_PREFIX[$1, 
$2]AT_LOCATION_IF([[, location]])[);]])]
)

# YYLEX_RETURN_WITHOUT_VALUE
m4_define([YYLEX_RETURN_WITHOUT_VALUE],
[AT_TOKEN_CTOR_IF([[return 
Symbol.]AT_TOKEN_PREFIX[$1](AT_LOCATION_IF([[location]])[);]],
                  [[return 
Symbol(TokenKind.]AT_TOKEN_PREFIX[$1]AT_LOCATION_IF([[, location]])[);]])]
)

into one.  Untested, but that's the idea:


# AT_YYLEX_RETURN
# ---------------
m4_define([AT_YYLEX_RETURN],
[return dnl
AT_TOKEN_CTOR_IF(
  [[Symbol.]AT_TOKEN_PREFIX[$1](m4_ifval([$2], [$2 ])AT_LOCATION_IF([[, 
location]])[);]],
  [[Symbol(TokenKind.]AT_TOKEN_PREFIX[$1[]m4_ifval([$2], [, 
$2])]AT_LOCATION_IF([[, location]])[);]])
])


In case you're wondering why "$1[]m4_ifval" instead of "$1m4_ifval", it's to 
avoid that tokens get pasted together.  If $1 is "foo", then "$1my_ifval" 
yields "foom4_ifval", which is not a macro, so m4 will just paste that in the 
output.  With the '[]' m4 will see 'foo[]m4_ifval', and process first 'foo', 
then '[]' (giving nothing) and finally 'm4_ifval(...)'.





reply via email to

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