attempt to parse let

This commit is contained in:
Kasey White 2022-09-28 04:03:37 -04:00 committed by Lucas
parent 60359ec9b0
commit 3c5039134f
1 changed files with 21 additions and 0 deletions

View File

@ -382,9 +382,30 @@ pub fn expr_unit_parser() -> impl Parser<Token, expr::UntypedExpr, Error = Parse
location: span, location: span,
label, label,
}), }),
just(Token::Let)
.then(assignment_parser())
.map(|(_, assign)| assign),
)) ))
} }
fn assignment_parser() -> impl Parser<Token, expr::UntypedExpr, Error = ParseError> {
recursive(|_r| {
pattern_parser()
.then(just(Token::Colon).ignore_then(type_parser()).or_not())
.then_ignore(just(Token::Equal))
.then(expr_parser())
.map_with_span(
|((pattern, annotation), value), span| expr::UntypedExpr::Assignment {
location: span,
value: Box::new(value),
pattern,
kind: ast::AssignmentKind::Let,
annotation,
},
)
})
}
pub fn type_parser() -> impl Parser<Token, ast::Annotation, Error = ParseError> { pub fn type_parser() -> impl Parser<Token, ast::Annotation, Error = ParseError> {
recursive(|r| { recursive(|r| {
choice(( choice((