Created
September 28, 2015 20:13
-
-
Save devuo/b44d70b8b8f6f8f28d11 to your computer and use it in GitHub Desktop.
iCal Parser
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 | |
= calendar | |
calendar | |
= header a:attribute* c:component* footer { return { attributes: a, components: c } } | |
header | |
= "BEGIN:VCALENDAR" linebreak | |
footer | |
= "END:VCALENDAR" linebreak* | |
component | |
= t:component_header a:attribute* c:component* component_footer { return { type: t, components: c, attributes: a } } | |
component_header | |
= "BEGIN:" type:all_chars linebreak { return type } | |
component_footer | |
= "END:" all_chars linebreak | |
attribute | |
= !component_header !component_footer a:(multiline_attribute/simple_attribute/complex_attribute) { return { key: a.key, value: a.value } } | |
simple_attribute | |
= k:uppercase_az ":" v:all_chars linebreak { return { type: "simple", key: k, value: v } } | |
complex_attribute | |
= k:uppercase_az ";" v:all_chars linebreak { return { type: "complex", key: k, value: v } } | |
multiline_attribute | |
= k:uppercase_az ":" v:all_chars linebreak v2:multiline+ { return { type: "multiline", key: k, value: v.concat(v2) } } | |
multiline | |
= whitespace+ s:all_chars linebreak { return s } | |
uppercase_az | |
= s:[A-Z-_]+ { return s.join("").trim() } | |
all_chars | |
= s:[^\n]* { return s.join("").trim() } | |
linebreak | |
= [\n] | |
whitespace | |
= [\t\v\f \u00A0\uFEFF] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment