Hacker News new | ask | show | jobs
by hardmath123 1930 days ago
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.

[1] https://github.com/kach/nearley

1 comments

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.