‹ BackHN Continuity

Thread

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

126 points · 20 comments · jjba23

  1. zelphirkalt · · focus · HN ↗
    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.

    EDIT: Also it's going to be great to have an actual grammar based parser for org. This will ease creating one for other tools, like for example parsers of readmes in repos on git hosters.

    1. tgbugs · · focus · HN ↗
      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. <a href="https:&#x2F;&#x2F;github.com&#x2F;tgbugs&#x2F;laundry" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;tgbugs&#x2F;laundry

      1. jjba23 · · focus · HN ↗
        Some really impressive work there! thanks for sharing!
Open on Hacker News to reply ↗

Unofficial Hacker News client; not affiliated with Y Combinator.