Application and named types
This commit is contained in:
parent
dc50dd1545
commit
e56a56693c
|
@ -3,7 +3,7 @@
|
||||||
use std::{error::Error, fmt::Display};
|
use std::{error::Error, fmt::Display};
|
||||||
|
|
||||||
use chumsky::{
|
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},
|
text::{ident, int, keyword, whitespace},
|
||||||
Parser,
|
Parser,
|
||||||
};
|
};
|
||||||
|
@ -303,6 +303,7 @@ fn parse_func_decl<'a>(
|
||||||
|
|
||||||
fn parse_type_alias(m: &ParserMeta) -> impl Parser<char, ClassMember, Error = Simple<char>> {
|
fn parse_type_alias(m: &ParserMeta) -> impl Parser<char, ClassMember, Error = Simple<char>> {
|
||||||
keyword("type")
|
keyword("type")
|
||||||
|
.then_ignore(whitespace())
|
||||||
.ignore_then(parse_type(m))
|
.ignore_then(parse_type(m))
|
||||||
.then(
|
.then(
|
||||||
just('=')
|
just('=')
|
||||||
|
@ -481,11 +482,24 @@ fn parse_literal(_m: &ParserMeta) -> impl Parser<char, Expr, Error = Simple<char
|
||||||
.map(Expr::Literal)
|
.map(Expr::Literal)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parse_type(_m: &ParserMeta) -> impl Parser<char, Type, Error = Simple<char>> {
|
fn parse_type(m: &ParserMeta) -> impl Parser<char, Type, Error = Simple<char>> {
|
||||||
todo()
|
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>> {
|
fn parse_pattern(m: &ParserMeta) -> impl Parser<char, Pattern, Error = Simple<char>> {
|
||||||
|
// TODO: add all the patterns
|
||||||
choice((parse_capture_pattern(m),))
|
choice((parse_capture_pattern(m),))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue