pddl_core/parsers/durative/
f_exp_t.rs1use crate::parsers::error::R;
4use crate::parsers::sexpr::Node;
5use crate::parsers::{parse_f_exp, prefix};
6use crate::types::TimedFluentExpression;
7
8pub(crate) fn parse_f_exp_t(node: &Node) -> R<TimedFluentExpression> {
10 if node.atom().is_some() {
11 return if node.is("#t") {
12 Ok(TimedFluentExpression::new())
13 } else {
14 Err(node.error())
15 };
16 }
17 prefix(node, "*", |args| {
18 let first = args.next()?;
19 if first.is("#t") {
20 return parse_f_exp(args.next()?);
21 }
22 let exp = parse_f_exp(first)?;
23 args.expect("#t")?;
24 Ok(exp)
25 })
26 .map(TimedFluentExpression::new_scaled)
27}
28
29crate::parsers::impl_parser!(TimedFluentExpression => parse_f_exp_t);
30
31#[cfg(test)]
32mod tests {
33 use crate::parsers::UnwrapValue;
34 use assert2::check;
35
36 use crate::*;
37
38 #[test]
39 fn test_parse() {
40 check!(TimedFluentExpression::from_str("#t").is_value(TimedFluentExpression::Now));
41
42 check!(
43 TimedFluentExpression::from_str("(* (fuel ?tank) #t)").is_value(
44 TimedFluentExpression::scaled(FluentExpression::function(
45 FunctionHead::with_terms(
46 FunctionSymbol::string("fuel"),
47 [Term::Variable(Variable::string("tank"))]
48 )
49 ))
50 )
51 );
52
53 check!(
54 TimedFluentExpression::from_str("(* #t (fuel ?tank))").is_value(
55 TimedFluentExpression::scaled(FluentExpression::function(
56 FunctionHead::with_terms(
57 FunctionSymbol::string("fuel"),
58 [Term::Variable(Variable::string("tank"))]
59 )
60 ))
61 )
62 );
63 }
64}