Announcing Spirit Markdown

Alastair Rankine arsptr at
Tue May 11 17:32:03 EDT 2010

On 12/05/2010, at 5:00 AM, John MacFarlane wrote:

> +++ Alastair Rankine [May 11 10 21:51 ]:

>> Boost Spirit is a parser generator for PEG-based grammars. My grammar

>> is based on John MacFarlane's PEG grammars for markdown, and to him I

>> am much indebted. There are however quite a few differences between

>> John's and mine and I'd be happy to discuss them.


> Yes, I'd be interested (especially if some of the differences are

> mistakes in peg-markdown, which I could correct).

Not mistakes, at least I don't think so.

The main differences are due to me taking advantage of Spirit features, which may or may not be available for your PEG parser generator.

Spirit supports the concept of synthesised and inherited attributes. These allow state to be explicitly passed between rule invocations, similar to function call arguments. I have used these extensively, particularly for managing state that is difficult to manage otherwise.

As an example, my rules that support nested constructs (blockquotes, verbatim, lists) can be arbitarily nested by simply passing around a string which represents the "current" nesting level, in the form of a prefix. This allows the rules to check that they are still at the current level of nesting, by checking for the inherited prefix at the start of each line. If found, the rules ignore it and continue parsing just as though they were un-nested.

The result is a single-pass parser. AFAICT this is not possible without inherited and synthesised attributes (or an equivalent).

More information about the Markdown-Discuss mailing list