Skip to content

Instantly share code, notes, and snippets.

@diakopter
Created May 9, 2012 03:54
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 diakopter/2641674 to your computer and use it in GitHub Desktop.
Save diakopter/2641674 to your computer and use it in GitHub Desktop.
grammar dreme::datum::Grammar {
token TOP {
<datum>
[ $ || <.panic: "Syntax error"> ]
}
## Lexer items
# This <ws> rule treats # as "comment to eol".
token ws {
<!ww>
<comment>*
}
token comment {
| <line_comment>
| <nested_comment>
}
token line_comment {
';' \N* \n?
}
token nested_comment {
'#|' ~ '|#' .
}
## Data
rule datum {
| <simple_datum>
| <compound_datum>
}
rule simple_datum {
| <boolean>
| <character>
| <number>
| <string>
| <symbol>
| <bytevector>
}
rule compound_datum {
| <list>
| <vector>
}
rule symbol { <identifier> }
rule list {
| '(' ~ ')' <list_data>
| '[' ~ ']' <list_data> # R6RS
}
rule list_data {
| <datum>*
| <datum>+ '.' <datum>
| <datum> '.' <datum> '.' <datum> # Racket
}
rule abbreviation {
| "'" <datum>
| '`' <datum>
| ',' <datum>
| ',@' <datum>
}
rule vector {
'#' '(' ~ ')' <datum>*
}
token bytevector_hash {
| '#vu8' # R6RS
| '#u8' # R7RS
}
rule bytevector {
<bytevector_hash> '(' ~ ')' <u8>
}
token u8 {
\d**1..3 <?{$/ < 256}>
}
}
say dreme::datum::Grammar.parse('228');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment