← Sat, Sep 26 digest

Parsing Expression Grammar vs. Regexes: Building Org Parser in Lisp, Export HTML

read article ↗ hn thread ↗

Josep built OrgWebAlchemy, a Guile Scheme library using Parsing Expression Grammars to parse Emacs Org-mode files into an AST and render them to HTML without requiring Emacs.

summary is enough The post introduces a clean Guile Scheme parser, while the comment section features a rich debate on parsing theory and parser generation.

summary

The author developed OrgWebAlchemy in Guile Scheme to parse Emacs Org-mode documents into an abstract syntax tree using Parsing Expression Grammars and render them to HTML via SXML. Moving away from brittle regular expressions allows the parser to properly handle complex hierarchical structures like nested lists and blocks without Emacs. Commenters debate the limits of PEGs for context-dependent features and whether LLMs make traditional parser generators obsolete.

key points

  1. OrgWebAlchemy uses Guile Scheme's ice-9 peg module to translate Org-mode syntax into SXML and render HTML.
  2. PEGs handle nested lists, blocks, and inline formatting much more cleanly than complex regular expressions.
  3. Commenters discuss the Chomsky hierarchy limits of PEGs and whether LLMs diminish the value of parser generators.

who should read it

Scheme programmers, language parser enthusiasts, and developers interested in alternative Org-mode tooling.

discussion positive

consensus

Commenters praise the Lisp implementation and agree that regexes fail on hierarchical text, but note that PEGs struggle with context-dependent features.

pushback

A prominent thread questions the appeal of PEGs and parser generators now that LLMs can quickly write custom recursive-descent parsers.

best comment by overthenexttwod ↗

Over the years, I have implemented parsers numerous times, both at work and for side projects, so writing recursive-descent parsers from scratch has become second nature. Once you understand the mechanics, writing a parser by hand is straightforward and offers distinct advantages, particularly much greater flexibility with error handling and reporting. Because of that, I had always viewed PEGs and parser generators as tools primarily for people who couldn’t hand-roll their own because of their circumstances or skill level. (If you look at projects that are neither understaffed nor …

It argues that LLMs have made handwritten recursive-descent parsers so fast to build that traditional parser generators are hard to justify.

Generated by an LLM from the article and thread. Check the sources before relying on it.