-
Notifications
You must be signed in to change notification settings - Fork 173
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
Online playground ? #434
Comments
That's super cool! I'd love to see it work. I don't know much about Lua, but I hope that sources list can be auto generated somehow so that your script is easily updated when files are removed/added. |
Would be nice to have code generation for |
Here is my attempt to manually port (not yet runable)
|
And here is
|
I noticed that this piece of code is repeated a lot only changing the last line goto destination:
|
@mingodad I suggest starting with simpler examples if you want to experiment with a JS backend. But more importantly, I'm leaning towards a different approach for adding new backends in re2c. Not the way we did it with C/Rust/Go, but instead, there should be a way to write a backend "syntax file" with some configurations, and re2c should be able to generate code using those configurations. This is much more scalable than hardcoding every new backend, and much less demanding in terms of documentation (as only one config file per language will be needed). People would be able to use local syntax files for whatever language they need, or upstream them with some examples to prove that they are working. I actually plan to rework the early Dlang patch done by @abenedic (8df0ed6) this way. I think merging that early support straight into master was premature; it should have been on a branch until the full backend is ready. Dlang and JS support will only be added after implementing that "syntax file" logic (and other backends should be rewritten using this logic as well, without breaking backwards compatibility). I hope to start working on it approximately in a month time, and I'm not sure how long it will take: it's difficult to decide on an optimal set of configurations that would accommodate many languages, and it is generally a lot of work. I'm sorry that it blocks your work, but this is needed to keep re2c lean and maintainable. It may be tempting to add new backends, but if they have very few users and take a lot of effort to maintain, this is not a good solution. |
Thank you for reply ! |
Not quite, files like https://github.com/adrian-thurston/ragel/blob/master/src/host-js/rlparse.lm are language frontend parsers, and they are part of the Ragel source files (codegen definitions are in https://github.com/adrian-thurston/ragel/blob/master/src/host-js/main.cc which is also a source file). What I want is more dynamic: a syntax file should be read at runtime, so that one could add a new language just by writing a new file (no changes to source code needed, provided that the set of configurations in syntax file is sufficient for the new language). But thanks for the link, it is interesting. It may be a good place to look if we want to add language-specific lexers to fix #429. It also raises an interesting point that if we want languge-specific frontends, they may also need some configurations. |
@mingodad,
Then, it should be possible to run re2c fully on the client side. I guess it is possible to create something similar to Compiler Explorer: |
BTW code generation into JS is supported now (set |
This is great. Thank you. I have created a very ugly prototype re2c-web-playground If someone wants to help, please let me know. |
Thanks @PolarGoose! It looks nice to me, just missing an edit box to enter user's options.
Same here. :) I think it would be best to add re2c to https://github.com/compiler-explorer/compiler-explorer. It is well known and it has a good UI: https://godbolt.org.
It looks good and simple. But compiler explorer UI is a bit more suited to re2c as it is, after all, a compiler (having a menu for different versions, and an input for options is very useful). Besides, if we upstream re2c support it will be easier to maintain. |
I've tried https://polargoose.github.io/re2c-web-playground with this:
To find out that the
|
re2js tells you that you are missing an option. Conditions require |
re2c-web-playground runs
You can change the source of the HTML page to add extra parameters. |
I'm getting this error on a fresh full reload (Chromium Linux, but using Firefox it works fine ):
|
Would be nice to add a dropdown/select to load several examples. |
This comment was marked as resolved.
This comment was marked as resolved.
I noticed that when generating a lexer for |
What output exactly do you mean, the code generated by re2c? Which options did you use?
No, it cannot. |
I mean the code generated by re2c. |
After your last question and my answer I did a test again and it seems that I've got confused or something changed since I did it at that time because now I get this output:
|
JS backend does not support |
You are right ! I didn't added the
|
Sorry for the inconvenience. I use the Edge browser to test. I tried to cheat a bit and compile the code with |
Thank you @PolarGoose ! |
@PolarGoose I see you've also added graphviz output, great work! |
Hello @PolarGoose ! |
I think it is possible to just copy the source code of the site and create a GitHub action that will publish it on Github Pages. Let me look into that. |
Note that skvadrik.github.io/re2c (the |
Yes, a bit unorthodox :) |
Next thing on the wish-list for playground is a "share" button that would allow us one to share a re2c snippet by URL. I have no idea how to add it though. :) |
GraphvizOnline has a share button. They just generate a link with the code inside like this:
When you use this link, the code is copied and pasted into the source code editor. Let me see. I will try to implement it. |
Playground has been released in 4.0: https://re2c.org/playground, link available on the home page of https://re2c.org. It would be good to make it look better on mobile phones and tablets, so I'll keep the issue open for now. |
I made it somewhat better on the phone by using stacked layout: 59eb41b, but the font is still tiny. I'm not sure why it's fine on the website (https://re2c.org) and so tiny on the playground. What I have: What I want: |
Hacked it: f3598c8. Playground looks fine on mobile devices now, so closing the issue. |
Hello @skvadrik can't the contrast be enhanced on the playground ? |
Sure, but can you be more specific, where this low-contrast combination is? I don't think I set either green or red background anywhere (I didn't change editor/output colors at all). |
@skvadrik,
The playground web site says that it uses
Is it related to the editors' background color? I use my monitor in "Reader" mode, which makes everything a bit yellowish. |
@PolarGoose thanks!
I think just white and thin grey border should be fine. Accessibility is more important after all. @mingodad Let me know if white background looks contrast enough (I used default gihub highlighting scheme in Ace editor, hopefully it should be fine for most people).
Thanks for reminding me, I forgot to rebuild it. Updated now. |
I think it got a little better, another enhancement would be to somehow extend/overwrite the |
There is a way, we can use CSS selectors like |
Another thing I'd like to add is support of older version of re2c (at least the latest stable one), as many distros are slow to update and examples use new re2c features (so for old re2c version we'll fetch old examples). |
I thought about that. But it will add a lot of complexity. I don't think it is worth it. You don't want to get a website so complex it is hard to maintain, especially for people who are new to the project. It is not very hard. We can build several re2c.js and examples.js . But it will just make the building scripts and the code of the webpage more involved. I would say, let's not do it for now. There is also another option (wild idea): make GitHub actions build statically linked Linux, Windows, and MaxOs executables so that people don't need to depend on their distribution and can download the latest binary as a pre-build event. |
We even have a bug for this: #379. :) It wouldn't solve the problem with the examples, though. Linux users update via their package managers, they don't usually download binaries (it's inconvenient, because if you make an exception for one program, next day you'll need an exception for another one, and your whole system starts to fall apart and get impossible to upgrade/downgrade cleanly). I still think prebuilt binaries are useful, though. I thought about stable version on playground because someone tried to build an example from the website with an older re2c version, it broke (as the old re2c did not support some things) and they concluded that the examples are broken and not tested. I can't blame them -- it would look the same for me. But perhaps you are right, let's not make playground overly complex, I'll try to revert some of the examples to the state that works with older re2c versions (until most distros get updated). |
Ok, great.
Feature creep is also a thing. Would it be a better option to have a re2c directive to specify the minimal version for a specific re2c file? The same as Cmake does.
Looks good for me. |
You've got the idea and it seems a bit better, I also tried change the colors but I couldn't find a good combination. |
I'm not really sure about this. Most of the new features are behind a flag (you need to pass an option to enable them), and the old re2c version would just tell you that there's no such option, which is good enough. In this case it's a bunch of aliases that cause a problem -- it's not a typical change. I guess we'll just have to be more conservative with the examples for C/C++ for a while. I have mixed feelings about minimum required version because we've had so many releases without it (and without any problems), and I think it won't have much value going forward. |
@PolarGoose Do you think it would be hard to add stable links to every example on the playground? I'd like to have a link "run on playground" next to each example in the manual. But the current links are autogenerated from the example contents, so they are not stable (they need to be autoupdated together with examples). I wonder if it could be solved by having an autogenerated html page with a redirect, and the link to the page itself would be stable. Maybe you can think of a more elegant way. |
Ok, then it is not needed. Agreed.
What if we add an extra feature in |
Sure, if it's possible! I don't know how to do this. |
Ok, agreed. Let me look into this. |
A few things that I need to remember to do:
|
It is hard to believe, but it seems that it should be possible. Let me check. |
I'm looking to create a kind of online playground like:
And to start with I created this
Lua
script to generate an amalgamation of this project.mk-re2c-amalagamation.lua:
The text was updated successfully, but these errors were encountered: