logological / gpp

GPP, a generic preprocessor
https://logological.org/gpp
GNU Lesser General Public License v3.0
192 stars 33 forks source link

#mode preservelf does not seem to work #56

Open ptsl opened 2 years ago

ptsl commented 2 years ago

I have the following test file:

#mode preservelf off
#mode user "$" "$" "{" "}{" "}$" "{" "}" "@" "~"
#mode meta "$" "$\w\n" "{" "}{" "}$\w\n" "{" "}"
$define{macro}{xyzzy}$
$macro$

Depending on the value of preservelf, the gpp outputs:

-with preservelf off-

\n
\n
\n
xyzzy\n

-with preservelf on-

\n
\n
\n
\n
xyzzy\n

I'm not sure if this is a bug or an omission on my side, but I'd like gpp to output only a single line (xyzzy\n).

logological commented 2 years ago

On checking the source code, it seems the problem occurs because any invocation of the mode meta-macro assigns the preservelffield to true (gpp.c:2494). I agree that this seems to be a bug, and simply deleting the assignment does result in the expected behaviour for your examples, though it's not yet clear to me whether simply deleting that assignment might introduce further bugs. If any such bugs might be introduced, I suspect that they will affect GPP's handling of C-style strings, since the assignment occurs in that part of the code. Further testing would be appropriate here…

ptsl commented 2 years ago

Dear Tristan,

thank you for taking the time to check the issue. This "guerilla" setting of a public flag seems suspect; explicit is better than implicit. Do you think that Mr. Denis Auroux would be willing to comment?

Best regards, Peter

logological commented 2 years ago

Denis hasn't been involved in GPP development for over 15 years and so I'm loath to bother him with this issue. I think it could be solved by writing a few test cases apply the -n option, mode preservelf, and C-style strings in various combinations, and then seeing if the output remains sensible. If you'd like to do so yourself, I'd be glad to check over the tests and the results. Otherwise, I will add this to my own to-do list.

ptsl commented 2 years ago

Dear Tristan, I do not dare to write a set of tests, as this was my first encounter with gpp. If you have the capacity, I will appreciate if you do it yourself.

I highly appreciate your work and thank you for the effort you put in gpp. Peter