Warning:
This wiki has been archived and is now read-only.

EbnfGrammar

From Markdown Community Group
Jump to: navigation, search

EBNF for the core profile is listed on this page.

Paragraphs

The following is EBNF grammar which will parse multiple paragraphs, with the limitation that this grammar requires each paragraph end with an EOL followed by a blank line. In actual Markdown documents, the last paragraph in a document must be able to end on an (EOL BlankLine | EOL EOF | EOF), but I don't know how to represent EOF in EBNF nor deal with the uncertainty without EOF. It can be parsed using yacker (http://www.w3.org/1999/02/26-modules/User/Yacker), and conforms to the simplified EBNF notation.

Help is welcome!

   Paragraphs ::= Paragraph+
   
   Paragraph ::= Lines BlankLine+
   
   BlankLine ::= Ws* Eol
   
   Lines ::= Line+
   Line ::= LinePre Word (Ws Word)* LinePost Eol
   LinePre ::= (Sp (Sp (Sp)?)?)?
   LinePost ::= Sp?
   
   Ws ::= (Sp | Ht)+
   Word ::= Char+
   
   @terminals
   Sp ::= ' '
   Ht ::= '\t'
   Cr ::= '\r'
   Lf ::= '\n'
   Eol ::= Cr Lf | Cr | Lf
   
   Char ::= [^#xA#xD#x9#x20]
   
   @pass ::= "Everything goes downhill if you pass this rule."