3 ms·
Parser combinators are awesome! I've played with them just a bit. They seem to match my intuition of how a parser's implementation ought to resemble an EBNF gra
by AgentME 9y ago
Parser combinators are awesome! I've played with them just a bit. They seem to match my intuition of how a parser's implementation ought to resemble an EBNF grammar.
Just for fun, using the Bennu library[0] I wrote a JSON parser[1]. (Not intended for production use of course; well-optimized JSON parsers exist and browsers kinda ship with them now. If you're looking for a Bennu example or are thinking of experimenting with extending JSON in wacky ways for fun, then it's neat to mess with.) With that specific library, I seemed to create some messy parts when shuffling values through the library's stream abstraction, but I got the hang of it and the parts I thought were messy at least were straight-forward and didn't have issues like hidden edge cases. Something cool is that parsers made with the library and its stream abstraction automatically work incrementally too.
[0] http://bennu-js.com/ http://bennu-js.com/
[1] https://github.com/AgentME/bennu-json/blob/701d17bc4872469dcbe3dc736feeb66017105dec/src/index.js#L57 https://github.com/AgentME/bennu-json/blob/701d17bc4872469dc..., right on my favorite part.