pddl-core 0.5.0

The types and the parser behind the pddl crate; depend on pddl instead
Documentation
//! Pretty-printing of names, variables and function symbols.

use crate::pretty_print::{sealed, PrettyRenderer};
use crate::types::{FunctionSymbol, Name, Variable};
use crate::visitor::Visitor;
use pretty::RcDoc;

impl sealed::Sealed for Name {}
impl sealed::Sealed for Variable {}
impl sealed::Sealed for FunctionSymbol {}

impl Visitor<Name, RcDoc<'static>> for PrettyRenderer {
    fn visit(&self, value: &Name) -> RcDoc<'static> {
        RcDoc::text(value.to_string())
    }
}

impl Visitor<Variable, RcDoc<'static>> for PrettyRenderer {
    fn visit(&self, value: &Variable) -> RcDoc<'static> {
        RcDoc::text(value.to_string())
    }
}

impl Visitor<FunctionSymbol, RcDoc<'static>> for PrettyRenderer {
    fn visit(&self, value: &FunctionSymbol) -> RcDoc<'static> {
        RcDoc::text(value.to_string())
    }
}

#[cfg(test)]
mod tests {
    use super::*;
    use crate::pretty_print::prettify;
    use crate::visitor::Accept;
    use assert2::check;

    #[test]
    fn name_works() {
        let x = Name::new("name");
        check!(prettify!(x, 10) == "name");
    }

    #[test]
    fn variable_works() {
        let x = Variable::from("var");
        check!(prettify!(x, 10) == "?var");
    }

    #[test]
    fn function_symbol_works() {
        let x = FunctionSymbol::from("fun-sym");
        check!(prettify!(x, 10) == "fun-sym");
    }
}