3 ms·
The article mentioned using Parser Combinators as the sweet spot between Hand Written Parsers and Parser Generators. Another possible sweet spot would using so
by bd82 9y ago
The article mentioned using Parser Combinators as the sweet spot between Hand Written Parsers and Parser Generators.
Another possible sweet spot would using something I call a "Parsing DSL" which is a sort of a cross between a parser combinator and a parser generator.
TLDR:
See the JavaScript Parsing DSL library (Chevrotain) I've authored:
https://github.com/SAP/chevrotain https://github.com/SAP/chevrotain
Details:
A Parsing DSL means using API similar to hand building
a parser but without a-lot of the cruft associated with hand building while enjoying higher level abstractions
from the Parsing DSL library such as:
1. automatic ambiguity detection.
2. lookahead calculation.
3. Grammar diagrams
4. auto-complete.
5. automatic error recovery
6. and more...
Under V8 (Chrome/Node) this is much faster than any other library
tested and even substantially faster than a naive hand built parser.
http://sap.github.io/chevrotain/performance/ http://sap.github.io/chevrotain/performance/
(Benchmarked using a simple grammar [JSON])
- e12e 9y agoThis seems to share some ideas with ometa[1], but perhaps arriving at those ideas from another angle? [1] http://www.tinlizzie.org/ometa/ http://www.tinlizzie.org/ometa/ https://github.com/alexwarth/ometa-js https://github.com/alexwarth/ometa-js See also ohm: https://github.com/harc/ohm https://github.com/harc/ohm
- bd82 9y agoI'm less familiar with ometa. Chevrotain shares two main ideas/concepts with Ohm. 1. Separation of grammar and semantics, but in a less opinionated manner as it does not enforce the separation as Ohm does (it is still possible to embed actions directly in the grammar). 2. Grammar Inheritance. Although while those ideas are not common they are also not that rare (For example the same concepts exist in Antlr). I think there are three big conceptual differences. 1. In Chevrotain Performance is considered as a major feature. Which results in it being two orders of magnitude faster (in the benchmark linked above) 2. Chevrotain attempts to provides capabilities relevant for writing IDEs, for example automatic error recovery/tolerance and syntactic content assist. 3. Internal vs External DSL - From an implementation perspective there is a vast difference as Ohm is an external DSL while Chevrotain is an internal DSL. In practical(user) terms this means that you can place a breakpoint directly in a Chevrotain grammar, but you cannot do so in Ohm. Or that you will need a separate editor to edit an Ohm grammar while you can use any JavaScript editor to create a Chevrotain grammar. It also means that Ohm could be ported to different target runtimes (Like Antlr actually is) while Chevrotain can only run in an ECMAScript engine.