From 6707b97ef5473c6a888870675796b7351757d265 Mon Sep 17 00:00:00 2001 From: ElnuDev Date: Sat, 27 May 2023 13:19:45 -0700 Subject: [PATCH] Use PascalCase for exposed pest grammar --- renrs/src/lib.rs | 14 +++++++------- renrs/src/rpy.pest | 32 +++++++++++++++++--------------- 2 files changed, 24 insertions(+), 22 deletions(-) diff --git a/renrs/src/lib.rs b/renrs/src/lib.rs index 916dd69..02e146f 100644 --- a/renrs/src/lib.rs +++ b/renrs/src/lib.rs @@ -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!(), } } diff --git a/renrs/src/rpy.pest b/renrs/src/rpy.pest index 0834d09..a8b69c6 100644 --- a/renrs/src/rpy.pest +++ b/renrs/src/rpy.pest @@ -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 }