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