Skip to content

Commit

Permalink
Update parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
gerlero committed Apr 1, 2024
1 parent 1ab32f8 commit d8362da
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 25 deletions.
2 changes: 1 addition & 1 deletion foamlib/_dictionaries.py
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ def _list_of(elem: ParserElement) -> ParserElement:
Opt(common.integer).suppress()
+ (
Literal("(").suppress()
+ Group((elem)[...]).set_parse_action(lambda tks: tks.as_list())
+ Group((elem)[...], aslist=True)
+ Literal(")").suppress()
)
)
Expand Down
48 changes: 24 additions & 24 deletions tests/test_dictionaries.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,59 +11,59 @@


def test_parse_value() -> None:
assert _VALUE.parse_string("1").as_list()[0] == 1
assert _VALUE.parse_string("1.0").as_list()[0] == 1.0
assert _VALUE.parse_string("1.0e-3").as_list()[0] == 1.0e-3
assert _VALUE.parse_string("yes").as_list()[0] is True
assert _VALUE.parse_string("no").as_list()[0] is False
assert _VALUE.parse_string("word").as_list()[0] == "word"
assert _VALUE.parse_string("word word").as_list()[0] == "word word"
assert _VALUE.parse_string('"a string"').as_list()[0] == '"a string"'
assert _VALUE.parse_string("uniform 1").as_list()[0] == 1
assert _VALUE.parse_string("uniform 1.0").as_list()[0] == 1.0
assert _VALUE.parse_string("uniform 1.0e-3").as_list()[0] == 1.0e-3
assert _VALUE.parse_string("(1.0 2.0 3.0)").as_list()[0] == [1.0, 2.0, 3.0]
assert _VALUE.parse_string("uniform (1 2 3)").as_list()[0] == [1, 2, 3]
assert _VALUE.parse_string("nonuniform List<scalar> 2(1 2)").as_list()[0] == [1, 2]
assert _VALUE.parse_string("nonuniform List<scalar> 2{1}").as_list()[0] == [1, 1]
assert _VALUE.parse_string("3(1 2 3)").as_list()[0] == [1, 2, 3]
assert _VALUE.parse_string("2((1 2 3) (4 5 6))").as_list()[0] == [
assert _VALUE.parse_string("1")[0] == 1
assert _VALUE.parse_string("1.0")[0] == 1.0
assert _VALUE.parse_string("1.0e-3")[0] == 1.0e-3
assert _VALUE.parse_string("yes")[0] is True
assert _VALUE.parse_string("no")[0] is False
assert _VALUE.parse_string("word")[0] == "word"
assert _VALUE.parse_string("word word")[0] == "word word"
assert _VALUE.parse_string('"a string"')[0] == '"a string"'
assert _VALUE.parse_string("uniform 1")[0] == 1
assert _VALUE.parse_string("uniform 1.0")[0] == 1.0
assert _VALUE.parse_string("uniform 1.0e-3")[0] == 1.0e-3
assert _VALUE.parse_string("(1.0 2.0 3.0)")[0] == [1.0, 2.0, 3.0]
assert _VALUE.parse_string("uniform (1 2 3)")[0] == [1, 2, 3]
assert _VALUE.parse_string("nonuniform List<scalar> 2(1 2)")[0] == [1, 2]
assert _VALUE.parse_string("nonuniform List<scalar> 2{1}")[0] == [1, 1]
assert _VALUE.parse_string("3(1 2 3)")[0] == [1, 2, 3]
assert _VALUE.parse_string("2((1 2 3) (4 5 6))")[0] == [
[1, 2, 3],
[4, 5, 6],
]
assert _VALUE.parse_string("2{(1 2 3)}").as_list()[0] == [
assert _VALUE.parse_string("2{(1 2 3)}")[0] == [
[1, 2, 3],
[1, 2, 3],
]
assert _VALUE.parse_string("nonuniform List<vector> 2((1 2 3) (4 5 6))").as_list()[
assert _VALUE.parse_string("nonuniform List<vector> 2((1 2 3) (4 5 6))")[
0
] == [
[1, 2, 3],
[4, 5, 6],
]
assert _VALUE.parse_string("nonuniform List<vector> 2{(1 2 3)}").as_list()[0] == [
assert _VALUE.parse_string("nonuniform List<vector> 2{(1 2 3)}")[0] == [
[1, 2, 3],
[1, 2, 3],
]
assert _VALUE.parse_string("[1 1 -2 0 0 0 0]").as_list()[
assert _VALUE.parse_string("[1 1 -2 0 0 0 0]")[
0
] == FoamFile.DimensionSet(mass=1, length=1, time=-2)
assert _VALUE.parse_string("g [1 1 -2 0 0 0 0] (0 0 -9.81)").as_list()[
assert _VALUE.parse_string("g [1 1 -2 0 0 0 0] (0 0 -9.81)")[
0
] == FoamFile.Dimensioned(
name="g",
dimensions=FoamFile.DimensionSet(mass=1, length=1, time=-2),
value=[0, 0, -9.81],
)
assert _VALUE.parse_string("[1 1 -2 0 0 0 0] 9.81").as_list()[
assert _VALUE.parse_string("[1 1 -2 0 0 0 0] 9.81")[
0
] == FoamFile.Dimensioned(
dimensions=FoamFile.DimensionSet(mass=1, length=1, time=-2), value=9.81
)
assert (
_VALUE.parse_string(
"hex (0 1 2 3 4 5 6 7) (1 1 1) simpleGrading (1 1 1)"
).as_list()[0]
)[0]
== "hex (0 1 2 3 4 5 6 7) (1 1 1) simpleGrading (1 1 1)"
)

Expand Down

0 comments on commit d8362da

Please sign in to comment.