Answer the question
In order to leave comments, you need to log in
What is the best way to write a javascript-based language parser?
I want to make a simple language with the ability to insert pieces of js. (Ala jsx)
What is the best way to do this? How do different languages integrate into each other. For example html -> js, jsx -> js, php -> html etc.?
I note that I do not need AST from JavaScript, I need to define sections with it. Those. the output could be something like this:
node
- type='block'
- children [
node
- type="js"
- text="return foo"
...
<script>console.log('</script>')</script>
Answer the question
In order to leave comments, you need to log in
Use monodic/combinatorial parsers . Examples are usually given in Haskell, but using this pattern is not difficult in almost any language - closures and garbage collection are desirable, they can be dispensed with, but programming is difficult.
How do different languages integrate into each other in drgua. For example html -> js
1. <script>console.log('</script>')</script>
Such a construction in the browser can (could before?) cause problems. However, it's not too difficult to write a simple analyzer that will determine that these things are inside quotes.
3.jslint?
What you are looking for is called AST. acorn and esprima are exactly what you are looking for.
There is also https://developer.mozilla.org/en-US/docs/Mozilla/P...
I recommend you to take https://github.com/syntax-tree/hast and get nodes with JavaScript and them in turn to feed JS AST.
As far as I understand, you need to make your own language, but under js? If yes, then you can try to make a translator of your language (syntax) and translate it into js. Take as a basis any js implementation of your taste and language. And add your syntax constructs or whatever
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question