/// Parse the trailing part of a function introduction.
///
/// ```text
/// fun-ty  ::= type-param+ "->" term(50 - 1)
///
/// type-param  ::= "(" IDENTIFIER+ ":" term(0) ")"
///               | "{" IDENTIFIER+ (":" term(0))? "}"
///               | "{{" IDENTIFIER ":" term(0) "}}"
/// ```
Parse the trailing part of a function introduction.


Parse the trailing part of a function introduction .
fn parse_fun_ty(
        &mut self,
        start_token: Token<'file>,
    ) -> Result<Term<'file>, Diagnostic<FileSpan>> {
        let mut params = Vec::new();
        loop {
            if let Some(start_param_token) = self.try_match(TokenKind::Open(DelimKind::Paren)) {
                let mut param_names = Vec::new();
                while let Some(param_name) = self.try_identifier() {
                    param_names.push(param_name);
                }
                if param_names.is_empty() {
                    return Err(Diagnostic::new_error("expected at least one parameter")
                        .with_label(Label::new_primary(start_param_token.span()).with_message(
                            "at least one parameter was expected after this parenthesis",
                        )));
                }
                self.expect_match(TokenKind::Colon)?;
                let param_ty = self.parse_term(Prec(0))?;
                let end_param_token = self.expect_match(TokenKind::Close(DelimKind::Paren))?;
                let param_span = FileSpan::merge(start_param_token.span(), end_param_token.span());
                params.push(TypeParam::Explicit(param_span, param_names, param_ty));
            } else if let Some(start_param_token) =
                self.try_match(TokenKind::Open(DelimKind::Brace))
            {
                if self.try_match(TokenKind::Open(DelimKind::Brace)).is_some() {
                    let param_name = self.expect_identifier()?;
                    self.expect_match(TokenKind::Colon)?;
                    let param_ty = self.parse_term(Prec(0))?;
                    self.expect_match(TokenKind::Close(DelimKind::Brace))?;
                    let end_param_token = self.expect_match(TokenKind::Close(DelimKind::Brace))?;
                    let param_span =
                        FileSpan::merge(start_param_token.span(), end_param_token.span());
                    params.push(TypeParam::Instance(param_span, param_name, param_ty));
                } else {
                    let mut param_names = Vec::new();
                    while let Some(param_name) = self.try_identifier() {
                        param_names.push(param_name);
                    }
                    if param_names.is_empty() {
                        return Err(Diagnostic::new_error("expected at least one parameter")
                            .with_label(
                                Label::new_primary(start_param_token.span()).with_message(
                                    "at least one parameter was expected after this brace",
                                ),
                            ));
                    }
                    let param_ty = match self.try_match(TokenKind::Colon) {
                        Some(_) => Some(self.parse_term(Prec(0))?),
                        None => None,
                    };
                    let end_param_token = self.expect_match(TokenKind::Close(DelimKind::Brace))?;
                    let param_span =
                        FileSpan::merge(start_param_token.span(), end_param_token.span());
                    params.push(TypeParam::Implicit(param_span, param_names, param_ty));
                }
            } else {
                break;
            }
        }
        if params.is_empty() {
            return Err(
                Diagnostic::new_error("expected at least one parameter").with_label(
                    Label::new_primary(start_token.span())
                        .with_message("at least one parameter was expected after this keyword"),
                ),
            );
        }
        self.expect_match(TokenKind::RArrow)?;
        let body_ty = self.parse_term(Prec(50 - 1))?;
        let span = FileSpan::merge(start_token.span(), body_ty.span());
        Ok(Term::FunType(span, params, Box::new(body_ty)))
    }
fn parse_fun_ty ( & mut self , start_token : Token < ' file > , ) -> Result < Term < ' file > , Diagnostic < FileSpan > > { let mut params = Vec :: new ( ) ; loop { if let Some ( start_param_token ) = self . try_match ( TokenKind :: Open ( DelimKind :: Paren ) ) { let mut param_names = Vec :: new ( ) ; while let Some ( param_name ) = self . try_identifier ( ) { param_names . push ( param_name ) ; } if param_names . is_empty ( ) { return Err ( Diagnostic :: new_error ( " " ) . with_label ( Label :: new_primary ( start_param_token . span ( ) ) . with_message ( " " , ) ) ) ; } self . expect_match ( TokenKind :: Colon ) ? ; let param_ty = self . parse_term ( Prec ( 0 ) ) ? ; let end_param_token = self . expect_match ( TokenKind :: Close ( DelimKind :: Paren ) ) ? ; let param_span = FileSpan :: merge ( start_param_token . span ( ) , end_param_token . span ( ) ) ; params . push ( TypeParam :: Explicit ( param_span , param_names , param_ty ) ) ; } else if let Some ( start_param_token ) = self . try_match ( TokenKind :: Open ( DelimKind :: Brace ) ) { if self . try_match ( TokenKind :: Open ( DelimKind :: Brace ) ) . is_some ( ) { let param_name = self . expect_identifier ( ) ? ; self . expect_match ( TokenKind :: Colon ) ? ; let param_ty = self . parse_term ( Prec ( 0 ) ) ? ; self . expect_match ( TokenKind :: Close ( DelimKind :: Brace ) ) ? ; let end_param_token = self . expect_match ( TokenKind :: Close ( DelimKind :: Brace ) ) ? ; let param_span = FileSpan :: merge ( start_param_token . span ( ) , end_param_token . span ( ) ) ; params . push ( TypeParam :: Instance ( param_span , param_name , param_ty ) ) ; } else { let mut param_names = Vec :: new ( ) ; while let Some ( param_name ) = self . try_identifier ( ) { param_names . push ( param_name ) ; } if param_names . is_empty ( ) { return Err ( Diagnostic :: new_error ( " " ) . with_label ( Label :: new_primary ( start_param_token . span ( ) ) . with_message ( " " , ) , ) ) ; } let param_ty = match self . try_match ( TokenKind :: Colon ) { Some ( _ ) => Some ( self . parse_term ( Prec ( 0 ) ) ? ) , None => None , } ; let end_param_token = self . expect_match ( TokenKind :: Close ( DelimKind :: Brace ) ) ? ; let param_span = FileSpan :: merge ( start_param_token . span ( ) , end_param_token . span ( ) ) ; params . push ( TypeParam :: Implicit ( param_span , param_names , param_ty ) ) ; } } else { break ; } } if params . is_empty ( ) { return Err ( Diagnostic :: new_error ( " " ) . with_label ( Label :: new_primary ( start_token . span ( ) ) . with_message ( " " ) , ) , ) ; } self . expect_match ( TokenKind :: RArrow ) ? ; let body_ty = self . parse_term ( Prec ( 50 - 1 ) ) ? ; let span = FileSpan :: merge ( start_token . span ( ) , body_ty . span ( ) ) ; Ok ( Term :: FunType ( span , params , Box :: new ( body_ty ) ) ) }
Parse the trailing part of a function introduction.
Parse the trailing part of a function introduction .
&mut self
start_token
Token<'file>