markdown PEG (parsing expression grammar)

John MacFarlane jgm at berkeley.edu
Sun Apr 6 13:50:39 EDT 2008


There's been a lot of discussion on this list about creating a formal
grammar for markdown. I had a go at writing a [parsing expression
grammar] for markdown. I used Haskell and John Meacham's Frisby PEG
parsing library, but it should not be too hard to port the grammar
to PEG libraries in other languages.

[parsing expression grammar]: http://en.wikipedia.org/wiki/Parsing_expression_grammar

The code is at <http://github.com/jgm/markdown-peg/tree/master>.
All that is required to compile it is the GHC haskell compiler.
The grammar itself begins at line 68 of Markdown.hs:
<http://github.com/jgm/markdown-peg/tree/master/Markdown.hs#L68>.

This implementation is not particularly fast, though it is still
faster than Markdown.pl. It should be fairly easy to modify and extend,
though, and the grammar provides a precise specification of (one
interpretation of!) the syntax of markdown, which might be a useful
basis for discussion.

John



More information about the Markdown-Discuss mailing list