Skip to main content

pddl_core/parsers/terms/
function_symbol.rs

1//! Provides parsers for function symbols (`<function-symbol>`).
2
3use crate::parsers::error::R;
4use crate::parsers::parse_name;
5use crate::parsers::sexpr::Node;
6use crate::types::FunctionSymbol;
7
8/// Parses a function symbol (`<function-symbol>`), i.e. `<name>`.
9pub(crate) fn parse_function_symbol(node: &Node) -> R<FunctionSymbol> {
10    parse_name(node).map(FunctionSymbol::new)
11}
12
13crate::parsers::impl_parser!(FunctionSymbol => parse_function_symbol);
14
15#[cfg(test)]
16mod tests {
17    use crate::parsers::UnwrapValue;
18    use crate::{FunctionSymbol, Parser};
19    use assert2::check;
20
21    #[test]
22    fn test_parse() {
23        check!(FunctionSymbol::from_str("abcde").is_value("abcde".into()));
24        check!(FunctionSymbol::from_str("a-1_2").is_value("a-1_2".into()));
25        check!(FunctionSymbol::from_str("Z01").is_value("Z01".into()));
26        check!(FunctionSymbol::from_str("x-_-_").is_value("x-_-_".into()));
27        check!(FunctionSymbol::from_str("").is_err());
28        check!(FunctionSymbol::from_str(".").is_err());
29        check!(FunctionSymbol::from_str("-abc").is_err());
30        check!(FunctionSymbol::from_str("0124").is_err());
31        check!(FunctionSymbol::from_str("-1").is_err());
32    }
33}