Parsing Expression Grammar vs. Regexes: Building Org Parser in Lisp, Export HTML
2 days ago
- OrgWebAlchemy is a Guile Scheme library that uses Parsing Expression Grammars (PEG) via (ice-9 peg) to parse Org mode documents into an AST and render them as HTML via SXML.
- The project started with naive regexes but evolved to PEG to handle complex Org features like nested lists, inline markup, tables, and blocks without the typical regex maintenance problems.
- The grammar is expressed as S-expressions, making it readable and maintainable; the parser produces an AST which is then converted to SXML and finally HTML, allowing future export to other formats.
- Supported Org constructs include headings, paragraphs, ordered/unordered/description lists (with nesting), inline formatting (italic, bold, code), links, horizontal separators, tables, src/example/quote blocks, and export HTML blocks.
- Nested lists are parsed as flat sequences and then transformed into a tree structure based on indentation, with some ongoing work to handle mixed list types correctly.
- The HTML output is customizable via Guile parameters (e.g., heading classes per level), and the project is licensed under GNU LGPL v3+, with plans to be packaged for GNU Guix.