use crate::parsers::error::R;
use crate::parsers::sexpr::Node;
use crate::parsers::{parse_f_exp, prefix};
use crate::types::TimedFluentExpression;
pub(crate) fn parse_f_exp_t(node: &Node) -> R<TimedFluentExpression> {
if node.atom().is_some() {
return if node.is("#t") {
Ok(TimedFluentExpression::new())
} else {
Err(node.error())
};
}
prefix(node, "*", |args| {
let first = args.next()?;
if first.is("#t") {
return parse_f_exp(args.next()?);
}
let exp = parse_f_exp(first)?;
args.expect("#t")?;
Ok(exp)
})
.map(TimedFluentExpression::new_scaled)
}
crate::parsers::impl_parser!(TimedFluentExpression => parse_f_exp_t);
#[cfg(test)]
mod tests {
use crate::parsers::UnwrapValue;
use assert2::check;
use crate::*;
#[test]
fn test_parse() {
check!(TimedFluentExpression::from_str("#t").is_value(TimedFluentExpression::Now));
check!(
TimedFluentExpression::from_str("(* (fuel ?tank) #t)").is_value(
TimedFluentExpression::scaled(FluentExpression::function(
FunctionHead::with_terms(
FunctionSymbol::string("fuel"),
[Term::Variable(Variable::string("tank"))]
)
))
)
);
check!(
TimedFluentExpression::from_str("(* #t (fuel ?tank))").is_value(
TimedFluentExpression::scaled(FluentExpression::function(
FunctionHead::with_terms(
FunctionSymbol::string("fuel"),
[Term::Variable(Variable::string("tank"))]
)
))
)
);
}
}