Skip to content

Commit

Permalink
Merge pull request #36 from gerlero/dictionaries
Browse files Browse the repository at this point in the history
Update parsing
  • Loading branch information
gerlero authored Mar 26, 2024
2 parents 4cb2313 + 98cde0d commit 57d70d7
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions foamlib/_dictionaries/_parsing.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
from ._values import FoamValue, FoamDimensionSet, FoamDimensioned


_YES = Keyword("yes").set_parse_action(lambda s, loc, tks: True)
_NO = Keyword("no").set_parse_action(lambda s, loc, tks: False)
_YES = Keyword("yes").set_parse_action(lambda: True)
_NO = Keyword("no").set_parse_action(lambda: False)
_DIMENSIONS = (
Literal("[").suppress() + common.number * 7 + Literal("]").suppress()
).set_parse_action(lambda s, loc, tks: FoamDimensionSet(*tks))
).set_parse_action(lambda tks: FoamDimensionSet(*tks))
_TOKEN = common.identifier | QuotedString('"', unquote_results=False)
_ITEM = Forward()
_LIST = Opt(
Expand All @@ -33,21 +33,21 @@
)
| (
common.integer + Literal("{").suppress() + _ITEM + Literal("}").suppress()
).set_parse_action(lambda s, loc, tks: [tks[1]] * tks[0])
).set_parse_action(lambda tks: [tks[1]] * tks[0])
)
_FIELD = (Keyword("uniform").suppress() + _ITEM) | (
Keyword("nonuniform").suppress() + _LIST
)
_DIMENSIONED = (Opt(common.identifier) + _DIMENSIONS + _ITEM).set_parse_action(
lambda s, loc, tks: FoamDimensioned(*reversed(tks.as_list()))
lambda tks: FoamDimensioned(*reversed(tks.as_list()))
)
_ITEM <<= (
_FIELD | _LIST | _DIMENSIONED | _DIMENSIONS | common.number | _YES | _NO | _TOKEN
)

_TOKENS = (QuotedString('"', unquote_results=False) | Word(printables))[
1, ...
].set_parse_action(lambda s, loc, tks: " ".join(tks))
].set_parse_action(lambda tks: " ".join(tks))

_VALUE = _ITEM ^ _TOKENS

Expand Down

0 comments on commit 57d70d7

Please sign in to comment.