News for hackers. Stuff that matters.
Re:Parsing Expression Grammar vs. Regexes: Building Org Pars... by zelphirkalt on Saturday September 26, 2026 @06:56AM (#49855320)
Ha, that's interesting.

I started exactly such a project, for org syntax, a while ago. Didn't get very far though because it seems to me that things in org cannot be parsed and understood in one go. For example the TODO keywords can be specified at the top of an org file and then would influence how headings in the document are understood. This cannot be done with merely a PEG.

Another tricky point is nested inline markup. Bold inside italic? Verbatim inside bold, inside italic? And so on. Would be great to support all meaningful combinations via recursive rules. Org has many inline markup things. Even programming language specific inline markup elements.

Another issue is, that Guile's PEG library, when using the non-string form of grammar rules, does not allow mutually recursive grammar rules, due to being buggy (in that way it is not excellent, but in other ways it is!). One has to use the string form or rules, which makes it a lot less nice to use, unfortunately. I hope that will be fixed at some point, because I like the library except for that. And it is in the standard lib, no need to install any dependencies. Like to use it for AoC puzzle inputs for example.

Will be interesting to read how far they got.

Re:Parsing Expression Grammar vs. Regexes: Building Org Pars... by jjba23 on Saturday September 26, 2026 @09:04AM (#49856136)
Aha! Interesting to hear you were going in the same direction. There are indeed quite some tricky situations to handle since Org (and Markdown) are complex in many ways.

the approach I am taking is to combine the PEG with a step of AST processing in order to then produce a correct and descriptive tree structure (for later rendering).

I do agree the Guile library has some spots to improve but honestly, I am already enjoying it so much, and it's far better for the Lisper in me than other things I've tried. I also find S-expressions much more comprehensible and self-documenting.

Looking forward to seeing what you do with it :)

I am indeed hoping that this library is useful for more people and that perhaps things like Haunt blog generator can use it (and other interesting uses)

As for nested markup, and nested lists it has been tricky, but so far I've really promising results:

(assert-equal #:got (inline-org->html (inline-org->ast "*bold with /italic/*")) #:expect "<strong>bold with <em>italic</em></strong>")

Re:Parsing Expression Grammar vs. Regexes: Building Org Pars... by tgbugs on Saturday September 26, 2026 @09:15AM (#49856246)
I had done some work in this direction in my org parser for racket [0]. That work is stalled at the moment (though I still intend to come back to it), but many of the interactions between org and traditional formal grammars have been explored there.

0. https://github.com/tgbugs/laundry

Re:Parsing Expression Grammar vs. Regexes: Building Org Pars... by jjba23 on Saturday September 26, 2026 @09:21AM (#49856293)
Some really impressive work there! thanks for sharing!