bd82
Joined 10 years ago
Joined 10 years ago
- Antlr (https://github.com/antlr/antlr4/blob/master/doc/javascript-target.md)
- PegJS (https://github.com/pegjs/pegjs)
- Nearley (https://github.com/kach/nearley)Maybe it makes sense if you assume the input has already been tokenized so you are not expected to deal with the minutiae of string literal escape sequences and such and can focus on the high level design/flow...
Chevrotain - https://github.com/SAP/chevrotain
The list of features can be found here: - https://sap.github.io/chevrotain/docs/features/blazing_fast....
What is interesting imho is that Chevrotain is not a Parser Generator nor a Parser Combinator. It is a tool that makes it easier to craft hand built recursive decent parsers rather than a whole new level of abstraction.
1.The builds are much faster now. 2. The configuration has virtually no hacks anymore as I'm using Circle-CI own docker images (including browsers). 3. And the UI/UX is superior as well.
Chevrotain is an LL(K) Parser library, or more precisely SLL(K), It looks up-to K fixed token ahead to choose the next alternative.
Because it is just a library to assist in hand crafting recursive decent parsers, the same limitations apply, left recursion would lead to an infinite loop...,however left recursion is detected during initialization and an descriptive error is thrown instead.
Right recursion is allowed.
It is possible to resolve more complex ambiguities using back tracking: http://sap.github.io/chevrotain/docs/features/backtracking.h... or other types of custom logic.
However in general, the library does not try to be able to parse all the possible grammars in the world, instead the focus is more on performance, features and ease of development.
Instead of using an abstraction of a declarative grammar definition and code generation to provide an alternative to writing a parser by hand, Chevrotain simplifies the process of hand crafting a parser.
Meaning no code generation and you can still directly debug the code you have written (unlike most parser combinators).
The base performance however very low, as in two orders of magnitude lower than most other parsing libraries in JavaScript.
See benchmark at: https://sap.github.io/chevrotain/performance/ that I have created.
This is Not exactly a parser generator but an internal JavaScript DSL for writing parsers, but it does meet the criteria for a more verbose syntax.
It is implemented using a parsing library so the lookaheads are automatically performed by the library, but the general pattern is still relevant.
Basically each binary precedence level gets a rule (weakest first) and each of these rules will consume as many operators of the current precedence level as it can.
* https://github.com/antlr/antlr4/blob/master/doc/faq/general....
* See: "What do you think are the problems people will try to solve with ANTLR4?" question
I've used several different parser generators in the past. But I've also transitioned to hand-rolled recursive decent parsers, being Lazy I've created a library to assist in hand-rolling a recursive decent parser: https://github.com/SAP/chevrotain