Code Monkey home page Code Monkey logo

pddl-rs's Introduction

A PDDL 3.1 parser, strongly typed

A parser for the Planning Domain Definition Language version 3.1: written in Rust, based on nom.

GitHub Workflow Status docs.rs codecov Crates.io Crates.io

Crate documentation is available on docs.rs/pddl.

[dependencies]
pddl = "*"

The domain/problem types can be used independently of the parser; the parser is however enabled by default via the parser crate feature. To disable the parser and its dependencies, use

[dependencies]
pddl = { version = "*", default-features = false }

Documentation comments are assembled from the PDDL papers and nergmada/planning-wiki.

Usage Example

See tests/briefcase_world.rs for the full example.

use pddl::{Problem, Parser};

pub const BRIEFCASE_WORLD_PROBLEM: &'static str = r#"
    (define (problem get-paid)
        (:domain briefcase-world)
        (:init (place home) (place office)                  ; place types
               (object p) (object d) (object b)             ; object types
               (at B home) (at P home) (at D home) (in P))  ; setup
        (:goal (and (at B office) (at D office) (at P home)))
    )
    "#;

fn main() {
    let problem = Problem::from_str(BRIEFCASE_WORLD_PROBLEM).unwrap();

    assert_eq!(problem.name(), "get-paid");
    assert_eq!(problem.domain(), "briefcase-world");
    assert!(problem.requirements().is_empty());
    assert_eq!(problem.init().len(), 9);
    assert_eq!(problem.goal().len(), 3);
}

Caveat Emptor

At this point the parser supports all domain and problem definition elements required to fully describe a PDDL 3.1 environment. However, since types and enum variants are named closely to the underlying BNF descriptions (see below), they may be a bit unwieldy to use still.

Supported Elements

Parsers were implemented based on the BNF elements listed in the paper:

"Complete BNF description of PDDL 3.1 (completely corrected)", Daniel L. Kovacs

See ELEMENTS.md for a graph of BNF elements.

pddl-rs's People

Contributors

sunsided avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

pddl-rs's Issues

Error when parsing file with comments (`;;`)

Cannot use pddl-rs to parse PDDL files containing comments (;;).

Using pddl = "0.0.6" in Cargo.toml

Code:

use pddl::{Parser, Problem};
use std::fs;

fn main() {
    let path = "./problem.pddl";
    let contents = fs::read_to_string(path).unwrap();

    let problem = Problem::from_str(&contents);

    println!("{:#?}", problem);
}

PDDL file (./problem.pddl):

(define (problem pb1)
    (:domain air-cargo)
    (:objects
        C1 C2 P1 P2 SFO JFK
    )
    (:init
        ;; types
        (Cargo C1)
        (Cargo C2)
        (Plane P1)
        (Plane P2)
        (Airport SFO)
        (Airport JFK)

        ;; locations
        (At C1 SFO)
        (At C2 JFK)
        (At P1 SFO)
        (At P2 JFK)
    )

    (:goal
        (and (At C1 JFK) (At C2 SFO))
    )
)

Error printed:

Err(
    Error(
        GreedyError {
            errors: [
                (
                    LocatedSpan {
                        offset: 113,
                        line: 7,
                        fragment: ";; types\n        (Cargo C1)\n        (Cargo C2)\n        (Plane P1)\n        (Plane P2)\n        (Airport SFO)\n        (Airport JFK)\n\n        ;; locations\n        (At C1 SFO)\n        (At C2 JFK)\n        (At P1 SFO)\n        (At P2 JFK)\n    )\n\n    (:goal\n        (and (At C1 JFK) (At C2 SFO))\n    )\n)",
                        extra: (),
                    },
                    Nom(
                        Tag,
                    ),
                ),
            ],
        },
    ),
)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.