I’ve recently used NimbleParsec for parsing a programming language for a game/challenge, just for fun. It might not have been the best solution, but it was pretty good at getting the job done!
That got me wondering if anyone else has used NimbleParsec for parsing a programming language. And if so, how did you handle pretty-printing parsing errors? (I didn’t handle at all haha)
I’d love to see some examples to learn from them – and perhaps even add some examples to the lib’s documentation.
Also, if you know a more adequate lexer/parser for parsing programming langs in Elixir, please do let me know. I’d love some recommendations.
I haven’t used it for parsing an existing language but I’ve used it to parse DSLs. For example, I wrote a schema-less JSON document API on top of Elasticsearch and wrote a query language using NimbleParsec.
Can you provide any more detail about what you mean by pretty-printing exactly? I’ll provide some personal experience here though: I’ve found piping the result of NimbleParsec.wrap_and_tag/3 to the NimbleParsec.label/3 function is really useful for improving error messages. In combination with the line+column integers in the error tuple returned by defparsec-defined functions, I’ve managed to produce concise, easy-to-debug error messages
I think “prettry-print” wasn’t my best choice of wording there, I meant more like being able to provide fine grained error messages as one would expect from a compiler’s parser. using label/3 didn’t seem much helpful there (probably mb for misusing it).