pub fn termify_compound_name(&self, ast: &ast::CompoundName) -> Result<Spanned<Term<'a>>> {
        // Map the primary name.
        let mut term = self.fold(match ast.primary.kind {
            ast::PrimaryNameKind::String(s) => Spanned::new(Term::StrLit(s), ast.primary.span),
            _ => self.termify_name(ResolvableName::from_primary_name(&ast.primary, self.ctx)?)?,
        });

        // For each name part, wrap the term in another layer. Like an onion.
        for part in &ast.parts {
            term = self.fold(match *part {
                ast::NamePart::Select(ref primary) => {
                    let n = ResolvableName::from_primary_name(primary, self.ctx)?;
                    let sp = Span::union(term.span, n.span);
                    let selectable_scope = self.maybe_selectable_scope(&term.value);
                    match selectable_scope {
                        Some(id) => {
                            let t = self.ensure_resolved(self.termify_name_in_scope(n, id)?)?;
                            Spanned::new(t.value, sp)
                        }
                        None => Spanned::new(Term::Select(Box::new(term), n), sp),
                    }
                }
                ast::NamePart::SelectAll(span) => {
                    let sp = Span::union(term.span, span);
                    Spanned::new(Term::SelectAll(Box::new(term)), sp)
                }
                ast::NamePart::Signature(ref sig) => {
                    self.emit(
                        DiagBuilder2::bug(format!(
                            "termification of signature suffix `{}` not implemented",
                            sig.span.extract()
                        ))
                        .span(sig.span),
                    );
                    return Err(());
                }
                ast::NamePart::Attribute(ident) => {
                    let attr = self.termify_name(Spanned::new(ident.name.into(), ident.span))?;
                    match attr.value {
                        // TODO: Enable this as soon as we handle attribute
                        // declarations.
                        // Term::Ident(Spanned { value: Def::Attr(id), span }) => {
                        //  let sp = Span::union(term.span, attr.span);
                        //  Spanned::new(Term::Attribute(Box::new(term), Spanned::new(id, span)), sp)
                        // }
                        Term::Ident(other) => {
                            self.emit(
                                DiagBuilder2::error(format!(
                                    "`{}` is not an attribute name",
                                    ident.name
                                ))
                                .span(ident.span)
                                .add_note("Declared here:")
                                .span(other.span),
                            );
                            return Err(());
                        }
                        _ => unreachable!(),
                    }
                }
                ast::NamePart::Call(ref paren_elems) => {
                    let subterm = self.termify_paren_elems(paren_elems)?;
                    let sp = Span::union(term.span, subterm.span);
                    Spanned::new(Term::SuffixParen(Box::new(term), Box::new(subterm)), sp)
                }
                ast::NamePart::Range(ref expr) => {
                    if expr.data == ast::BoxExpr {
                        let sp = Span::union(term.span, expr.span);
                        Spanned::new(Term::UnboundedRange(Box::new(term)), sp)
                    } else {
                        let expr = self.termify_expr(expr)?;
                        let sp = Span::union(term.span, expr.span);
                        Spanned::new(Term::RangeSuffix(Box::new(term), Box::new(expr)), sp)
                    }
                }
            });
        }

        Ok(term)
    }
/// Map an AST compound name to a term.
Map an AST compound name to a term.
Map an AST compound name to a term .
pub fn termify_compound_name(&self, ast: &ast::CompoundName) -> Result<Spanned<Term<'a>>> {
        // Map the primary name.
        let mut term = self.fold(match ast.primary.kind {
            ast::PrimaryNameKind::String(s) => Spanned::new(Term::StrLit(s), ast.primary.span),
            _ => self.termify_name(ResolvableName::from_primary_name(&ast.primary, self.ctx)?)?,
        });
        // For each name part, wrap the term in another layer. Like an onion.
        for part in &ast.parts {
            term = self.fold(match *part {
                ast::NamePart::Select(ref primary) => {
                    let n = ResolvableName::from_primary_name(primary, self.ctx)?;
                    let sp = Span::union(term.span, n.span);
                    let selectable_scope = self.maybe_selectable_scope(&term.value);
                    match selectable_scope {
                        Some(id) => {
                            let t = self.ensure_resolved(self.termify_name_in_scope(n, id)?)?;
                            Spanned::new(t.value, sp)
                        }
                        None => Spanned::new(Term::Select(Box::new(term), n), sp),
                    }
                }
                ast::NamePart::SelectAll(span) => {
                    let sp = Span::union(term.span, span);
                    Spanned::new(Term::SelectAll(Box::new(term)), sp)
                }
                ast::NamePart::Signature(ref sig) => {
                    self.emit(
                        DiagBuilder2::bug(format!(
                            "termification of signature suffix `{}` not implemented",
                            sig.span.extract()
                        ))
                        .span(sig.span),
                    );
                    return Err(());
                }
                ast::NamePart::Attribute(ident) => {
                    let attr = self.termify_name(Spanned::new(ident.name.into(), ident.span))?;
                    match attr.value {
                        // TODO: Enable this as soon as we handle attribute
                        // declarations.
                        // Term::Ident(Spanned { value: Def::Attr(id), span }) => {
                        //  let sp = Span::union(term.span, attr.span);
                        //  Spanned::new(Term::Attribute(Box::new(term), Spanned::new(id, span)), sp)
                        // }
                        Term::Ident(other) => {
                            self.emit(
                                DiagBuilder2::error(format!(
                                    "`{}` is not an attribute name",
                                    ident.name
                                ))
                                .span(ident.span)
                                .add_note("Declared here:")
                                .span(other.span),
                            );
                            return Err(());
                        }
                        _ => unreachable!(),
                    }
                }
                ast::NamePart::Call(ref paren_elems) => {
                    let subterm = self.termify_paren_elems(paren_elems)?;
                    let sp = Span::union(term.span, subterm.span);
                    Spanned::new(Term::SuffixParen(Box::new(term), Box::new(subterm)), sp)
                }
                ast::NamePart::Range(ref expr) => {
                    if expr.data == ast::BoxExpr {
                        let sp = Span::union(term.span, expr.span);
                        Spanned::new(Term::UnboundedRange(Box::new(term)), sp)
                    } else {
                        let expr = self.termify_expr(expr)?;
                        let sp = Span::union(term.span, expr.span);
                        Spanned::new(Term::RangeSuffix(Box::new(term), Box::new(expr)), sp)
                    }
                }
            });
        }
        Ok(term)
    }
pub fn termify_compound_name ( & self , ast : & ast :: CompoundName ) -> Result < Spanned < Term < ' a > > > { // Map the primary name. let mut term = self . fold ( match ast . primary . kind { ast :: PrimaryNameKind :: String ( s ) => Spanned :: new ( Term :: StrLit ( s ) , ast . primary . span ) , _ => self . termify_name ( ResolvableName :: from_primary_name ( & ast . primary , self . ctx ) ? ) ? , } ) ; // For each name part, wrap the term in another layer. Like an onion. for part in & ast . parts { term = self . fold ( match * part { ast :: NamePart :: Select ( ref primary ) => { let n = ResolvableName :: from_primary_name ( primary , self . ctx ) ? ; let sp = Span :: union ( term . span , n . span ) ; let selectable_scope = self . maybe_selectable_scope ( & term . value ) ; match selectable_scope { Some ( id ) => { let t = self . ensure_resolved ( self . termify_name_in_scope ( n , id ) ? ) ? ; Spanned :: new ( t . value , sp ) } None => Spanned :: new ( Term :: Select ( Box :: new ( term ) , n ) , sp ) , } } ast :: NamePart :: SelectAll ( span ) => { let sp = Span :: union ( term . span , span ) ; Spanned :: new ( Term :: SelectAll ( Box :: new ( term ) ) , sp ) } ast :: NamePart :: Signature ( ref sig ) => { self . emit ( DiagBuilder2 :: bug ( format ! ( " " sig span extract ( ) ) ) . span ( sig . span ) , ) ; return Err ( ( ) ) ; } ast :: NamePart :: Attribute ( ident ) => { let attr = self . termify_name ( Spanned :: new ( ident . name . into ( ) , ident . span ) ) ? ; match attr . value { // TODO: Enable this as soon as we handle attribute // declarations. // Term::Ident(Spanned { value: Def::Attr(id), span }) => { //  let sp = Span::union(term.span, attr.span); //  Spanned::new(Term::Attribute(Box::new(term), Spanned::new(id, span)), sp) // } Term :: Ident ( other ) => { self . emit ( DiagBuilder2 :: error ( format ! ( " " ident name ) ) . span ( ident . span ) . add_note ( " " ) . span ( other . span ) , ) ; return Err ( ( ) ) ; } _ => unreachable ! ( ) , } } ast :: NamePart :: Call ( ref paren_elems ) => { let subterm = self . termify_paren_elems ( paren_elems ) ? ; let sp = Span :: union ( term . span , subterm . span ) ; Spanned :: new ( Term :: SuffixParen ( Box :: new ( term ) , Box :: new ( subterm ) ) , sp ) } ast :: NamePart :: Range ( ref expr ) => { if expr . data == ast :: BoxExpr { let sp = Span :: union ( term . span , expr . span ) ; Spanned :: new ( Term :: UnboundedRange ( Box :: new ( term ) ) , sp ) } else { let expr = self . termify_expr ( expr ) ? ; let sp = Span :: union ( term . span , expr . span ) ; Spanned :: new ( Term :: RangeSuffix ( Box :: new ( term ) , Box :: new ( expr ) ) , sp ) } } } ) ; } Ok ( term ) }
Map an AST compound name to a term.
Map an AST compound name to a term .
&self
ast
&ast::CompoundName
&self
ast
&ast::CompoundName