Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- grammar ical {
- rule TOP {
- <vcalendar>
- }
- rule vcalendar {
- <section>
- \n?
- }
- # section does not end with a NL
- rule section {
- 'BEGIN:' <tag> \n
- <thing>+ % \n
- \n
- 'END:' $<tag>
- }
- rule thing {
- [ <section> | <property> ]
- }
- rule property {
- <single-line> | <multi-line>
- }
- regex single-line {
- ^^ <!before 'BEGIN'|'END'> <tag> ':' <value> $$
- }
- token multi-line {
- ^^ <tag> ':' \n
- <multi-line-value>
- }
- token multi-line-value {
- [ ^^ <.indent> \N* ]+ %% \n
- }
- token indent {
- ' '+
- }
- regex tag {
- <[A..Z-]>+
- }
- token value {
- \V+
- }
- token ws { <!ww> \h* }
- }
- class actions {
- my sub escape($str) {
- $str.subst('\n',"\n",:g);
- }
- method TOP($/) {
- $/.make: $<vcalendar>.made
- }
- method vcalendar($/) {
- $/.make: $<section>.made<VCALENDAR>;
- }
- method section($/) {
- $/.make: "$<tag>" => %( $<thing>.map: *.made )
- }
- multi method thing($/ where $<property>) {
- $/.make: $<property>.made;
- }
- multi method thing($/ where $<section>) {
- $/.make: $<section>.made;
- }
- method single-line($/) {
- $/.make: "$<tag>" => $<value>
- }
- method multi-line($/) {
- $/.make: "$<tag>" => escape("$<multi-line-value>")
- }
- method property($/) {
- $/.make: .made given $<single-line> || $<multi-line>;
- }
- }
Add Comment
Please, Sign In to add comment