Created
May 9, 2012 03:54
-
-
Save diakopter/2641674 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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