Markdown Extra Spec: Parsing Section

Michel Fortin michel.fortin at
Tue May 13 08:52:56 EDT 2008

Le 2008-05-13 à 2:20, John MacFarlane a écrit :

> PS. Here's all you have to learn in order to write or read a PEG

> grammar.


> A B C A followed by B followed by C

> A | B A or B (ordered choice)

> A+ one or more As

> A* zero or more As

> A? optional A

> !A not followed by A

> &A followed by A (but does not consume A)

> (A B) grouping

> . matches any character

> 'x' matches the character 'x'

> "string" matches the string "string"

> [a-z] matches a character from 'a' to 'z'

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.

Michel Fortin
michel.fortin at

More information about the Markdown-Discuss mailing list