Last active
May 23, 2018 03:20
-
-
Save dasdachs/078485a7c8fc31988940551cc79a1241 to your computer and use it in GitHub Desktop.
peg.js
This file contains hidden or 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
VAR = line:line* { return line; } // Return array of arrays with elements :D | |
start = ws "{{" ws | |
end = ws "}}" ws | |
ws "whitespace" | |
= s:[ \t\r]* | |
n "newline" | |
= n:"\n"* | |
line | |
= start:element body:element* n { return [start].concat(body); } | |
// DRY, element coudl be a var or a line of text | |
element | |
= element: ( | |
text | |
/ var | |
) | |
{ return element; } | |
text | |
= ws words:word+ ws { return words.join(""); } | |
var | |
= ws start var_name:word filter:filter? end ws { return {"name": var_name, "filter": filter }; } | |
filter = ws "|" ws filter:word { return filter; } | |
word | |
= ws char:[A-z_]+ end:ws {return char.join("") + end; } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment