Application and named types

main
Alex Bethel 2022-08-06 23:03:10 -05:00
parent dc50dd1545
commit e56a56693c
1 changed files with 17 additions and 3 deletions

View File

@ -3,7 +3,7 @@
use std::{error::Error, fmt::Display};
use chumsky::{
prelude::{choice, end, just, none_of, one_of, todo, Simple},
prelude::{choice, end, just, none_of, one_of, Simple},
text::{ident, int, keyword, whitespace},
Parser,
};
@ -303,6 +303,7 @@ fn parse_func_decl<'a>(
fn parse_type_alias(m: &ParserMeta) -> impl Parser<char, ClassMember, Error = Simple<char>> {
keyword("type")
.then_ignore(whitespace())
.ignore_then(parse_type(m))
.then(
just('=')
@ -481,11 +482,24 @@ fn parse_literal(_m: &ParserMeta) -> impl Parser<char, Expr, Error = Simple<char
.map(Expr::Literal)
}
fn parse_type(_m: &ParserMeta) -> impl Parser<char, Type, Error = Simple<char>> {
todo()
fn parse_type(m: &ParserMeta) -> impl Parser<char, Type, Error = Simple<char>> {
parse_named_type(m).repeated().at_least(1).map(|types| {
types
.into_iter()
.reduce(|l, r| Type::Application {
function: Box::new(l),
expression: Box::new(r),
})
.unwrap()
})
}
fn parse_named_type(_m: &ParserMeta) -> impl Parser<char, Type, Error = Simple<char>> {
ident().then_ignore(whitespace()).map(Type::Named)
}
fn parse_pattern(m: &ParserMeta) -> impl Parser<char, Pattern, Error = Simple<char>> {
// TODO: add all the patterns
choice((parse_capture_pattern(m),))
}