pddl

package
v0.2.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 11, 2026 License: MIT Imports: 3 Imported by: 0

README

pddl

Package pddl parses PDDL (Planning Domain Definition Language) files and converts the resulting ASTs into graphplan domain types.

Supported requirements: :strips, :typing, :equality, :disjunctive-preconditions, :conditional-effects, :quantified-preconditions, and :derived-predicates.

Key Types

  • Adapter -- main entry point; wraps parse + convert in single calls
  • DomainAST -- parsed representation of a PDDL domain
  • ProblemAST -- parsed representation of a PDDL problem
  • FormulaAST -- interface for parsed formula trees (And, Or, Imply, Forall, Exists, When, Atom)
  • DerivedAST -- parsed derived predicate definition

Usage

Create an Adapter, call ParseDomain and ParseProblem:

adapter := pddl.NewAdapter()

domain, err := adapter.ParseDomain(domainPDDL)
if err != nil {
    log.Fatal(err)
}

problem, err := adapter.ParseProblem(problemPDDL, domain)
if err != nil {
    log.Fatal(err)
}

fmt.Printf("Domain: %s (%d operators)\n",
    domain.Name, len(domain.Operators))
fmt.Printf("Problem: %s (%d objects)\n",
    problem.Name, len(problem.Objects))

The returned *graphplan.Domain and *graphplan.Problem can be passed directly to graphplan.Solver.Solve.

See examples/parse_rocket/ for a complete working example.

Documentation

Overview

Package pddl provides a parser for PDDL (Planning Domain Definition Language) files. It supports STRIPS with :typing and :equality requirements as well as ADL features including :disjunctive-preconditions, :conditional-effects, :quantified-preconditions, and :derived-predicates. The parser handles universal and existential quantifiers (forall, exists), implication, disjunction (or), conditional effects (when), and derived predicate axioms. Parsed ASTs are converted to graphplan Formula trees and domain types.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConvertDomain

func ConvertDomain(
	ast *DomainAST,
) (*graphplan.Domain, error)

ConvertDomain converts a DomainAST into a graphplan.Domain.

func ConvertProblem

func ConvertProblem(
	ast *ProblemAST,
	domain *graphplan.Domain,
) (*graphplan.Problem, error)

ConvertProblem converts a ProblemAST into a graphplan.Problem, linking it to the given domain.

Types

type ActionAST

type ActionAST struct {
	Name         string
	Precondition FormulaAST
	Effect       FormulaAST
	Params       []TypedList
}

ActionAST is a parsed action schema.

type Adapter

type Adapter struct{}

Adapter wraps the PDDL parse and convert pipeline into single-call methods.

Pattern: Adapter -- translates PDDL parse/convert two-step into single-call interfaces.

func NewAdapter

func NewAdapter() *Adapter

NewAdapter creates a PDDL adapter.

func (*Adapter) ParseDomain

func (*Adapter) ParseDomain(
	input string,
) (*graphplan.Domain, error)

ParseDomain parses a PDDL domain string and converts it to a graphplan.Domain.

func (*Adapter) ParseProblem

func (*Adapter) ParseProblem(
	input string,
	domain *graphplan.Domain,
) (*graphplan.Problem, error)

ParseProblem parses a PDDL problem string and converts it to a graphplan.Problem.

type AndFormulaAST added in v0.2.2

type AndFormulaAST struct {
	Children []FormulaAST
}

AndFormulaAST is a parsed conjunction.

type AtomFormulaAST added in v0.2.2

type AtomFormulaAST struct {
	Predicate string
	Args      []string
	Negated   bool
}

AtomFormulaAST is a parsed atomic predicate.

type DerivedAST added in v0.2.2

type DerivedAST struct {
	Body   FormulaAST
	Name   string
	Params []TypedList
}

DerivedAST is a parsed derived predicate axiom.

type DomainAST

type DomainAST struct {
	Name         string
	Requirements []string
	Types        []TypedList
	Constants    []TypedList
	Predicates   []PredicateAST
	Actions      []ActionAST
	Derived      []DerivedAST
}

DomainAST is the parsed form of a PDDL domain.

func ParseDomain

func ParseDomain(input string) (*DomainAST, error)

ParseDomain parses a PDDL domain definition and returns the corresponding AST.

type ExistsFormulaAST added in v0.2.2

type ExistsFormulaAST struct {
	Body FormulaAST
	Vars []TypedList
}

ExistsFormulaAST is a parsed existential quantifier.

type ForallFormulaAST added in v0.2.2

type ForallFormulaAST struct {
	Body FormulaAST
	Vars []TypedList
}

ForallFormulaAST is a parsed universal quantifier.

type FormulaAST added in v0.2.2

type FormulaAST interface {
	// contains filtered or unexported methods
}

FormulaAST is the parsed representation of a logical formula.

type ImplyFormulaAST added in v0.2.2

type ImplyFormulaAST struct {
	Antecedent FormulaAST
	Consequent FormulaAST
}

ImplyFormulaAST is a parsed implication.

type Lexer

type Lexer struct {
	// contains filtered or unexported fields
}

Lexer tokenizes PDDL input. It handles comments (;), parentheses, keywords (:keyword), variables (?var), dashes, and bare names.

func NewLexer

func NewLexer(input string) *Lexer

NewLexer creates a lexer for the given PDDL source.

func (*Lexer) Next

func (l *Lexer) Next() Token

Next returns the next token. Returns TokenEOF at end of input.

type LiteralAST

type LiteralAST struct {
	Predicate string
	Args      []string
	Negated   bool
}

LiteralAST is a predicate application, possibly negated.

type OrFormulaAST added in v0.2.2

type OrFormulaAST struct {
	Children []FormulaAST
}

OrFormulaAST is a parsed disjunction.

type ParseError

type ParseError struct {
	Message string
	Line    int
	Col     int
}

ParseError reports a syntax error with position.

func (*ParseError) Error

func (e *ParseError) Error() string

Error implements the error interface.

type PredicateAST

type PredicateAST struct {
	Name   string
	Params []TypedList
}

PredicateAST is a predicate declaration.

type ProblemAST

type ProblemAST struct {
	Name    string
	Domain  string
	Goal    FormulaAST
	Objects []TypedList
	Init    []LiteralAST
}

ProblemAST is the parsed form of a PDDL problem.

func ParseProblem

func ParseProblem(
	input string,
) (*ProblemAST, error)

ParseProblem parses a PDDL problem definition and returns the corresponding AST.

type Token

type Token struct {
	Text string
	Kind TokenKind
	Line int
	Col  int
}

Token is a lexed PDDL token with source position.

type TokenKind

type TokenKind int

TokenKind identifies the type of a lexical token.

const (
	TokenLParen  TokenKind = iota // (
	TokenRParen                   // )
	TokenDash                     // -
	TokenName                     // name
	TokenVar                      // variable
	TokenKeyword                  // keyword
	TokenEOF                      // eof
)

func (TokenKind) String

func (i TokenKind) String() string

type TypedList

type TypedList struct {
	Type  string
	Names []string
}

TypedList represents "name1 name2 - type" groups.

type WhenFormulaAST added in v0.2.2

type WhenFormulaAST struct {
	Condition FormulaAST
	Effect    FormulaAST
}

WhenFormulaAST is a parsed conditional effect.

Directories

Path Synopsis
examples
parse_rocket command
Command parse_rocket parses the rocket PDDL files and prints the resulting domain and problem.
Command parse_rocket parses the rocket PDDL files and prints the resulting domain and problem.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL