pub fn termify_literal(&self, ast: Spanned<&Literal>) -> Result<Spanned<Term<'a>>> {
        Ok(Spanned::new(
            match *ast.value {
                Literal::Abstract(base, int, frac, exp) => {
                    let base = match base {
                        Some(base) => match base.as_str().parse() {
                            Ok(base) => base,
                            Err(_) => {
                                self.emit(
                                    DiagBuilder2::error(format!(
                                        "`{}` is not a valid base for a number literal",
                                        base
                                    ))
                                    .span(ast.span),
                                );
                                return Err(());
                            }
                        },
                        None => 10,
                    };
                    let int = match BigInt::parse_bytes(int.as_str().as_bytes(), base) {
                        Some(v) => v,
                        None => {
                            self.emit(
                                DiagBuilder2::error(format!(
                                    "`{}` is not a valid base-{} integer",
                                    int, base
                                ))
                                .span(ast.span),
                            );
                            return Err(());
                        }
                    };
                    let exp: isize = match exp {
                        Some(Exponent(sign, exp)) => match exp.as_str().parse() {
                            Ok(v) => {
                                if sign == ExponentSign::Positive {
                                    v
                                } else {
                                    -v
                                }
                            }
                            Err(_) => {
                                self.emit(
                                    DiagBuilder2::error(format!(
                                        "`{}` is not a valid exponent for a number literal",
                                        exp
                                    ))
                                    .span(ast.span),
                                );
                                return Err(());
                            }
                        },
                        None => 0,
                    };

                    // Parse the rest of the number.
                    if let Some(frac) = frac {
                        use num::pow;
                        let shift = frac.as_str().len();
                        let frac = match BigInt::parse_bytes(frac.as_str().as_bytes(), base) {
                            Some(v) => v,
                            None => {
                                self.emit(
                                    DiagBuilder2::error(format!(
                                        "`{}` is not a valid base-{} integer",
                                        frac, base
                                    ))
                                    .span(ast.span),
                                );
                                return Err(());
                            }
                        };
                        let num = int * pow(BigInt::from(base), shift) + frac;
                        let adj = exp - shift as isize;
                        let q = if adj < 0 {
                            BigRational::new(num, pow(BigInt::from(base), (-adj) as usize))
                        } else if adj > 0 {
                            BigRational::from(num * pow(BigInt::from(base), adj as usize))
                        } else {
                            BigRational::from(num)
                        };
                        Term::FloatLit(q)
                    } else {
                        if exp < 0 {
                            self.emit(
                                DiagBuilder2::error(format!(
                                    "integer literal `{}` has negative exponent",
                                    ast.span.extract()
                                ))
                                .span(ast.span),
                            );
                            return Err(());
                        }
                        if exp > 0 {
                            use num::pow;
                            Term::IntLit(int * pow(BigInt::from(base), exp as usize))
                        } else {
                            Term::IntLit(int)
                        }
                    }
                }
                ref wrong => {
                    self.emit(
                        DiagBuilder2::bug(format!(
                            "termification of literal `{}` not implemented",
                            ast.span.extract()
                        ))
                        .span(ast.span)
                        .add_note(format!("{:?}", wrong)),
                    );
                    return Err(());
                }
            },
            ast.span,
        ))
    }
/// Map an AST literal to a term.
Map an AST literal to a term.
Map an AST literal to a term .
pub fn termify_literal(&self, ast: Spanned<&Literal>) -> Result<Spanned<Term<'a>>> {
        Ok(Spanned::new(
            match *ast.value {
                Literal::Abstract(base, int, frac, exp) => {
                    let base = match base {
                        Some(base) => match base.as_str().parse() {
                            Ok(base) => base,
                            Err(_) => {
                                self.emit(
                                    DiagBuilder2::error(format!(
                                        "`{}` is not a valid base for a number literal",
                                        base
                                    ))
                                    .span(ast.span),
                                );
                                return Err(());
                            }
                        },
                        None => 10,
                    };
                    let int = match BigInt::parse_bytes(int.as_str().as_bytes(), base) {
                        Some(v) => v,
                        None => {
                            self.emit(
                                DiagBuilder2::error(format!(
                                    "`{}` is not a valid base-{} integer",
                                    int, base
                                ))
                                .span(ast.span),
                            );
                            return Err(());
                        }
                    };
                    let exp: isize = match exp {
                        Some(Exponent(sign, exp)) => match exp.as_str().parse() {
                            Ok(v) => {
                                if sign == ExponentSign::Positive {
                                    v
                                } else {
                                    -v
                                }
                            }
                            Err(_) => {
                                self.emit(
                                    DiagBuilder2::error(format!(
                                        "`{}` is not a valid exponent for a number literal",
                                        exp
                                    ))
                                    .span(ast.span),
                                );
                                return Err(());
                            }
                        },
                        None => 0,
                    };
                    // Parse the rest of the number.
                    if let Some(frac) = frac {
                        use num::pow;
                        let shift = frac.as_str().len();
                        let frac = match BigInt::parse_bytes(frac.as_str().as_bytes(), base) {
                            Some(v) => v,
                            None => {
                                self.emit(
                                    DiagBuilder2::error(format!(
                                        "`{}` is not a valid base-{} integer",
                                        frac, base
                                    ))
                                    .span(ast.span),
                                );
                                return Err(());
                            }
                        };
                        let num = int * pow(BigInt::from(base), shift) + frac;
                        let adj = exp - shift as isize;
                        let q = if adj < 0 {
                            BigRational::new(num, pow(BigInt::from(base), (-adj) as usize))
                        } else if adj > 0 {
                            BigRational::from(num * pow(BigInt::from(base), adj as usize))
                        } else {
                            BigRational::from(num)
                        };
                        Term::FloatLit(q)
                    } else {
                        if exp < 0 {
                            self.emit(
                                DiagBuilder2::error(format!(
                                    "integer literal `{}` has negative exponent",
                                    ast.span.extract()
                                ))
                                .span(ast.span),
                            );
                            return Err(());
                        }
                        if exp > 0 {
                            use num::pow;
                            Term::IntLit(int * pow(BigInt::from(base), exp as usize))
                        } else {
                            Term::IntLit(int)
                        }
                    }
                }
                ref wrong => {
                    self.emit(
                        DiagBuilder2::bug(format!(
                            "termification of literal `{}` not implemented",
                            ast.span.extract()
                        ))
                        .span(ast.span)
                        .add_note(format!("{:?}", wrong)),
                    );
                    return Err(());
                }
            },
            ast.span,
        ))
    }
pub fn termify_literal ( & self , ast : Spanned < & Literal > ) -> Result < Spanned < Term < ' a > > > { Ok ( Spanned :: new ( match * ast . value { Literal :: Abstract ( base , int , frac , exp ) => { let base = match base { Some ( base ) => match base . as_str ( ) . parse ( ) { Ok ( base ) => base , Err ( _ ) => { self . emit ( DiagBuilder2 :: error ( format ! ( " " base ) ) . span ( ast . span ) , ) ; return Err ( ( ) ) ; } } , None => 10 , } ; let int = match BigInt :: parse_bytes ( int . as_str ( ) . as_bytes ( ) , base ) { Some ( v ) => v , None => { self . emit ( DiagBuilder2 :: error ( format ! ( " " int base ) ) . span ( ast . span ) , ) ; return Err ( ( ) ) ; } } ; let exp : isize = match exp { Some ( Exponent ( sign , exp ) ) => match exp . as_str ( ) . parse ( ) { Ok ( v ) => { if sign == ExponentSign :: Positive { v } else { - v } } Err ( _ ) => { self . emit ( DiagBuilder2 :: error ( format ! ( " " exp ) ) . span ( ast . span ) , ) ; return Err ( ( ) ) ; } } , None => 0 , } ; // Parse the rest of the number. if let Some ( frac ) = frac { use num :: pow ; let shift = frac . as_str ( ) . len ( ) ; let frac = match BigInt :: parse_bytes ( frac . as_str ( ) . as_bytes ( ) , base ) { Some ( v ) => v , None => { self . emit ( DiagBuilder2 :: error ( format ! ( " " frac base ) ) . span ( ast . span ) , ) ; return Err ( ( ) ) ; } } ; let num = int * pow ( BigInt :: from ( base ) , shift ) + frac ; let adj = exp - shift as isize ; let q = if adj < 0 { BigRational :: new ( num , pow ( BigInt :: from ( base ) , ( - adj ) as usize ) ) } else if adj > 0 { BigRational :: from ( num * pow ( BigInt :: from ( base ) , adj as usize ) ) } else { BigRational :: from ( num ) } ; Term :: FloatLit ( q ) } else { if exp < 0 { self . emit ( DiagBuilder2 :: error ( format ! ( " " ast span extract ( ) ) ) . span ( ast . span ) , ) ; return Err ( ( ) ) ; } if exp > 0 { use num :: pow ; Term :: IntLit ( int * pow ( BigInt :: from ( base ) , exp as usize ) ) } else { Term :: IntLit ( int ) } } } ref wrong => { self . emit ( DiagBuilder2 :: bug ( format ! ( " " ast span extract ( ) ) ) . span ( ast . span ) . add_note ( format ! ( " " wrong ) ) , ) ; return Err ( ( ) ) ; } } , ast . span , ) ) }
Map an AST literal to a term.
Map an AST literal to a term .
&self
ast
Spanned<&Literal>
&self
ast
Spanned<&Literal>