-
-
Save lamchau/9fa50bdc6f15a0066614 to your computer and use it in GitHub Desktop.
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
// do not use result cache, nor line and column tracking | |
{ var indentStack = [], indent = ""; } | |
start | |
= INDENT? lines:( blank / line )* | |
{ return lines; } | |
line | |
= SAMEDENT line:(!EOL c:. { return c; })+ EOL? | |
children:( b:blank* INDENT c:( blank / line )* DEDENT { return b.concat(c); })? | |
{ return [line.join(""), children === "" ? [] : children]; } | |
blank | |
= [ \t]* EOL | |
{ return undefined; } | |
EOL | |
= "\r\n" / "\n" / "\r" | |
SAMEDENT | |
= i:[ \t]* &{ return i.join("") === indent; } | |
INDENT | |
= i:[ \t]+ &{ return i.length > indent.length; } | |
{ indentStack.push(indent); indent = i.join(""); pos = offset; } | |
DEDENT | |
= { indent = indentStack.pop(); } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment