How best to write the javascript parser-based language?

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

Note that the AST from JavaScript a I don't need, I need to identify the sections with him. Ie, the exhaust may be approximately:
- type='block'
- children [
 - type="js"
 - 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 <script>console.log('</script>')
Will be recognized, not as much as I would like

2) use a parser with a configurable grammar.
For example Yacc, jison, chevrotain , 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,
esprima, 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.

Summing up:
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.
June 10th 19 at 15:01
5 answers
June 10th 19 at 15:03
Use melodicheskie/combinatorial parsers. Examples are usually given in Haskell, but using this pattern is not difficult in almost any language - preferably the presence of closures and garbage collection, you can do without them, but the program has hard.
June 10th 19 at 15:05
How do integrate the different languages each of drgw. For example, html -> js

2 completely separate libraries - one for HTML, the other some JS engine harness
basically works first, and how he finds the item
June 10th 19 at 15:07
1. the<script>console.log('</script>')This design and the browser can (could before?) to cause a problem. However, it is particularly difficult to write a simple parser that will determine what these things inside the quotes.

3. jslint?
You can learn more about how to write a parser? Especially unpretentious.
It is not understood about jslint. To use it as a parser? - idell_Kassulke commented on June 10th 19 at 15:10
sorry , jslint it was about "living databasenya parser"

Simple - something like this:
actually the analyzer on the lines 4-16
it is primitive, but the concept should be clear - iterated character by character, and determine inside the quotation marks is the symbol or not. - Austen.Thompson53 commented on June 10th 19 at 15:13
June 10th 19 at 15:09
What you are looking for is called AST. acorn and esprima is exactly what you are looking for.
There are still

I recommend you to take and to nodes with JavaScript, and they in turn feed it to the JS AST.
June 10th 19 at 15:11
As I understand it, you need to make your language, but under js? If so, you can try to make a translator of their language (syntax) and convert to js. Take as a basis any implementation of js on your taste and language. And paste your syntax or whatever

Find more questions by tags JavaScriptProgrammingProgramming languagesTranslators