Guest User

Untitled

a guest
Dec 9th, 2018
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.46 KB | None | 0 0
  1. grammar ical {
  2. rule TOP {
  3. <vcalendar>
  4. }
  5. rule vcalendar {
  6. <section>
  7. \n?
  8. }
  9. # section does not end with a NL
  10. rule section {
  11. 'BEGIN:' <tag> \n
  12. <thing>+ % \n
  13. \n
  14. 'END:' $<tag>
  15. }
  16. rule thing {
  17. [ <section> | <property> ]
  18. }
  19. rule property {
  20. <single-line> | <multi-line>
  21. }
  22. regex single-line {
  23. ^^ <!before 'BEGIN'|'END'> <tag> ':' <value> $$
  24. }
  25. token multi-line {
  26. ^^ <tag> ':' \n
  27. <multi-line-value>
  28. }
  29. token multi-line-value {
  30. [ ^^ <.indent> \N* ]+ %% \n
  31. }
  32. token indent {
  33. ' '+
  34. }
  35. regex tag {
  36. <[A..Z-]>+
  37. }
  38. token value {
  39. \V+
  40. }
  41. token ws { <!ww> \h* }
  42. }
  43.  
  44. class actions {
  45. my sub escape($str) {
  46. $str.subst('\n',"\n",:g);
  47. }
  48. method TOP($/) {
  49. $/.make: $<vcalendar>.made
  50. }
  51. method vcalendar($/) {
  52. $/.make: $<section>.made<VCALENDAR>;
  53. }
  54. method section($/) {
  55. $/.make: "$<tag>" => %( $<thing>.map: *.made )
  56. }
  57. multi method thing($/ where $<property>) {
  58. $/.make: $<property>.made;
  59. }
  60. multi method thing($/ where $<section>) {
  61. $/.make: $<section>.made;
  62. }
  63. method single-line($/) {
  64. $/.make: "$<tag>" => $<value>
  65. }
  66. method multi-line($/) {
  67. $/.make: "$<tag>" => escape("$<multi-line-value>")
  68. }
  69. method property($/) {
  70. $/.make: .made given $<single-line> || $<multi-line>;
  71. }
  72. }
Add Comment
Please, Sign In to add comment