/// Map a term to a range.
Map a term to a range.
Map a term to a range .
pub fn term_to_expr<'t, C>(term: Spanned<Term<'t>>, ctx: C) -> Result<&'t hir::Expr2<'t>>
where
    C: SessionContext + Copy + for<'a> Alloc<'a, 't, hir::LitExpr>,
{
    match term.value {
        Term::Unresolved(name) => {
            ctx.emit(DiagBuilder2::error(format!("`{}` is unknown", name)).span(term.span));
            Err(())
        }
        Term::IntLit(value) => Ok(ctx.alloc(hir::LitExpr::new_integer(term.span, value))),
        Term::FloatLit(value) => Ok(ctx.alloc(hir::LitExpr::new_float(term.span, value))),
        // Throw an error for everything that does not look like an expression.
        _ => {
            ctx.emit(
                DiagBuilder2::error(format!(
                    "`{}` is not a valid expression",
                    term.span.extract()
                ))
                .span(term.span),
            );
            debugln!("It is a {:#?}", term);
            Err(())
        }
    }
}
pub fn term_to_expr < ' t , C > ( term : Spanned < Term < ' t > > , ctx : C ) -> Result < & ' t hir :: Expr2 < ' t > > where C : SessionContext + Copy + for < ' a > Alloc < ' a , ' t , hir :: LitExpr > , { match term . value { Term :: Unresolved ( name ) => { ctx . emit ( DiagBuilder2 :: error ( format ! ( " " name ) ) . span ( term . span ) ) ; Err ( ( ) ) } Term :: IntLit ( value ) => Ok ( ctx . alloc ( hir :: LitExpr :: new_integer ( term . span , value ) ) ) , Term :: FloatLit ( value ) => Ok ( ctx . alloc ( hir :: LitExpr :: new_float ( term . span , value ) ) ) , // Throw an error for everything that does not look like an expression. _ => { ctx . emit ( DiagBuilder2 :: error ( format ! ( " " term span extract ( ) ) ) . span ( term . span ) , ) ; debugln ! ( " " term ) ; Err ( ( ) ) } } }
Map a term to a range.
Map a term to a range .
term
Spanned<Term<'t>>
ctx
C