diff --git a/crates/parser/src/parser/common/types.rs b/crates/parser/src/parser/common/types.rs index 64b032d..6726f41 100644 --- a/crates/parser/src/parser/common/types.rs +++ b/crates/parser/src/parser/common/types.rs @@ -43,7 +43,11 @@ impl<'a> TryFrom> for TypeExpr { } Rule::fn_type => { - + ty = TypeExpr::Fn { + return_type: Box::new(ty), + kind: ref_inner.next().unwrap().try_into()?, + params: collect_recovered(ref_inner)?, + }; } _ => AstError::bug_unimplemented(ref_pair)?, @@ -54,7 +58,7 @@ impl<'a> TryFrom> for TypeExpr { } Rule::lifetime => Ok(TypeExpr::Lifetime(inner.next().unwrap().try_into()?)), - Rule::void_type => Ok(TypeExpr::Tuple(Vec::new())), + Rule::void_type => Ok(TypeExpr::Void), Rule::tuple_type => Ok(TypeExpr::Tuple(collect_recovered(inner)?)), Rule::path_type => Ok(TypeExpr::Path( @@ -71,6 +75,22 @@ impl<'a> TryFrom> for TypeExpr { } } +impl<'a> TryFrom> for FnKind { + type Error = AstError<'a>; + + fn try_from(pair: pest::iterators::Pair<'a, Rule>) -> Result { + match pair.as_rule() { + Rule::fn_kind_fn => Ok(FnKind::Fn), + Rule::fn_kind_unsafe => Ok(FnKind::UnsafeFn), + Rule::fn_kind_closure => Ok(FnKind::FnClosure), + Rule::fn_kind_once => Ok(FnKind::FnOnce), + Rule::fn_kind_mut => Ok(FnKind::FnMut), + + _ => AstError::bug_unimplemented(pair), + } + } +} + impl<'a> TryFrom> for GenericsDecl { type Error = AstError<'a>;