Browse Source

Dicts in lists and lists in dicts

master
Julio Biason 2 years ago
parent
commit
07f286e0d7
  1. 58
      pestfoamtest/resources/blockMeshDict
  2. 13
      pestfoamtest/src/foam.pest
  3. 9
      pestfoamtest/src/lib.rs

58
pestfoamtest/resources/blockMeshDict

@ -0,0 +1,58 @@
/*--------------------------------*- C++ -*----------------------------------*\
| ========= | |
| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
| \\ / O peration | Version: v2212 |
| \\ / A nd | Website: www.openfoam.com |
| \\/ M anipulation | |
\*---------------------------------------------------------------------------*/
FoamFile
{
version 2.0;
format ascii;
class dictionary;
object blockMeshDict;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
scale 1;
vertices
(
( -6.0 -0.5 -0.1)
( 0.5 -0.5 -0.1)
( 0.5 5.0 -0.1)
( -6.0 5.0 -0.1)
( -6.0 -0.5 2.9)
( 0.5 -0.5 2.9)
( 0.5 5.0 2.9)
( -6.0 5.0 2.9)
);
blocks
(
hex (0 1 2 3 4 5 6 7) (65 55 30) simpleGrading (1 1 1)
);
edges
(
);
boundary
(
allBoundary
{
type patch;
faces
(
(3 7 6 2)
(0 4 7 3)
(2 6 5 1)
(1 5 4 0)
(0 3 2 1)
(4 5 6 7)
);
}
);
// ************************************************************************* //

13
pestfoamtest/src/foam.pest

@ -2,13 +2,14 @@ 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 = { ('a'..'z' | 'A'..'Z' | '0'..'9' | "_" | ".")+ } rvalue = { ('a'..'z' | 'A'..'Z' | '0'..'9' | "_" | "." | "-")+ }
middle = { (whitespace | multi_comment)+ } middle = { (whitespace | multi_comment)+ }
include = { "#" ~ identifier ~ middle ~ "\"" ~ identifier ~ "\"" } include = { "#" ~ identifier ~ middle ~ "\"" ~ identifier ~ "\"" }
attribution = { identifier ~ middle ~ rvalue ~ ";" } attribution = { identifier ~ middle ~ rvalue ~ ";" }
dictionary = { identifier ~ middle ~ "{" ~ ( dictionary = { identifier ~ middle ~ "{" ~ (
dictionary dictionary
| list
| attribution | attribution
| whitespace | whitespace
| multi_comment | multi_comment
@ -16,7 +17,15 @@ dictionary = { identifier ~ middle ~ "{" ~ (
| include | include
)+ ~ "}" } )+ ~ "}" }
list_size = _{ ASCII_DIGIT+ ~ whitespace+ } list_size = _{ ASCII_DIGIT+ ~ whitespace+ }
list = { identifier ~ middle ~ list_size? ~ "(" ~ (rvalue | whitespace | multi_comment | single_comment)+ ~ ");" } list_middle = { "(" ~ (
dictionary
| rvalue
| list_middle
| whitespace
| multi_comment
| single_comment
)+ ~ ")" }
list = { identifier ~ middle ~ list_size? ~ list_middle ~ ";" }
file = { SOI ~ ( file = { SOI ~ (
whitespace whitespace

9
pestfoamtest/src/lib.rs

@ -125,10 +125,19 @@ mod file {
assert!(parse.is_ok(), "{:?}", parse); assert!(parse.is_ok(), "{:?}", parse);
} }
// Note: the following files were retrieved from OpenFoam examples:
// https://develop.openfoam.com/Development/openfoam/-/tree/develop/tutorials/incompressible/pimpleFoam/RAS/rotatingFanInRoom/system
#[test] #[test]
fn control_dict() { fn control_dict() {
let text = include_bytes!("../resources/controlDict"); let text = include_bytes!("../resources/controlDict");
let parse = FoamParser::parse(Rule::file, &std::str::from_utf8(text).unwrap()); let parse = FoamParser::parse(Rule::file, &std::str::from_utf8(text).unwrap());
assert!(parse.is_ok(), "{:?}", parse); assert!(parse.is_ok(), "{:?}", parse);
} }
#[test]
fn block_mesh_dict() {
let text = include_bytes!("../resources/blockMeshDict");
let parse = FoamParser::parse(Rule::file, &std::str::from_utf8(text).unwrap());
assert!(parse.is_ok(), "{:?}", parse);
}
} }

Loading…
Cancel
Save