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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
//! Provides parsers for atomic function skeletons.
use crate::parsers::{parens, typed_list, ws, ParseResult, Span};
use crate::parsers::{parse_function_symbol, parse_variable};
use crate::types::AtomicFunctionSkeleton;
use nom::combinator::map;
use nom::sequence::tuple;
/// Parses an atomic function skeleton, i.e. `(<function-symbol> <typed list (variable)>)`.
///
/// ## Example
/// ```
/// # use pddl::parsers::{parse_atomic_function_skeleton, Span, UnwrapValue};
/// # use pddl::{Variable, AtomicFunctionSkeleton, Predicate, FunctionSymbol};
/// # use pddl::{ToTyped, TypedList};
/// assert!(parse_atomic_function_skeleton(Span::new("(battery-amount ?r - rover)")).is_value(
/// AtomicFunctionSkeleton::new(
/// FunctionSymbol::from("battery-amount"),
/// TypedList::from_iter([
/// Variable::from("r").to_typed("rover")
/// ]))
/// ));
/// ```
pub fn parse_atomic_function_skeleton<'a, T: Into<Span<'a>>>(
input: T,
) -> ParseResult<'a, AtomicFunctionSkeleton> {
map(
parens(tuple((
parse_function_symbol,
ws(typed_list(parse_variable)),
))),
AtomicFunctionSkeleton::from,
)(input.into())
}
impl crate::parsers::Parser for AtomicFunctionSkeleton {
type Item = AtomicFunctionSkeleton;
/// Parses an atomic function skeleton, i.e. `(<function-symbol> <typed list (variable)>)`.
///
/// ## Example
/// ```
/// # use pddl::{Variable, AtomicFunctionSkeleton, FunctionSymbol, Parser};
/// # use pddl::{ToTyped, TypedList};
/// let (_, value) = AtomicFunctionSkeleton::parse("(battery-amount ?r - rover)").unwrap();
///
/// assert_eq!(value,
/// AtomicFunctionSkeleton::new(
/// FunctionSymbol::from("battery-amount"),
/// TypedList::from_iter([
/// Variable::from("r").to_typed("rover")
/// ]))
/// );
/// ```
///
/// ## See also
/// See [`parse_atomic_function_skeleton`].
fn parse<'a, S: Into<Span<'a>>>(input: S) -> ParseResult<'a, Self::Item> {
parse_atomic_function_skeleton(input)
}
}
#[cfg(test)]
mod tests {
use crate::{AtomicFunctionSkeleton, FunctionSymbol, Parser, Variable};
use crate::{ToTyped, TypedList};
#[test]
fn test_parse() {
let (_, value) = AtomicFunctionSkeleton::parse("(battery-amount ?r - rover)").unwrap();
assert_eq!(
value,
AtomicFunctionSkeleton::new(
FunctionSymbol::from("battery-amount"),
TypedList::from_iter([Variable::from("r").to_typed("rover")])
)
);
}
}