Tree-sitter uses JS for grammars and I'm sure there are others:
https://tree-sitter.github.io/tree-sitter/creating-parsers#t...
I was aiming for sub-100 lines of code implementation. IMO, a full-fledged library would be much better off if they just supported EBNF or McKeeman Form.
Re:Applicative Parsing
by hardmath123 on Monday March 01, 2021 @05:03PM
(#26309060)
Parsers in nearley.js [1] are written in a very readable EBNF-like DSL; then they get desugared down to a JS file that's a lot like your snippet.
Re:Applicative Parsing
by matheusmoreira on Monday March 01, 2021 @09:18PM
(#26311184)
I love Earley's algorithm! I wonder why it's so rare. Nearley is the only implementation I know. Why? It handles every possible grammar and yet it is a relatively simple algorithm. Would make an excellent choice for a standard library parse(grammar, input) function.
Is it because the papers are hard to understand? All those symbols make no sense to the uninitiated. I definitely struggled to gain an understanding of how it works.
My best stab at representing something like EBNF in JS looked like this:
This is a grammar for "arrays" of positive integers. I tested it out and concluded that this is too awful to be of any practical use. Now I'm seeing something with significantly more involved representation making it to the front page of HN. Hm.---
Edit: Not much to look at, but here is the source code of the toy implementation if anyone is interested:
https://jsfiddle.net/306jrnt9/1/
The only "cool" part about it is that the parser implementation is close to 100 lines of code.