WHITESPACE = _{ " " | "\t" | "\n" }
single_line_comment = @{ ";" ~ (!NEWLINE ~ ANY)* }
single_notation_comment = _{ "#;" ~ notation }
COMMENT = _{ single_line_comment | single_notation_comment }
// --------- boolean ------------
boolean = @{ "#t" | "#f" }
// --------- char ---------------
char = @{
"#\\newline" |
"#\\return" |
"#\\space" |
"#\\tab" |
"#\\" ~ ANY
}
// --------- integer ------------
SIGN = @{ "+"|"-" }
dec_int = @{ ASCII_DIGIT ~ ("_"? ~ ASCII_DIGIT)* }
int = @{ SIGN? ~ dec_int }
// --------- rational -----------
rational = @{ int ~ "/" ~ dec_int }
// --------- float ---------------
float = @{
int ~ "." ~ dec_int
| SIGN? ~ "." ~ dec_int
}
// --------- string ----------
string = @{ "\"" ~ ALPHABETIC* ~ "\"" }
// --------- identifier ----------
SCHEME_ALPHA = _{
ALPHABETIC
| "-"
| "!"
| "$"
| "%"
| "^"
| "&"
| "*"
| "-"
| "_"
| "="
| "+"
| "<"
| "."
| ">"
| "/"
| "?"
}
identifier = @{ ALPHABETIC ~ (SCHEME_ALPHA*)? }
// --------- list ---------------
paren_list = { "(" ~ notation* ~ ")" }
bracket_list = { "[" ~ notation* ~ "]" }
list = { paren_list | bracket_list }
// --------- set ----------------
set = { "#{" ~ notation* ~ "}" }
// --------- object -------------
object = {
"{" ~ "}" |
"{" ~ object_pair ~ ("," ~ object_pair)* ~ ","? ~ "}"
}
unamed_object = {
"{" ~ "}" |
"{" ~ notation ~ ("," ~ notation)* ~ ","? ~ "}"
}
object_pair = {
identifier ~ ":" ~ notation
}
// --------- quote --------------
quote = { "'" ~ notation }
quasiquote = { "`" ~ notation }
unquote = { "," ~ notation }
unquote_splicing = { ",@" ~ notation }
// --------- syntax -------------
syntax = { "#'" ~ notation }
quasisyntax = { "#`" ~ notation }
unsyntax = { "#," ~ notation }
unsyntax_splicing = { "#,@" ~ notation }
literal = {
boolean
| char
| float
| rational
| int
| string
| identifier
}
container = {
list
| set
| unamed_object
| object
}
quoting = {
quote
| quasiquote
| unquote
| unquote_splicing
}
syntaxing = {
syntax
| quasisyntax
| unsyntax
| unsyntax_splicing
}
notation = {
literal
| container
| quoting
| syntaxing
}