Parsers
Published on 5 April 2023
There are plenty of resources helping you to make parsers and interpreters in various languages. Resources mentioned in the Easy Mode are the ones that I followed. Most of them are in Golang:
Easy Mode
I followed these, in the exact order they are listed:
- https://notes.eatonphil.com/documentdb.html
- I don’t remember really if I followed along, but I did go through the article
- https://www.youtube.com/playlist?list=PLjJMyANAIVHEgUOK2cU0hrvSwFPNHT2a7
- I watched and followed along
- https://youtu.be/x5p_SJNRB4U
- It’s fine if you don’t fully understand what’s happening in the video, the next two ones in the list will help you to solidify the concepts.
- Slides are at https://docs.google.com/presentation/d/1PfFFXjguakJM13tHWkFxFcy4wee65B26T9Cij2TWC0w/
- Code is at https://github.com/jhbrown-veradept/gophercon22-parser-combinators
- This talk mentions an Elm lang talk https://youtu.be/M9ulswr1z0E, which is fun to listen to
- https://youtu.be/JiViND-bpmw
- Great resource
- Helped me to understand parser combinators
- Discovering that the ability of producing nice errors via parser combinators is a plus
- https://www.youtube.com/playlist?list=PLP29wDx6QmW5yfO1LAgO8kU3aQEj8SIrU
- While I not followed, I find this one to be the most useful, as it helped me hammer down concepts
- Again, having some previous knowledge before watching this came very useful, that’s why it is in the last of the list
- I watched till 01:05 of episode 6
Before implementing your own parser in Go, I’d suggest you to take a refresher on:
- https://go.dev/doc/faq#nil_error
- https://go.dev/blog/strings
- Result (inspired from Rust): making either a success or a failure/error type using generics in Go https://github.com/samber/mo#resultt-any
- With the omission of ? operator and
context
from anyhow (https://github.com/dtolnay/anyhow) Result in Go could not feel super useful
- With the omission of ? operator and
Hard Mode
Only titling it as “hard” because the steps to make them work are quite involved. You can learn a lot of stuff with this though, like reporting nice errors and having a fault tolerant parser:
- https://youtu.be/ZJbofN7eg6E
- https://www.youtube.com/playlist?list=PLhb66M_x9UmrqXhQuIpWC5VgTdrGxMx3y
Goto Resources
- From Phil Eaton: here, here and here
- https://craftinginterpreters.com/
- https://interpreterbook.com/ and https://compilerbook.com/
- https://lists.eatonphil.com/compilers-and-interpreters.html
Other Resources (Mostly Rust)
- (must see) https://www.reddit.com/r/rust/comments/zquqo9/got_so_annoyed_at_all_the_parsing_i_needed_to_do/
- https://www.reddit.com/r/rust/comments/wsf5vb/earley_parsing_explained/
- https://github.com/figsoda/pep-508
- https://tratt.net/laurie/blog/2020/which_parsing_approach.html
- https://github.com/jinxdash/jinx-rust
- https://github.com/Marwes/combine https://github.com/francisrstokes/arcsecond
- https://www.reddit.com/r/rust/comments/123mnma/easy_way_to_produce_a_parser/jdw8c35/
- https://github.com/maciejhirsz/logos and https://www.reddit.com/r/rust/comments/sxh9o2/logosnombridge_a_crate_to_implement_nom_parsers/
- https://github.com/brendanzab/codespan or https://github.com/zkat/miette
- https://github.com/zesterer/chumsky and https://www.reddit.com/r/rust/comments/10ys3qb/write_better_parsers_with_nom_supreme/
- https://lunacookies.github.io/lang/