pddl-core 0.5.0

The types and the parser behind the pddl crate; depend on pddl instead
Documentation
//! Provides parsers for predicates (`<predicate>`).

use crate::parsers::error::R;
use crate::parsers::parse_name;
use crate::parsers::sexpr::Node;
use crate::types::Predicate;

/// Parses a predicate (`<predicate>`), i.e. `<name>`.
pub(crate) fn parse_predicate(node: &Node) -> R<Predicate> {
    parse_name(node).map(Predicate::from)
}

crate::parsers::impl_parser!(Predicate => parse_predicate);

#[cfg(test)]
mod tests {
    use crate::parsers::UnwrapValue;
    use crate::{Parser, Predicate};
    use assert2::check;

    #[test]
    fn test_parse() {
        check!(Predicate::from_str("abcde").is_value("abcde".into()));
        check!(Predicate::from_str("a-1_2").is_value("a-1_2".into()));
        check!(Predicate::from_str("Z01").is_value("Z01".into()));
        check!(Predicate::from_str("x-_-_").is_value("x-_-_".into()));
        check!(Predicate::from_str("").is_err());
        check!(Predicate::from_str(".").is_err());
        check!(Predicate::from_str("-abc").is_err());
        check!(Predicate::from_str("0124").is_err());
        check!(Predicate::from_str("-1").is_err());
    }
}