Skip to content

Commit

Permalink
fix: problem optionally accepts requirements
Browse files Browse the repository at this point in the history
  • Loading branch information
marcofavorito committed Jun 7, 2023
1 parent 67d3b1d commit 124a60a
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 4 deletions.
7 changes: 5 additions & 2 deletions pddl/parser/problem.lark
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
start: problem

problem: LPAR DEFINE problem_def problem_domain [requirements] [objects] init goal RPAR
problem: LPAR DEFINE problem_def problem_domain [problem_requirements] [objects] init goal RPAR
problem_def: LPAR PROBLEM NAME RPAR
problem_domain: LPAR DOMAIN_P NAME RPAR

problem_requirements: LPAR REQUIREMENTS require_key+ RPAR


objects: LPAR OBJECTS typed_list_name RPAR

init: LPAR INIT init_el* RPAR
Expand All @@ -29,7 +32,7 @@ GOAL: ":goal"
%ignore COMMENT

%import .common.COMMENT -> COMMENT
%import .domain.requirements -> requirements
%import .domain.require_key -> require_key
%import .domain.typed_list_name -> typed_list_name
%import .domain.predicate -> predicate
%import .common.NAME -> NAME
Expand Down
2 changes: 1 addition & 1 deletion pddl/parser/problem.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def problem_domain(self, args):
"""Process the 'problem_domain' rule."""
return "domain_name", args[2]

def requirements(self, args):
def problem_requirements(self, args):
"""Process the 'requirements' rule."""
return "requirements", {Requirements(r[1:]) for r in args[2:-1]}

Expand Down
21 changes: 20 additions & 1 deletion tests/test_parser/test_problem.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@

"""This module contains the tests for the domain parser."""
from pathlib import Path
from textwrap import dedent

import pytest
from pytest import lazy_fixture # type:ignore # noqa

from pddl.core import Problem
from pddl.core import Problem, Requirements
from pddl.parser.problem import ProblemParser
from tests.conftest import BLOCKSWORLD_FILES, BLOCKSWORLD_FOND_FILES, PROBLEM_FILES


Expand Down Expand Up @@ -45,3 +47,20 @@ def test_check_problem_parser_output(problem_parser, pddl_file: Path, expected_p

assert isinstance(actual_problem, Problem)
assert actual_problem == expected_problem


def test_problem_requirements_section_parsed() -> None:
"""Check that the requirements section is parsed correctly."""
problem_str = dedent(
"""
(define (problem test-problem)
(:domain test-domain)
(:requirements :typing)
(:objects a b c)
(:init (p b b b))
(:goal (g a a a))
)"""
)
problem = ProblemParser()(problem_str)

assert problem.requirements == {Requirements.TYPING}

0 comments on commit 124a60a

Please sign in to comment.