Hello Akim, În mie., 20 ian. 2021 la 08:08, Akim Demaille <[email protected]> a scris:
> Hi Adela, > > > Le 19 janv. 2021 à 23:54, Adela Vais <[email protected]> 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. > I added another commit on the branch: https://github.com/adelavais/bison/tree/token-constructors-squash > 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(...)'. > > I tried to combine them, and I did not put the '[]'. That explains why it failed. I will modify the function for the final version of the patch. Thank you again, Akim. Adela
