From 07f286e0d79ae23169f8816a6d93f3f5c5ba54cd Mon Sep 17 00:00:00 2001 From: Julio Biason Date: Wed, 15 Feb 2023 09:49:41 -0300 Subject: [PATCH] Dicts in lists and lists in dicts --- pestfoamtest/resources/blockMeshDict | 58 ++++++++++++++++++++++++++++ pestfoamtest/src/foam.pest | 15 +++++-- pestfoamtest/src/lib.rs | 9 +++++ 3 files changed, 79 insertions(+), 3 deletions(-) create mode 100644 pestfoamtest/resources/blockMeshDict diff --git a/pestfoamtest/resources/blockMeshDict b/pestfoamtest/resources/blockMeshDict new file mode 100644 index 0000000..7bdd3cb --- /dev/null +++ b/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) + ); + } +); + + +// ************************************************************************* // diff --git a/pestfoamtest/src/foam.pest b/pestfoamtest/src/foam.pest index f82e1e9..fa8afb4 100644 --- a/pestfoamtest/src/foam.pest +++ b/pestfoamtest/src/foam.pest @@ -2,13 +2,14 @@ whitespace = _{ " " | "\t" | "\r" | "\n" } multi_comment = { "/*" ~ (!"*/" ~ ANY)* ~ "*/" } single_comment = { "//" ~ (!NEWLINE ~ ANY)* } 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)+ } include = { "#" ~ identifier ~ middle ~ "\"" ~ identifier ~ "\"" } attribution = { identifier ~ middle ~ rvalue ~ ";" } dictionary = { identifier ~ middle ~ "{" ~ ( - dictionary + dictionary + | list | attribution | whitespace | multi_comment @@ -16,7 +17,15 @@ dictionary = { identifier ~ middle ~ "{" ~ ( | include )+ ~ "}" } 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 ~ ( whitespace diff --git a/pestfoamtest/src/lib.rs b/pestfoamtest/src/lib.rs index bd2cf20..0787445 100644 --- a/pestfoamtest/src/lib.rs +++ b/pestfoamtest/src/lib.rs @@ -125,10 +125,19 @@ mod file { 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] fn control_dict() { let text = include_bytes!("../resources/controlDict"); let parse = FoamParser::parse(Rule::file, &std::str::from_utf8(text).unwrap()); 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); + } }