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
//! Provides parsers for goal object declarations.
use nom::combinator::map;
use crate::parsers::{parse_name, prefix_expr, typed_list, ParseResult, Span};
use crate::types::Objects;
/// Parser for goal object declarations.
///
/// ## Example
/// ```
/// # use pddl::parsers::{parse_problem_objects_declaration, preamble::*};
/// # use pddl::{Name, Objects, ToTyped, Type};
/// let input = "(:objects train1 train2)";
/// assert!(parse_problem_objects_declaration(input).is_value(
/// Objects::new([
/// Name::new("train1").to_typed(Type::OBJECT),
/// Name::new("train2").to_typed(Type::OBJECT),
/// ])
/// ));
/// ```
pub fn parse_problem_objects_declaration<'a, T: Into<Span<'a>>>(
input: T,
) -> ParseResult<'a, Objects> {
map(
prefix_expr(":objects", typed_list(parse_name)),
Objects::new,
)(input.into())
}
impl crate::parsers::Parser for Objects {
type Item = Objects;
/// See [`parse_problem_objects_declaration`].
fn parse<'a, S: Into<Span<'a>>>(input: S) -> ParseResult<'a, Self::Item> {
parse_problem_objects_declaration(input)
}
}
#[cfg(test)]
mod test {
use crate::parsers::UnwrapValue;
use crate::{Name, Parser, ToTyped, Type};
use super::*;
#[test]
fn test_parse() {
let input = "(:objects train1 train2)";
assert!(Objects::parse(input).is_value(Objects::new([
Name::new("train1").to_typed(Type::OBJECT),
Name::new("train2").to_typed(Type::OBJECT),
])));
}
}