Markdown Extra Spec: Parsing Section

John MacFarlane jgm at berkeley.edu
Tue May 13 10:02:48 EDT 2008



> It certainly true that many parts could be converted to this and be less

> verbose, and I find this idea appealing. I doubt the whole Markdown Extra

> ruleset can be expressed in this format though. Can a PEG grammar have

> parametrized rules?

>

> I've just added nested block element support in the spec. This is done

> by having the block element generator (formerly the block element pass)

> have a stack of rules to match when starting each line. This idea coming

> straight from Allan Odgaard's explanation of his lost Markdown parser.

> <http://six.pairlist.net/pipermail/markdown-discuss/2008-March/001107.html


No, PEG can't do this. But there is a different approach that works
(described in my earlier email).

By the way: if I understand it correctly, your description of "Code
block" would parse the following as two code blocks, not one code block
containing a blank line:

some code

more code

(Note: there is no tab on the middle line.) I don't think that's the
desired behavior.

Here's the markdown-peg version (and remember, this is "runnable"):

verbatim <- newRule $
many1 (doesNotMatch blankline ->> indentedLine) <++>
(many (many1 (optional indent ->> blankline) <++>
many1 (doesNotMatch blankline ->> indentedLine)) ## concat) <<-
many blankline ## Verbatim . concat

John



More information about the Markdown-Discuss mailing list