Repository: gerlero/foamlib

Issue:
div((nuEff*dev2(T(grad(U))))) parsing
Hi again, so I think I have found another issue with the parsing in the `fvSchemes` file for the `divSchemes` when trying to parse the following line `div((nuEff*dev2(T(grad(U)))))`. I think this is a valid keyword?

```py
from pathlib import Path
from foamlib import FoamFile

Path("./system").mkdir(exist_ok=True)
file = open('./system/fvSchemes', 'w')
file.close()
fv_schemes = {
    'divSchemes': {
        'default': 'none',
        'div((nuEff*dev2(T(grad(U)))))': 'Gauss linear',
        'div(phi,U)': 'bounded Gauss upwind'
    },
}
file = FoamFile(path='./system/fvSchemes')
file.update(fv_schemes)
```

```sh
Traceback (most recent call last):
  File ".../test.py", line 15, in <module>
    file.update(fv_schemes)
  File ".../.venv/lib/python3.12/site-packages/foamlib/_files/_files.py", line 359, in update
    super().update(*args, **kwargs)
  File "<frozen _collections_abc>", line 982, in update
  File ".../.venv/lib/python3.12/site-packages/foamlib/_files/_files.py", line 307, in __setitem__
    self[(*keywords, k)] = v
    ~~~~^^^^^^^^^^^^^^^^
  File ".../.venv/lib/python3.12/site-packages/foamlib/_files/_files.py", line 200, in __setitem__
    raise ValueError(msg)
ValueError: Invalid keyword: div((nuEff*dev2(T(grad(U)))))
~``

Discussion:

Fix (patch):
diff --git a/foamlib/_files/_parsing.py b/foamlib/_files/_parsing.py
index 31be86c..1ecf502 100644
--- a/foamlib/_files/_parsing.py
+++ b/foamlib/_files/_parsing.py
@@ -235,11 +235,12 @@ _TENSOR = (
     | _tensor(TensorKind.SYMM_TENSOR)
     | _tensor(TensorKind.TENSOR)
 )
-_IDENTIFIER = Forward()
-_IDENTIFIER <<= Combine(
-    Word(_IDENTCHARS, _IDENTBODYCHARS, exclude_chars="()")
-    + Opt(Literal("(") + _IDENTIFIER + Literal(")"))
+_PARENTHESIZED = Forward()
+_IDENTIFIER = Combine(
+    Word(_IDENTCHARS, _IDENTBODYCHARS, exclude_chars="()") + Opt(_PARENTHESIZED)
 )
+_PARENTHESIZED <<= Combine(Literal("(") + (_PARENTHESIZED | _IDENTIFIER) + Literal(")"))
+
 _DIMENSIONED = (Opt(_IDENTIFIER) + _DIMENSIONS + _TENSOR).set_parse_action(
     lambda tks: Dimensioned(*reversed(tks.as_list()))
 )


Test changes:
diff --git a/tests/test_files/test_parsing.py b/tests/test_files/test_parsing.py
index 140b899..486a22c 100644
--- a/tests/test_files/test_parsing.py
+++ b/tests/test_files/test_parsing.py
@@ -93,6 +93,7 @@ def test_parse_value() -> None:
     assert Parsed(b"(water oil mercury air)")[()] == ["water", "oil", "mercury", "air"]
     assert Parsed(b"div(phi,U)")[()] == "div(phi,U)"
     assert Parsed(b"div(nuEff*dev(T(grad(U))))")[()] == "div(nuEff*dev(T(grad(U))))"
+    assert Parsed(b"div((nuEff*dev(T(grad(U)))))")[()] == "div((nuEff*dev(T(grad(U)))))"
     assert Parsed(b"((air and water) { type constant; sigma 0.07; })")[()] == [
         (["air", "and", "water"], {"type": "constant", "sigma": 0.07})
     ]