Skip to content

Commit

Permalink
Merge pull request #56 from AI-Planning/parse-failures
Browse files Browse the repository at this point in the history
Subtle changes for better error handling and bug fix on missing elements
  • Loading branch information
haz authored May 12, 2023
2 parents 9ac95ea + 8be350e commit 75ecdf4
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
4 changes: 4 additions & 0 deletions pddl/parser/domain.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#

"""Implementation of the PDDL domain parser."""
import sys
from typing import Dict, Set

from lark import Lark, ParseError, Transformer
Expand Down Expand Up @@ -55,6 +56,7 @@ def start(self, args):

def domain(self, args):
"""Process the 'domain' rule."""
args = [arg for arg in args if arg is not None]
kwargs = {}
actions = []
derived_predicates = []
Expand Down Expand Up @@ -349,6 +351,8 @@ def __init__(self):

def __call__(self, text):
"""Call."""
sys.tracebacklimit = 0 # noqa
tree = self._parser.parse(text)
sys.tracebacklimit = None # noqa
formula = self._transformer.transform(tree)
return formula
7 changes: 7 additions & 0 deletions pddl/parser/problem.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#

"""Implementation of the PDDL problem parser."""
import sys
from typing import Dict

from lark import Lark, ParseError, Transformer
Expand Down Expand Up @@ -41,6 +42,10 @@ def start(self, args):

def problem(self, args):
"""Process the 'problem' rule."""
args = [arg for arg in args if arg is not None]
assert (
args[0].value + args[1].value + args[-1].value == "(define)"
), "Problem should start with '(define' and close with ')'"
return Problem(**dict(args[2:-1]))

def problem_def(self, args):
Expand Down Expand Up @@ -140,6 +145,8 @@ def __init__(self):

def __call__(self, text):
"""Call."""
sys.tracebacklimit = 0 # noqa
tree = self._parser.parse(text)
sys.tracebacklimit = None # noqa
formula = self._transformer.transform(tree)
return formula

0 comments on commit 75ecdf4

Please sign in to comment.