pddl/parsers/
constants_def.rs1use nom::combinator::map;
4
5use crate::parsers::{parse_name, prefix_expr, typed_list, ParseResult, Span};
6use crate::types::Constants;
7
8pub fn parse_constants_def<'a, T: Into<Span<'a>>>(input: T) -> ParseResult<'a, Constants> {
24 map(prefix_expr(":constants", typed_list(parse_name)), |vec| {
25 Constants::new(vec)
26 })(input.into())
27}
28
29impl crate::parsers::Parser for Constants {
30 type Item = Constants;
31
32 fn parse<'a, S: Into<Span<'a>>>(input: S) -> ParseResult<'a, Self::Item> {
34 parse_constants_def(input)
35 }
36}
37
38#[cfg(test)]
39mod tests {
40 use crate::parsers::UnwrapValue;
41 use crate::{Constants, Name, Parser, ToTyped, TypedList};
42
43 #[test]
44 fn test_parse() {
45 let input = "(:constants B P D - physob)";
46 assert!(
47 Constants::parse(input).is_value(Constants::new(TypedList::from_iter([
48 Name::from("B").to_typed("physob"),
49 Name::from("P").to_typed("physob"),
50 Name::from("D").to_typed("physob"),
51 ])))
52 );
53 }
54}