|
|
|
@ -1,52 +1,54 @@
|
|
|
|
|
// characters are anything but newlines
|
|
|
|
|
char = { !NEWLINE ~ ANY }
|
|
|
|
|
|
|
|
|
|
// token definition
|
|
|
|
|
// Token definition
|
|
|
|
|
// http://pest.rs/book/grammars/syntax.html#atomic
|
|
|
|
|
inner = @{ char* }
|
|
|
|
|
|
|
|
|
|
token = { string | array | boolean | number | keyword }
|
|
|
|
|
Token = { String | Array | Boolean | Number | Keyword }
|
|
|
|
|
|
|
|
|
|
// KEYWORDS
|
|
|
|
|
// has to be atomic for no implicit separate (spaces)
|
|
|
|
|
keyword = ${ (!(whitespace | NEWLINE) ~ ANY)+ }
|
|
|
|
|
Keyword = ${ (!(whitespace | NEWLINE) ~ ANY)+ }
|
|
|
|
|
|
|
|
|
|
// STRING
|
|
|
|
|
single_quote_string_data = @{ (
|
|
|
|
|
SingleQuoteStringData = @{ (
|
|
|
|
|
"\\'" // Escaped single quotes
|
|
|
|
|
| (!"'" ~ ANY)
|
|
|
|
|
)* }
|
|
|
|
|
double_quote_string_data = @{ (
|
|
|
|
|
DoubleQuoteStringData = @{ (
|
|
|
|
|
"\\\"" // Escaped double quotes
|
|
|
|
|
| (!"\"" ~ ANY)
|
|
|
|
|
)* }
|
|
|
|
|
string = ${
|
|
|
|
|
("'" ~ single_quote_string_data ~ "'")
|
|
|
|
|
| ("\"" ~ double_quote_string_data ~ "\"")
|
|
|
|
|
String = ${
|
|
|
|
|
("'" ~ SingleQuoteStringData ~ "'")
|
|
|
|
|
| ("\"" ~ DoubleQuoteStringData ~ "\"")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ARRAY
|
|
|
|
|
array = ${
|
|
|
|
|
// Array
|
|
|
|
|
Array = ${
|
|
|
|
|
"[" ~ "]"
|
|
|
|
|
| "[" ~ whitespace* ~ NEWLINE* ~ whitespace* ~ token ~ ("," ~ whitespace* ~ NEWLINE* ~ whitespace* ~ token)* ~ NEWLINE* ~ "]"
|
|
|
|
|
| "[" ~ whitespace* ~ NEWLINE* ~ whitespace* ~ Token ~ ("," ~ whitespace* ~ NEWLINE* ~ whitespace* ~ Token)* ~ NEWLINE* ~ "]"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// BOOLEAN
|
|
|
|
|
boolean = ${ "True" | "False" }
|
|
|
|
|
Boolean = ${ "True" | "False" }
|
|
|
|
|
|
|
|
|
|
// NUMBER
|
|
|
|
|
number = @{
|
|
|
|
|
Number = @{
|
|
|
|
|
"-"?
|
|
|
|
|
~ ("0" | ASCII_NONZERO_DIGIT ~ ASCII_DIGIT*)
|
|
|
|
|
~ ("." ~ ASCII_DIGIT*)?
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// comments are a # followed by
|
|
|
|
|
// any number of non-newline characters
|
|
|
|
|
// any Number of non-newline characters
|
|
|
|
|
COMMENT = _{ "#" ~ char* }
|
|
|
|
|
|
|
|
|
|
Colon = { ":" }
|
|
|
|
|
|
|
|
|
|
// lines are comprised of a statement
|
|
|
|
|
line = @{ (token ~ whitespace+)* ~ token }
|
|
|
|
|
line = @{ (Token ~ whitespace+)* ~ Token ~ Colon? }
|
|
|
|
|
|
|
|
|
|
file = { SOI ~ NEWLINE* ~ block_content* ~ NEWLINE* ~ EOI }
|
|
|
|
|
|
|
|
|
|