From 308f028f4976f45df94c6f6960c29a3f59cb869f Mon Sep 17 00:00:00 2001 From: Julio Biason Date: Wed, 15 Feb 2023 09:38:53 -0300 Subject: [PATCH] #include support --- pestfoamtest/resources/controlDict | 59 ++++++++++++++++++++++++++++++ pestfoamtest/src/foam.pest | 11 +++++- pestfoamtest/src/lib.rs | 7 ++++ 3 files changed, 76 insertions(+), 1 deletion(-) create mode 100644 pestfoamtest/resources/controlDict diff --git a/pestfoamtest/resources/controlDict b/pestfoamtest/resources/controlDict new file mode 100644 index 0000000..0afcfdd --- /dev/null +++ b/pestfoamtest/resources/controlDict @@ -0,0 +1,59 @@ +/*--------------------------------*- 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 controlDict; +} +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +application pimpleFoam; + +startFrom latestTime; + +startTime 0; + +stopAt endTime; + +endTime 1; + +deltaT 0.0002; + +writeControl adjustable; + +writeInterval 0.02; + +purgeWrite 0; + +writeFormat ascii; + +writePrecision 7; + +writeCompression no; + +timeFormat general; + +timePrecision 6; + +runTimeModifiable yes; + +adjustTimeStep yes; + +maxCo 1; + +maxDeltaT 1; + +functions +{ + #include "relVelocity" +} + + +// ************************************************************************* // diff --git a/pestfoamtest/src/foam.pest b/pestfoamtest/src/foam.pest index c5795bf..f82e1e9 100644 --- a/pestfoamtest/src/foam.pest +++ b/pestfoamtest/src/foam.pest @@ -4,8 +4,17 @@ single_comment = { "//" ~ (!NEWLINE ~ ANY)* } identifier = { ASCII_ALPHA+ ~ (ASCII_ALPHA | ASCII_DIGIT | "_")* } rvalue = { ('a'..'z' | 'A'..'Z' | '0'..'9' | "_" | ".")+ } middle = { (whitespace | multi_comment)+ } + +include = { "#" ~ identifier ~ middle ~ "\"" ~ identifier ~ "\"" } attribution = { identifier ~ middle ~ rvalue ~ ";" } -dictionary = { identifier ~ middle ~ "{" ~ (dictionary | attribution | whitespace | multi_comment | single_comment)+ ~ "}" } +dictionary = { identifier ~ middle ~ "{" ~ ( + dictionary + | attribution + | whitespace + | multi_comment + | single_comment + | include + )+ ~ "}" } list_size = _{ ASCII_DIGIT+ ~ whitespace+ } list = { identifier ~ middle ~ list_size? ~ "(" ~ (rvalue | whitespace | multi_comment | single_comment)+ ~ ");" } diff --git a/pestfoamtest/src/lib.rs b/pestfoamtest/src/lib.rs index 48fecbb..bd2cf20 100644 --- a/pestfoamtest/src/lib.rs +++ b/pestfoamtest/src/lib.rs @@ -124,4 +124,11 @@ mod file { let parse = FoamParser::parse(Rule::file, text); assert!(parse.is_ok(), "{:?}", parse); } + + #[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); + } }