Skip to content

Commit

Permalink
fix: domain parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
francescofuggitti committed Oct 8, 2023
1 parent 850a09d commit 954465d
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 9 deletions.
18 changes: 9 additions & 9 deletions pddl/parser/domain.lark
Original file line number Diff line number Diff line change
Expand Up @@ -54,18 +54,18 @@ atomic_formula_term: LPAR predicate term* RPAR
?predicate: NAME
constant: NAME

binary_comp: GREATER_OP
| LESSER_OP
| EQUAL_OP
| GREATER_EQUAL_OP
| LESSER_EQUAL_OP
?binary_comp: GREATER_OP
| LESSER_OP
| EQUAL_OP
| GREATER_EQUAL_OP
| LESSER_EQUAL_OP

assign_op: INCREASE
| DECREASE
?assign_op: INCREASE
| DECREASE

f_exp: NUMBER
?f_exp: NUMBER
| f_head
?f_head: NAME
f_head: NAME
| LPAR NAME term* RPAR

typed_list_variable: variable*
Expand Down
20 changes: 20 additions & 0 deletions pddl/parser/domain.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
GreaterThan,
LesserEqualThan,
LesserThan,
Increase,
Decrease,
)
from pddl.logic.predicates import DerivedPredicate, EqualTo, Predicate
from pddl.logic.terms import Constant, Variable
Expand Down Expand Up @@ -282,6 +284,16 @@ def cond_effect(self, args):
assert_(len(args) == 1)
return args[0]

def num_effect(self, args):
"""Process the 'num_effect' rule."""
function = args[2]
value = args[3]
if args[1] == Symbols.INCREASE.value:
return Increase(function, value)
if args[1] == Symbols.DECREASE.value:
return Decrease(function, value)
raise PDDLParsingError("Assign operator not recognized")

def atomic_formula_term(self, args):
"""Process the 'atomic_formula_term' rule."""

Expand Down Expand Up @@ -331,6 +343,14 @@ def atomic_function_skeleton(self, args):
variables = self._formula_skeleton(args)
return Function(function_name, *variables)

def f_head(self, args):
"""Process the 'f_head' rule."""
if len(args) == 1:
return args[0]
function_name = args[1]
variables = [Variable(x, {}) for x in args[2:-1]]
return Function(function_name, *variables)

def typed_list_name(self, args) -> Dict[name, Optional[name]]:
"""Process the 'typed_list_name' rule."""
try:
Expand Down

0 comments on commit 954465d

Please sign in to comment.