Last active
August 29, 2015 14:00
-
-
Save skoji/11024885 to your computer and use it in GitHub Desktop.
mini NoraMark parser definition for PEG.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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