Skip to content

Instantly share code, notes, and snippets.

@skoji
Last active August 29, 2015 14:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save skoji/11024885 to your computer and use it in GitHub Desktop.
Save skoji/11024885 to your computer and use it in GitHub Desktop.
mini NoraMark parser definition for PEG.js
start
= Document
Document
= EmptyLine* blocks:Block* { return blocks.join("\n"); }
Block
= b:(ExplicitBlock / ParagraphGroup) EmptyLine*
{ return b; }
ExplicitBlockHead
= SPC* name:Word SPC* '{' SPC* LF { return name; }
ExplicitBlockEnd
= SPC* '}' EOL
ExplicitBlock
= head:ExplicitBlockHead
content:Block*
EmptyLine*
ExplicitBlockEnd
{ return "<" + head + ">\n" + content.join("") + "\n</" + head + ">"; }
ParagraphGroup
= pg:Paragraphs
{ return '<div class="pgroup">\n' + pg.join("\n") + "\n</div>"; }
ParagraphDelimiter
= ExplicitBlockHead / ExplicitBlockEnd
Paragraphs
= p:Paragraph LF pg:Paragraphs
{ pg.unshift(p); return pg;}
/ p:Paragraph
{ return [p]; }
Paragraph
= !ParagraphDelimiter dl:DocumentLine
{ return "<p>" + dl + "</p>"; }
DocumentLine
= l:Character+ &EOL
{ return l.join(''); }
Alpha
= [a-zA-Z]
WordChar
= Alpha / [-_]
Word
= s:Alpha r:WordChar* { r.unshift(s); return r.join(''); }
Character
= !LF c:.
{ return c; }
EmptyLine
= LF SPC* EOL / SPC* LF
LF
= "\n"
SPC
= [ \t]
EOL
= "\n" / EOF
EOF
= !.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment