Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue1030 #155

Merged
merged 7 commits into from
Jan 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 13 additions & 6 deletions src/translate/pddl/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,22 @@ def dump(self):
for axiom in self.axioms:
axiom.dump()


REQUIREMENT_LABELS = [
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since Python 3.8, there's a notion of Final: https://peps.python.org/pep-0591/

":strips", ":adl", ":typing", ":negation", ":equality",
":negative-preconditions", ":disjunctive-preconditions",
":existential-preconditions", ":universal-preconditions",
":quantified-preconditions", ":conditional-effects",
":derived-predicates", ":action-costs"
]


class Requirements:
def __init__(self, requirements: List[str]):
self.requirements = requirements
for req in requirements:
assert req in (
":strips", ":adl", ":typing", ":negation", ":equality",
":negative-preconditions", ":disjunctive-preconditions",
":existential-preconditions", ":universal-preconditions",
":quantified-preconditions", ":conditional-effects",
":derived-predicates", ":action-costs"), req
if req not in REQUIREMENT_LABELS:
raise ValueError(f"Invalid requirement. Got: {req}\n"
f"Expected: {', '.join(REQUIREMENT_LABELS)}")
def __str__(self):
return ", ".join(self.requirements)
1 change: 1 addition & 0 deletions src/translate/pddl_parser/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
from .parse_error import ParseError
from .pddl_file import open
19 changes: 8 additions & 11 deletions src/translate/pddl_parser/lisp_parser.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
__all__ = ["ParseError", "parse_nested_list"]
__all__ = ["parse_nested_list"]

class ParseError(Exception):
def __init__(self, value):
self.value = value
def __str__(self):
return self.value
from .parse_error import ParseError

# Basic functions for parsing PDDL (Lisp) files.
def parse_nested_list(input_file):
tokens = tokenize(input_file)
next_token = next(tokens)
if next_token != "(":
raise ParseError("Expected '(', got %s." % next_token)
raise ParseError(f"Expected '(', got '{next_token}'.")
result = list(parse_list_aux(tokens))
for tok in tokens: # Check that generator is exhausted.
raise ParseError("Unexpected token: %s." % tok)
remaining_tokens = list(tokens)
if remaining_tokens:
raise ParseError(f"Tokens remaining after parsing: "
f"{' '.join(remaining_tokens)}")
return result

def tokenize(input):
Expand All @@ -23,8 +21,7 @@ def tokenize(input):
try:
line.encode("ascii")
except UnicodeEncodeError:
raise ParseError("Non-ASCII character outside comment: %s" %
line[0:-1])
raise ParseError(f"Non-ASCII character outside comment: {line[0:-1]}")
line = line.replace("(", " ( ").replace(")", " ) ").replace("?", " ?")
for token in line.split():
yield token.lower()
Expand Down
2 changes: 2 additions & 0 deletions src/translate/pddl_parser/parse_error.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
class ParseError(Exception):
pass
Loading
Loading