Skip to content

Commit

Permalink
Some minor touchup to preconditions and fix for minus.
Browse files Browse the repository at this point in the history
  • Loading branch information
haz committed Dec 28, 2023
1 parent 7a0132d commit e1227b5
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 6 deletions.
6 changes: 2 additions & 4 deletions pddl/parser/domain.lark
Original file line number Diff line number Diff line change
Expand Up @@ -67,17 +67,15 @@ constant: NAME
| GREATER_EQUAL_OP
| LESSER_EQUAL_OP

?binary_op: multi_op
| MINUS
?binary_op: MINUS
| DIVIDE

?multi_op: TIMES
| PLUS

f_exp: NUMBER
| LPAR binary_op f_exp f_exp RPAR
| LPAR multi_op f_exp f_exp+ RPAR
| LPAR MINUS f_exp RPAR
| LPAR multi_op f_exp+ RPAR
| f_head

f_head: NAME
Expand Down
7 changes: 6 additions & 1 deletion pddl/parser/domain.py
Original file line number Diff line number Diff line change
Expand Up @@ -462,8 +462,13 @@ def __init__(self):

def __call__(self, text):
"""Call."""
def handle_debug(e):
print("\nLocation of parse error:")
print(e.get_context(text))
print(e.interactive_parser.pretty())
print()
sys.tracebacklimit = 0 # noqa
tree = self._parser.parse(text)
tree = self._parser.parse(text, on_error=handle_debug)
sys.tracebacklimit = None # noqa
formula = self._transformer.transform(tree)
return formula
7 changes: 6 additions & 1 deletion pddl/parser/problem.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,8 +244,13 @@ def __init__(self):

def __call__(self, text):
"""Call."""
def handle_debug(e):
print("\nLocation of parse error:")
print(e.get_context(text))
print(e.interactive_parser.pretty())
print()
sys.tracebacklimit = 0 # noqa
tree = self._parser.parse(text)
tree = self._parser.parse(text, on_error=handle_debug)
sys.tracebacklimit = None # noqa
formula = self._transformer.transform(tree)
return formula
28 changes: 28 additions & 0 deletions tests/test_parser/test_domain.py
Original file line number Diff line number Diff line change
Expand Up @@ -317,3 +317,31 @@ def test_check_action_costs_requirement_with_total_cost() -> None:
match=r"action costs requirement is not specified, but the total-cost function is specified.",
):
DomainParser()(domain_str)


def test_minus_in_precondition() -> None:
"""Check minus in precondition."""
domain_str = dedent(
"""
(define (domain cant-subtract-in-precondition)
(:requirements :strips :typing :numeric-fluents)
(:types
agent - object
)
(:functions
(x ?l - agent)
)
(:action move-south
:parameters (?ag - agent)
:precondition (and
(< (- (x ?ag) 1) 1)
)
:effect (and (decrease (x ?ag) 1))
)
)
"""
)
DomainParser()(domain_str)

0 comments on commit e1227b5

Please sign in to comment.