-
Notifications
You must be signed in to change notification settings - Fork 169
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Example is not C #484
Comments
I noticed this years ago and thought little of it because re2c is a preprocessor and doesn't really care if the input is C or C++. It seemed like it was good to make it clear to the reader that either syntax would be fine in context, but maybe it needs to be more explicit? I do agree that more modern C++ syntax is a good idea though. |
@pmetzger the repository contains the transpilation as C source code with the .c suffix, e.g. https://github.com/skvadrik/re2c/blob/f2395c299886cfc5639f841f6445ab9ad0fa26f9/examples/c/conditions/parse_u32_conditions.c so that is another confusion. On the front page it says "User manual (C)" and so I wouldn't expect C++ examples. Something needs to be fixed to make this presentation consistent, obviously it's not important though. |
Thank for reporting @createyourpersonalaccount. The mismatch is caused by the fact that re2c has one backend for both C and C++, and the testing scripts / manual generators / everything assumes that there's one file extension per language (and it's a reasonable assumption for most languages). You make a valid point, but so far it seemed enough to place a note on the manual page https://re2c.org/manual/manual_c.html saying
I should change this to say C/C++ (it's not a trivial change, as the manuals are autogenerated from one language-independent source, and the change requires regenerating them and inspecting the diffs). I'll address this later when I update all docs before the next release. |
Thanks for the report indeed.
Imo it makes perfect sense to keep the generator for both C and C++ the
same as long as feasible. Nonetheless, we could:
a) call that out clearly in the documentation,
b) separate the examples into C and C++ respectively, and
c) as pointed out in the original report the template is not even
necessary, so we could also change the example to C.
For b) I assume here that we go from extension to backend somewhere in our
testing. That simply needs to have the ability to map multiple extensions
to the same backend. Then we can rename the C++ examples into `.cpp` and
keep the C ones as `.c`. This will also work for other languages with
multiple extensions or cases where multiple languages share a single
backends.
my 2c
…On Sun, Aug 11, 2024 at 6:31 PM Ulya Trofimovich ***@***.***> wrote:
Thank for reporting @createyourpersonalaccount
<https://github.com/createyourpersonalaccount>. The mismatch is caused by
the fact that re2c has one backend for both C and C++, and the testing
scripts / manual generators / everything assumes that there's one file
extension per language (and it's a reasonable assumption for most
languages). You make a valid point, but so far it seemed enough to place a
note on the manual page https://re2c.org/manual/manual_c.html saying Note:
examples are in C++ (but can be easily adapted to C).
On the front page it says "User manual (C)
<https://re2c.org/manual/manual_c.html>" and so I wouldn't expect C++
examples.
I should change this to say C/C++ (it's not a trivial change, as the
manuals are autogenerated from one language-independent source, and the
change requires regenerating them and inspecting the diffs). I'll address
this later when I update all docs before the next release.
—
Reply to this email directly, view it on GitHub
<#484 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/ABQ7NSJUJMUGO452GSDYA5DZQ6GVBAVCNFSM6AAAAABMJT6LYKVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDEOBSHAYTGMRQGQ>
.
You are receiving this because you are subscribed to this thread.Message
ID: ***@***.***>
|
Let me say that I personally like the examples shown and if they become too decoupled (i.e. in separate pages) I think that would be a net loss to the presentation. I'm not sure if that was implied somewhere in the suggestions above, just a remark. I totally missed the note at the top of the page. I did not realize all the examples are in C++, because the first few are valid C. Re2c is a very nice tool, I don't think these quirks are important to waste your sleep over them, using re2c with lemon was certainly less painful than trying to figure out flex/bison with reentrancy. I wrote a small project in CMake here https://github.com/createyourpersonalaccount/lemon_example for demonstration purposes because I noticed that I couldn't find a complete example online combining the two (lemon and re2c). |
Nice. Having that combination work and documented in the open is very
valuable. There have been rumors for way over a decade that the combo is in
fact the best combo. But I haven't seen any open documentation or
discussions.
…On Sun, Aug 11, 2024, 22:10 Nikolaos Chatzikonstantinou < ***@***.***> wrote:
Let me say that I personally like the examples shown and if they become
too decoupled (i.e. in separate pages) I think that would be a net loss to
the presentation. I'm not sure if that was implied somewhere in the
suggestions above, just a remark.
I totally missed the note at the top of the page. I did not realize *all*
the examples are in C++, because the first few are valid C.
Re2c is a very nice tool, I don't think these quirks are important to
waste your sleep over them, using re2c with lemon was certainly less
painful than trying to figure out flex/bison with reentrancy. I wrote a
small project in CMake here
https://github.com/createyourpersonalaccount/lemon_example for
demonstration purposes because I noticed that I couldn't find a complete
example online combining the two (lemon and re2c).
—
Reply to this email directly, view it on GitHub
<#484 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/ABQ7NSP7HHNQCWBTUN7TYZTZQ7ALLAVCNFSM6AAAAABMJT6LYKVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDEOBSHA3TKMRUG4>
.
You are receiving this because you commented.Message ID:
***@***.***>
|
This example https://github.com/skvadrik/re2c/blob/f2395c299886cfc5639f841f6445ab9ad0fa26f9/examples/c/conditions/parse_u32_conditions.re is transpiled as C but it contains C++ templates.
It can be trivially translated into C e.g. with
and if it stays as C++ the template is excessive for this simple example and should probably be converted to the function above. If C++ stays, the deprecated C headers should be converted, e.g.
<limits.h>
should be converted to<climits>
.The text was updated successfully, but these errors were encountered: