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)* ~ "*/" }
single_comment = { "//" ~ (!NEWLINE ~ ANY)* }
identifier = { ASCII_ALPHA+ ~ (ASCII_ALPHA | ASCII_DIGIT | "_")* }
rvalue = { (!";" ~ ANY)+ }
rvalue = { ('a'..'z' | 'A'..'Z' | '0'..'9' | "_" | ".")+ }
attribution = { identifier ~ whitespace+ ~ rvalue ~ ";" }
dictionary = { identifier ~ whitespace+ ~ "{" ~ (dictionary | attribution | whitespace)+ ~ "}" }
list_size = _{ ASCII_DIGIT+ ~ whitespace+ }
list = { identifier ~ whitespace+ ~ list_size? ~ "(" ~ (rvalue | whitespace)+ ~ ");" }
file = { SOI ~ (
whitespace
| multi_comment
| single_comment
| dictionary
| list
| attribution)*
~ EOI }

28
pestfoamtest/src/lib.rs

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