Skip to main content

pddl_core/parsers/structure/
domain_constraints_def.rs

1//! Provides parsers for domain constraint definitions (`<constraints>`).
2
3use crate::parsers::error::R;
4use crate::parsers::sexpr::Node;
5use crate::parsers::{parse_con_gd, prefix};
6use crate::types::DomainConstraintsDef;
7
8/// Parses a domain constraint definition (`<constraints>`), i.e. `(:constraints <con-GD>)`.
9pub(crate) fn parse_domain_constraints_def(node: &Node) -> R<DomainConstraintsDef> {
10    prefix(node, ":constraints", |args| {
11        parse_con_gd(args.next()?).map(DomainConstraintsDef::new)
12    })
13}
14
15crate::parsers::impl_parser!(DomainConstraintsDef => parse_domain_constraints_def);
16
17#[cfg(test)]
18mod tests {
19    use crate::parsers::UnwrapValue;
20    use assert2::check;
21
22    use crate::*;
23
24    #[test]
25    fn test_parse() {
26        let input = "(:constraints (and))";
27        check!(
28            DomainConstraintsDef::from_str(input).is_value(DomainConstraintsDef::new(
29                ConstraintGoalDescription::and([])
30            ))
31        );
32    }
33
34    #[test]
35    fn doc_example_0() {
36        let input = "(:constraints (and))";
37        check!(
38            DomainConstraintsDef::from_str(input).is_value(DomainConstraintsDef::new(
39                ConstraintGoalDescription::and([])
40            ))
41        );
42    }
43}