Browse Source

Lists

master
Julio Biason 2 years ago
parent
commit
703c193053
  1. 5
      pestfoamtest/src/foam.pest
  2. 28
      pestfoamtest/src/lib.rs

5
pestfoamtest/src/foam.pest

@ -2,14 +2,17 @@ whitespace = _{ " " | "\t" | "\r" | "\n" }
multi_comment = { "/*" ~ (!"*/" ~ ANY)* ~ "*/" } multi_comment = { "/*" ~ (!"*/" ~ ANY)* ~ "*/" }
single_comment = { "//" ~ (!NEWLINE ~ ANY)* } single_comment = { "//" ~ (!NEWLINE ~ ANY)* }
identifier = { ASCII_ALPHA+ ~ (ASCII_ALPHA | ASCII_DIGIT | "_")* } identifier = { ASCII_ALPHA+ ~ (ASCII_ALPHA | ASCII_DIGIT | "_")* }
rvalue = { (!";" ~ ANY)+ } rvalue = { ('a'..'z' | 'A'..'Z' | '0'..'9' | "_" | ".")+ }
attribution = { identifier ~ whitespace+ ~ rvalue ~ ";" } attribution = { identifier ~ whitespace+ ~ rvalue ~ ";" }
dictionary = { identifier ~ whitespace+ ~ "{" ~ (dictionary | attribution | whitespace)+ ~ "}" } dictionary = { identifier ~ whitespace+ ~ "{" ~ (dictionary | attribution | whitespace)+ ~ "}" }
list_size = _{ ASCII_DIGIT+ ~ whitespace+ }
list = { identifier ~ whitespace+ ~ list_size? ~ "(" ~ (rvalue | whitespace)+ ~ ");" }
file = { SOI ~ ( file = { SOI ~ (
whitespace whitespace
| multi_comment | multi_comment
| single_comment | single_comment
| dictionary | dictionary
| list
| attribution)* | attribution)*
~ EOI } ~ EOI }

28
pestfoamtest/src/lib.rs

@ -31,8 +31,7 @@ mod test {
#[test] #[test]
fn chained_comments() { fn chained_comments() {
let text = "/* this is one comment */ let text = "/* this is one comment */\n// And this is another";
// And this is another";
let parse = Foam::parse(Rule::file, text); let parse = Foam::parse(Rule::file, text);
assert!(parse.is_ok(), "{:?}", parse); assert!(parse.is_ok(), "{:?}", parse);
} }
@ -69,14 +68,7 @@ mod test {
#[test] #[test]
fn dictionary() { fn dictionary() {
let text = "FoamFile let text = "FoamFile\n{\nversion 2.0;\nformat ascii;\nclass dictionary;\nlocation system;\nobject caseSetupDict;\n}";
{
version 2.0;
format ascii;
class dictionary;
location system;
object caseSetupDict;
}";
let parse = Foam::parse(Rule::dictionary, text); let parse = Foam::parse(Rule::dictionary, text);
assert!(parse.is_ok(), "{:#?}", parse); assert!(parse.is_ok(), "{:#?}", parse);
} }
@ -85,6 +77,20 @@ mod test {
fn dict_in_dict() { fn dict_in_dict() {
let text = "dict1 { dict2 { class bad; } }"; let text = "dict1 { dict2 { class bad; } }";
let parse = Foam::parse(Rule::dictionary, text); let parse = Foam::parse(Rule::dictionary, text);
assert!(parse.is_err(), "{:#?}", parse); assert!(parse.is_ok(), "{:#?}", parse);
}
#[test]
fn list() {
let text = "list_name ( 1 2 3 );";
let parse = Foam::parse(Rule::list, text);
assert!(parse.is_ok(), "{:#?}", parse);
}
#[test]
fn sized_list() {
let text = "list_name 3 ( 1 2 3 );";
let parse = Foam::parse(Rule::list, text);
assert!(parse.is_ok(), "{:#?}", parse);
} }
} }

Loading…
Cancel
Save