1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
//! Provides parsers for problem constraint definitions.
use nom::combinator::map;
use nom::Parser;
use crate::parsers::{parse_pref_con_gd, prefix_expr, ParseResult, Span};
use crate::types::ProblemConstraintsDef;
/// Parses problem constraint definitions, i.e. `(:constraints <pref-con-GD>)`.
///
/// ## Example
/// ```
/// # use pddl::parsers::{parse_problem_constraints_def, preamble::*};
/// # use pddl::{ConstraintGoalDefinition, ProblemConstraintsDef, PreferenceConstraintGoalDefinitions};
/// let input = "(:constraints (preference test (and)))";
/// assert!(parse_problem_constraints_def(input).is_value(
/// ProblemConstraintsDef::new(
/// PreferenceConstraintGoalDefinitions::preference(Some("test".into()), ConstraintGoalDefinition::and([]))
/// )
/// ));
/// ```
pub fn parse_problem_constraints_def<'a, T: Into<Span<'a>>>(
input: T,
) -> ParseResult<'a, ProblemConstraintsDef> {
// :constraints
map(
prefix_expr(":constraints", parse_pref_con_gd),
ProblemConstraintsDef::new,
)
.parse(input.into())
}
impl crate::parsers::Parser for ProblemConstraintsDef {
type Item = ProblemConstraintsDef;
/// See [`parse_problem_constraints_def`].
fn parse<'a, S: Into<Span<'a>>>(input: S) -> ParseResult<'a, Self::Item> {
parse_problem_constraints_def(input)
}
}
#[cfg(test)]
mod tests {
use crate::parsers::preamble::*;
use crate::{
ConstraintGoalDefinition, PreferenceConstraintGoalDefinitions, ProblemConstraintsDef,
};
#[test]
fn test_parse() {
let input = "(:constraints (preference test (and)))";
assert!(
ProblemConstraintsDef::parse(input).is_value(ProblemConstraintsDef::new(
PreferenceConstraintGoalDefinitions::preference(
Some("test".into()),
ConstraintGoalDefinition::and([])
)
))
);
}
}