diff --git a/pddl/parser/domain.py b/pddl/parser/domain.py index 82b1c13..0ce8307 100644 --- a/pddl/parser/domain.py +++ b/pddl/parser/domain.py @@ -296,8 +296,13 @@ def atomic_formula_skeleton(self, args): def typed_list_name(self, args) -> Dict[str, Optional[str]]: """Process the 'typed_list_name' rule.""" - types_index = TypesIndex.parse_typed_list(args) - return types_index.get_typed_list_of_names() + try: + types_index = TypesIndex.parse_typed_list(args) + return types_index.get_typed_list_of_names() + except ValueError as e: + raise PDDLParsingError( + f"error while parsing tokens {list(map(str, args))}: {str(e)}" + ) from None def typed_list_variable(self, args) -> Dict[str, Set[str]]: """ diff --git a/pddl/parser/types_index.py b/pddl/parser/types_index.py index b9b1f6f..54ae6f4 100644 --- a/pddl/parser/types_index.py +++ b/pddl/parser/types_index.py @@ -39,9 +39,11 @@ def __init__(self) -> None: def add_item(self, item_name: str, type_tags: Set[str]) -> None: """Add an item.""" if item_name in self._item_to_types: + types_list = sorted(map(str, self._item_to_types[item_name])) + types_list_str = f" with types {types_list}" if len(types_list) > 0 else "" raise ValueError( - f"duplicate name '{item_name}' in typed list: already present with " - f"types {sorted(map(str,self._item_to_types[item_name]))}" + f"duplicate name '{item_name}' in typed list already present" + + types_list_str ) exisiting_tags = self._item_to_types.get(item_name, set()) diff --git a/tests/test_parser.py b/tests/test_parser.py index a2e1332..c518260 100644 --- a/tests/test_parser.py +++ b/tests/test_parser.py @@ -135,8 +135,8 @@ def test_types_repetition_in_simple_typed_lists_not_allowed() -> None: with pytest.raises( lark.exceptions.VisitError, - match="duplicate items \\['a'\\] found in the typed list: " - "\\['a', 'b', 'c', 'a'\\]", + match=".*error while parsing tokens \\['a', 'b', 'c', 'a'\\]: " + "duplicate name 'a' in typed list already present", ): DomainParser()(domain_str) @@ -154,8 +154,8 @@ def test_types_repetition_in_typed_lists_not_allowed() -> None: with pytest.raises( lark.exceptions.VisitError, - match="detected conflicting items in a typed list: items occurred " - "twice: \\['a'\\]", + match=".*error while parsing tokens \\['a', '-', 't1', 'b', 'c', '-', 't2', 'a', '-', 't3'\\]: " + "duplicate name 'a' in typed list already present with types \\['t1'\\]", ): DomainParser()(domain_str) @@ -174,8 +174,8 @@ def test_constants_repetition_in_simple_typed_lists_not_allowed() -> None: with pytest.raises( lark.exceptions.VisitError, - match="duplicate items \\['c1'\\] found in the typed list: " - "\\['c1', 'c2', 'c3', 'c1'\\]", + match=".*error while parsing tokens \\['c1', 'c2', 'c3', 'c1'\\]: " + "duplicate name 'c1' in typed list already present", ): DomainParser()(domain_str) @@ -194,7 +194,7 @@ def test_constants_repetition_in_typed_lists_not_allowed() -> None: with pytest.raises( lark.exceptions.VisitError, - match="detected conflicting items in a typed list: items occurred " - "twice: \\['c1'\\]", + match=".*error while parsing tokens \\['c1', '-', 't1', 'c1', '-', 't2'\\]: " + "duplicate name 'c1' in typed list already present with types \\['t1'\\]", ): DomainParser()(domain_str)