I want to make a simple language with the possibility of inserting pieces of js. (Ala jsx)
How best to do this? How do integrate different languages into each other. For example, html -> js, jsx -> js, php -> html etc.?
- children [
- text="return foo"
See the following ways:
1) can we try to solve the problem without parsing the js, but it leads to problems.
In the case of html, this is reflected in the fact that the design of the
Will be recognized, not as much as I would like
2) use a parser with a configurable grammar.
For example Yacc, jison
, this variant I really like, but I don't want to "velosipedit" parsing the js, moreover wants to have his grammar from external sources + constantly updated. If you have in mind, for example, supported the repository es6+ grammar - it would be very cool.
3) use parsers sharpened js: acorn
, or maybe you will offer to make it through the Babel plugins I like. If you have more articles / projects describing build a superset of js this way - I would be grateful. In this case, out of the box is a very good language support (and it still does not fully support the feature), which is lacking in the 2nd embodiment;
3.5) suggest that it is possible to teach any of the parsers to parse the string as long as he can and when he can't count on anything - consider it a end of js snippet. How is the right approach. Moreover, it is desirable to stop tokenization (since the js ast as I said I don't need)
4) Not to parse the js completely, but only split it into "threat" tokens (strings, regular expressions, comments) - parts of the code where it may be "closing tag/bracket" - this option honestly I don't like, but if there is a very cheap solution in this way - I'd be happy to link.
1) do you know where to find grammar (es6, ideally with alive community) js, which can expand and feed "live" (not abandoned) the parser?
2) do you have any experience / an article in the bookmarks how to do it differently?
3) is it possible to integrate the parser with free grammar (jison for example) with, for example acorn ohms. It would be great if got a tip where to dig, where to read?
Suggestions are welcome.