A Smart python like language that compiles to modern (functional) Javascript.
npm i -S red-dragon
Chevrotain has the capability to automatically create a concrete syntax tree (CST) during parsing. A CST is a simple structure which represents the entire parse tree. It contains information on every token parsed.
The main advantage of using the automatic CST creation is that it enables writing "pure" grammars. This means that the semantic actions are not embedded into the grammar implementation but are instead completely separated from it.
This separation of concerns makes the grammar easier to maintain and makes it easier to implement different capabilities on the grammar, for example: separate logic for compilation and for IDE support.
CST is enabled by setting the outputCst
flag.
class MyParser extends chevrotain.Parser {
constructor(input) {
super(input, allTokens, {outputCst : true})
}
}
Using:
$.RULE("qualifiedName", () => {
$.CONSUME(Identifier)
$.CONSUME(Dot)
$.CONSUME2(Identifier)
})
input = "foo.bar"
output = {
name: "qualifiedName",
children: {
Dot : ["."],
Identifier : ["foo", "bar"]
}
}
Note: even when building a CST the performance on most recent versions of Chrome (59) was faster Than any other tested parsing library (Antlr4/PegJS/Jison).
Install dependency modules/packages
npm i
The project includes a gulpfile
configured to use Babel 6.
All /src
files are compiled to /dist
including source maps.
Scripts:
- start:
npm start
- build:
npm run build
(ie. compile) - watch and start:
npm run watch
- watch and build:
npm run watch:b
npm test
or simply ava test
MIT Kristian Mandrup