Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- grammar dreme::datum::Grammar {
- token TOP {
- <datum>
- [ $ || <.panic: "Syntax error"> ]
- }
- ## Lexer item
- # <interlexeme space>
- token ws {
- <atmosphere>*
- }
- token comment {
- | <.line_comment>
- | <.nested_comment>
- # | <datum_comment>
- # | <bang_comment>
- }
- token line_comment {
- ';' \N* \n?
- }
- token nested_comment {
- '#|' <.comment_text> <.comment_cont>* '|#'
- }
- token comment_text {
- [ <-[|\#]> ]*
- }
- token comment_cont {
- <nested_comment> <comment_text>
- }
- token atmosphere { \s | <comment> }
- token identifier {
- | <.initial> <.subsequent>*
- # | <peculiar_identifier>
- }
- token initial {
- | <.constituent>
- | <.special_initial>
- | <.inline_hex_escape>
- }
- token constituent {
- <.alpha>
- # TODO
- }
- token special_initial {
- <[!$%&*/:<=>?^_~]>
- }
- token subsequent {
- | <.initial>
- | <.digit>
- # | TODO
- | <.special_subsequent>
- }
- token special_subsequent {
- <[+\-.@]>
- }
- token inline_hex_escape {
- '\x' <.hex_scalar_value> ';'
- }
- token hex_scalar_value {
- <.xdigit>+
- }
- token peculiar_identifier {
- | '+'
- | '-'
- | '...'
- | '->' <.subsequent>*
- }
- token boolean {
- '#' <[tTfF]>
- }
- token character {
- '#\\' .
- }
- token string {
- '"' ~ '"' <.string_element>*
- }
- token string_element {
- <-[\"]>
- }
- rule symbol {
- | <identifier>
- | '#%' <identifier>
- }
- ## Data
- rule datum {
- | <simple_datum>
- | <compound_datum>
- }
- rule simple_datum {
- | <boolean>
- | <character>
- | <number>
- | <string>
- | <symbol>
- | <bytevector>
- }
- rule compound_datum {
- | <list>
- | <vector>
- }
- 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}>
- }
- ## Numbers
- token number {
- \d+
- }
- ## End
- }
- ## Main
- my Str $input = @*ARGS[0];
- say dreme::datum::Grammar.parse($input);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement