Skip to content

Instantly share code, notes, and snippets.

@devuo
Created September 28, 2015 20:13
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 devuo/b44d70b8b8f6f8f28d11 to your computer and use it in GitHub Desktop.
Save devuo/b44d70b8b8f6f8f28d11 to your computer and use it in GitHub Desktop.
iCal Parser
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