use crate::parsers::{parse_type, ParseResult, Span};
use crate::types::FunctionType;
use nom::combinator::map;
pub fn parse_function_type<'a, T: Into<Span<'a>>>(input: T) -> ParseResult<'a, FunctionType> {
map(parse_type, FunctionType::from)(input.into())
}
impl crate::parsers::Parser for FunctionType {
type Item = FunctionType;
fn parse<'a, S: Into<Span<'a>>>(input: S) -> ParseResult<'a, Self::Item> {
parse_function_type(input)
}
}
#[cfg(test)]
mod tests {
use crate::parsers::UnwrapValue;
use crate::{FunctionType, Parser, Type};
#[test]
fn test_parse() {
assert!(FunctionType::parse("number")
.is_value(FunctionType::new(Type::Exactly("number".into()))));
assert!(FunctionType::parse("(either object number)")
.is_value(FunctionType::new(Type::from_iter(["object", "number"]))));
}
}