Skip to content
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

Javascript Support #420

Open
F35H opened this issue Oct 29, 2022 · 4 comments
Open

Javascript Support #420

F35H opened this issue Oct 29, 2022 · 4 comments

Comments

@F35H
Copy link

F35H commented Oct 29, 2022

I plan on using this for use with Javascript. The syntax is so similar it's worth using the same tool.

With --loop-switch it's almost perfect* - the string obviously can't be a pointer though.

The other settings can be used easily as well replacing goto with a break or continue.

I might as well leave an issue here for the future.

*Many times I speak mid-idea. Likely the most efficient for anything is bit-vectors, but this will always be contextual and dependent on context.

**Hilarious, but because of the way continue statements work in javascript, --loop-switch is probably the only one viable right now without copious amounts of work in comparison.

@skvadrik
Copy link
Owner

Hi @F35H , thanks for the heads up. There is an idea to add syntax files (user-supplied configs) that will make it easier to use re2c with different language backends. This is not implemented yet, but I'm slowly rewriting codegen subsystem to make it possible.

@skvadrik
Copy link
Owner

There is no need for a string to be a byte stream. The details can be encapsulated behind generic API and you can provide suitable definitions for YYPEEK, YYSKIP and other primitives using the string type and index operator.

@F35H
Copy link
Author

F35H commented Oct 29, 2022

I got it to work appropriately [and viably].

The main thing that makes it difficult for javascript [beyond things such as types, pointers, etc. ] is that continue statements only work with labels that are defined above them only work in loops. It essentially makes it where --loop-switch is the only real option without having to over-analyze each case.

Other than that, it's just a matter of replacing variables where appropriate and organizing "blocks" into functions. Cntrl-H is absolutely your friend [although, now that I've tried it, free-form style with YYPEEK, YYSKIP, etc. is also clearly your friend].

@skvadrik
Copy link
Owner

skvadrik commented Jul 8, 2024

Experimental JS support was added on syntax-files branch: 74ace08. See https://github.com/skvadrik/re2c/tree/syntax-files/examples/js for examples (they use nodejs as the examples run in a non-browser environment).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants