skvadrik/re2c

Javascript Support

Opened this issue ยท 4 comments

F35H commented

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.

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.

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 commented

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].

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).