aiken_lang/parser/pattern/
pair.rs

1use crate::{
2    ast::{UntypedPattern, well_known},
3    parser::{error::ParseError, token::Token},
4};
5use chumsky::prelude::*;
6
7pub fn parser(
8    pattern: Recursive<'_, Token, UntypedPattern, ParseError>,
9) -> impl Parser<Token, UntypedPattern, Error = ParseError> + '_ {
10    select! {Token::UpName { name } if name == well_known::PAIR => name}
11        .ignore_then(choice((
12            just(Token::LeftParen),
13            just(Token::NewLineLeftParen),
14        )))
15        .then(pattern.clone())
16        .then_ignore(just(Token::Comma))
17        .then(pattern.clone())
18        .then_ignore(just(Token::RightParen))
19        .map_with_span(|((_name, fst), snd), location| UntypedPattern::Pair {
20            fst: Box::new(fst),
21            snd: Box::new(snd),
22            location,
23        })
24}