Skip to content

Commit 59e4283

Browse files
committed
test(lark): debugging ambiguity
1 parent 45702d6 commit 59e4283

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

flopy4/mf6/io/parser.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ def make_parser(
8484
params: Iterable[str],
8585
dict_blocks: Iterable[str],
8686
list_blocks: Iterable[str],
87+
**kwargs,
8788
):
8889
"""
8990
Create a parser for the MODFLOW 6 input language with the given
@@ -109,4 +110,4 @@ def make_parser(
109110
f"LISTBLOCK: ({list_blocks})",
110111
]
111112
)
112-
return Lark(grammar, start="component")
113+
return Lark(grammar, start="component", **kwargs)

test/test_lark.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,18 +34,20 @@
3434
params=["k", "i", "d", "s", "f", "a"],
3535
dict_blocks=["options", "packagedata"],
3636
list_blocks=["period"],
37+
debug=True,
38+
# ambiguity="explicit" # uncomment to see ambiguous parse tree
3739
)
3840
MF6_TRANSFORMER = MF6Transformer()
3941

4042

4143
def test_parse_mf6():
4244
tree = MF6_PARSER.parse(COMPONENT)
43-
# view the parse tree with e.g.
44-
# pytest test/test_lark.py::test_parse -s
45+
# pytest -s to view the parse tree
4546
print(linesep + tree.pretty())
4647

4748

4849
def test_transform_mf6():
50+
# fails with ambiguity="explicit"
4951
tree = MF6_PARSER.parse(COMPONENT)
5052
data = MF6_TRANSFORMER.transform(tree)
5153
assert data["options"] == {

0 commit comments

Comments
 (0)