Advertisement
Guest User

Untitled

a guest
May 9th, 2012
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 2.16 KB | None | 0 0
  1. grammar dreme::datum::Grammar {
  2.  
  3. token TOP {
  4.     <datum>
  5.     [ $ || <.panic: "Syntax error"> ]
  6. }
  7.  
  8. ## Lexer item
  9.  
  10. # <interlexeme space>
  11. token ws {
  12.     <atmosphere>*
  13. }
  14.  
  15. token comment {
  16.     | <.line_comment>
  17.     | <.nested_comment>
  18. #   | <datum_comment>
  19. #   | <bang_comment>
  20. }
  21.  
  22. token line_comment {
  23.     ';' \N* \n?
  24. }
  25.  
  26. token nested_comment {
  27.     '#|' <.comment_text> <.comment_cont>* '|#'
  28. }
  29.  
  30. token comment_text {
  31.     [ <-[|\#]> ]*
  32. }
  33.  
  34. token comment_cont {
  35.     <nested_comment> <comment_text>
  36. }
  37.  
  38. token atmosphere { \s | <comment> }
  39.  
  40. token identifier {
  41.     | <.initial> <.subsequent>*
  42. #   | <peculiar_identifier>
  43. }
  44.  
  45. token initial {
  46.     | <.constituent>
  47.     | <.special_initial>
  48.     | <.inline_hex_escape>
  49. }
  50.  
  51. token constituent {
  52.     <.alpha>
  53. #   TODO
  54. }
  55.  
  56. token special_initial {
  57.     <[!$%&*/:<=>?^_~]>
  58. }
  59.  
  60. token subsequent {
  61.     | <.initial>
  62.     | <.digit>
  63. #   | TODO
  64.     | <.special_subsequent>
  65. }
  66.  
  67. token special_subsequent {
  68.     <[+\-.@]>
  69. }
  70.  
  71. token inline_hex_escape {
  72.     '\x' <.hex_scalar_value> ';'
  73. }
  74.  
  75. token hex_scalar_value {
  76.     <.xdigit>+
  77. }
  78.  
  79. token peculiar_identifier {
  80.     | '+'
  81.     | '-'
  82.     | '...'
  83.     | '->' <.subsequent>*
  84. }
  85.  
  86. token boolean {
  87.     '#' <[tTfF]>
  88. }
  89.  
  90. token character {
  91.     '#\\' .
  92. }
  93.  
  94. token string {
  95.     '"' ~ '"' <.string_element>*
  96. }
  97.  
  98. token string_element {
  99.     <-[\"]>
  100. }
  101.  
  102. rule symbol {
  103.     | <identifier>
  104.     | '#%' <identifier>
  105. }
  106.  
  107. ## Data
  108.  
  109. rule datum {
  110.     | <simple_datum>
  111.     | <compound_datum>
  112. }
  113.  
  114. rule simple_datum {
  115.     | <boolean>
  116.     | <character>
  117.     | <number>
  118.     | <string>
  119.     | <symbol>
  120.     | <bytevector>
  121. }
  122.  
  123. rule compound_datum {
  124.     | <list>
  125.     | <vector>
  126. }
  127.  
  128. rule list {
  129.     | '(' ~ ')' <list_data>
  130.     | '[' ~ ']' <list_data> # R6RS
  131. }
  132.  
  133. rule list_data {
  134.     | <datum>*
  135.     | <datum>+ '.' <datum>
  136.     | <datum> '.' <datum> '.' <datum> # Racket
  137. }
  138.  
  139. rule abbreviation {
  140.     | "'" <datum>
  141.     | '`' <datum>
  142.     | ',' <datum>
  143.     | ',@' <datum>
  144. }
  145.  
  146. rule vector {
  147.     '#' '(' ~ ')' <datum>*
  148. }
  149.  
  150. token bytevector_hash {
  151.     | '#vu8' # R6RS
  152.     | '#u8'  # R7RS
  153. }
  154.  
  155. rule bytevector {
  156.     <bytevector_hash> '(' ~ ')' <u8>*
  157. }
  158.  
  159. token u8 {
  160.     \d**1..3 <?{$/ < 256}>
  161. }
  162.  
  163. ## Numbers
  164.  
  165. token number {
  166.     \d+
  167. }
  168.  
  169. ## End
  170.  
  171. }
  172.  
  173. ## Main
  174.  
  175. my Str $input = @*ARGS[0];
  176. say dreme::datum::Grammar.parse($input);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement