Fix tuple-pattern parser

This case was originally left out but, tuple parsers are almost always exclusively starting with a NewLineLeftParen token.
This commit is contained in:
KtorZ 2023-01-21 10:04:11 +01:00
parent d321b85df2
commit 2101bb924d
No known key found for this signature in database
GPG Key ID: 33173CB6F77F4277
2 changed files with 58 additions and 1 deletions

View File

@ -1615,7 +1615,10 @@ pub fn pattern_parser() -> impl Parser<Token, ast::UntypedPattern, Error = Parse
r.clone()
.separated_by(just(Token::Comma))
.allow_trailing()
.delimited_by(just(Token::LeftParen), just(Token::RightParen))
.delimited_by(
choice((just(Token::LeftParen), just(Token::NewLineLeftParen))),
just(Token::RightParen),
)
.map_with_span(|elems, span| ast::UntypedPattern::Tuple {
location: span,
elems,

View File

@ -1948,3 +1948,57 @@ fn tuple_type_alias() {
})],
)
}
#[test]
fn tuple_pattern() {
let code = indoc! {r#"
fn foo() {
when a is {
(u, dic) -> True
}
}
"#};
assert_definitions(
code,
vec![ast::UntypedDefinition::Fn(Function {
arguments: vec![],
body: expr::UntypedExpr::When {
location: Span::new((), 13..49),
subjects: vec![expr::UntypedExpr::Var {
location: Span::new((), 18..19),
name: "a".to_string(),
}],
clauses: vec![ast::Clause {
location: Span::new((), 29..45),
pattern: vec![ast::Pattern::Tuple {
location: Span::new((), 29..37),
elems: vec![
ast::Pattern::Var {
location: Span::new((), 30..31),
name: "u".to_string(),
},
ast::Pattern::Var {
location: Span::new((), 33..36),
name: "dic".to_string(),
},
],
}],
alternative_patterns: vec![],
guard: None,
then: expr::UntypedExpr::Var {
location: Span::new((), 41..45),
name: "True".to_string(),
},
}],
},
doc: None,
location: Span::new((), 0..8),
name: "foo".to_string(),
public: false,
return_annotation: None,
return_type: (),
end_position: 50,
})],
);
}