Use PascalCase for exposed pest grammar

main
Elnu 2 years ago
parent f178baf1e6
commit 6707b97ef5

@ -178,15 +178,15 @@ fn parse_token(pair: Pair) -> Token {
};
}
match token {
Rule::string => {
Rule::String => {
let contents = contents!();
Token::Str(match contents.as_rule() {
Rule::single_quote_string_data => contents.as_str().replace("\\'", "'"),
Rule::double_quote_string_data => contents.as_str().replace("\\\"", "\""),
Rule::SingleQuoteStringData => contents.as_str().replace("\\'", "'"),
Rule::DoubleQuoteStringData => contents.as_str().replace("\\\"", "\""),
_ => unreachable!(),
})
}
Rule::array => {
Rule::Array => {
let contents = contents!();
let mut array = Vec::new();
for token in contents.into_inner() {
@ -194,13 +194,13 @@ fn parse_token(pair: Pair) -> Token {
}
Token::Array(array)
}
Rule::boolean => Token::Boolean(match pair.as_str() {
Rule::Boolean => Token::Boolean(match pair.as_str() {
"True" => true,
"False" => false,
_ => unreachable!(),
}),
Rule::number => Token::Number(pair.as_str().parse().unwrap()),
Rule::keyword => Token::Keyword(pair.as_str().to_owned()),
Rule::Number => Token::Number(pair.as_str().parse().unwrap()),
Rule::Keyword => Token::Keyword(pair.as_str().to_owned()),
__ => unreachable!(),
}
}

@ -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 }

Loading…
Cancel
Save