154 days ago · Writing · hide · Fediverse post

I've been writing a LOT of Gleam recently. So it felt like it was probably time for me to get my parser combinator library (aka. parz) into a fully usable state Since I wrote it back in 2024 (wow that long ago huh?) I hadn't really had a need for it. Recently I wanted to write some small parsers to help me with my site but the library was still missing one thing that would make it actually sorta useful - recursive parsing The actual implementation isn't really difficult, it's basically just defining a combinator that delays actually calling a parser which then lets a parser reference itself, for example: /// Takes a thunk that will be lazily evaluated to a parser. This makes it /// possible to define recursive parsers pub fn lazy( thunk: fn() -> Parser(a), ) -> fn(String) -> Result(ParserState(a), String) { fn(state) { thunk()(state) } } // using it then looks something like this fn group() { lazy(fn() { between(str("("), choice([constant(), group()]), str(")")) // ^ we can reference…

Commenting on Bubbles has been removed. Why? If you want to talk about this post, write to the author, use the comments on their blog if it has them, or reply with a "RE:" post on your own blog. Suggestions? feedback@bubbles.town