fn interpret_float_lit(&mut self, value: &str, token_name: &str) -> PResult<BigRational> {
        // float_lit = decimals "." [ decimals ] [ exponent ] |
        //             decimals exponent |
        //             "." decimals [ exponent ] .
        // decimals  = decimal_digit { decimal_digit } .
        // exponent  = ( "e" | "E" ) [ "+" | "-" ] decimals .
        trace!("interpret_float_lit");

        let mut res = BigRational::from_integer(BigInt::from(0u8));
        let mut chars = value.chars().peekable();
        let mut parse_exponent = false;
        let mut digits_after_dot = 0u32; // the number of digits after the dot we are

        while let Some(c) = chars.next() {
            if c == '.' {
                digits_after_dot = 1;
            } else if c == 'e' || c == 'E' {
                parse_exponent = true;
                break;
            } else {
                let digit = c.to_digit(10).expect("BUG: invalid char in float/imag lit");
                let digit_value = BigRational::from_integer(BigInt::from(digit));

                if digits_after_dot == 0 {
                    res = res * BigRational::from_integer(BigInt::from(10u8));
                    res = res + BigRational::from_integer(BigInt::from(digit));
                } else {
                    res = res +
                          digit_value /
                          BigRational::from_integer(BigInt::from(10u32.pow(digits_after_dot)));

                    digits_after_dot += 1;
                }
            }
        }

        if parse_exponent {
            let mut negative = false;
            if let Some(&c) = chars.peek() {
                if c == '+' {
                    chars.next();
                } else if c == '-' {
                    negative = true;
                    chars.next();
                }
            } else {
                // Empty exponent
                return Err(self.err(ErrorKind::other(format!("malformed {} exponent",
                                                             token_name))));
            }

            let mut exponent = 0;
            while let Some(c) = chars.next() {
                exponent *= 10;
                exponent += c.to_digit(10).expect("BUG: invalid char in float/imag lit exponent");
            }

            for _ in 0..exponent {
                if negative {
                    res = res / BigRational::from_integer(BigInt::from(10u8));
                } else {
                    res = res * BigRational::from_integer(BigInt::from(10u8));
                }
            }
        }

        Ok(res)
    }
/// Interpret the value of a float/imaginary literal and return the result as a BigRational.
/// If this method is being used to parse an imaginary lit, don't include the trailing `i`.
Interpret the value of a float/imaginary literal and return the result as a BigRational.
If this method is being used to parse an imaginary lit, don't include the trailing `i`.
Interpret the value of a float / imaginary literal and return the result as a BigRational . If this method is being used to parse an imaginary lit don ' t include the trailing ` i ` .
fn interpret_float_lit(&mut self, value: &str, token_name: &str) -> PResult<BigRational> {
        // float_lit = decimals "." [ decimals ] [ exponent ] |
        //             decimals exponent |
        //             "." decimals [ exponent ] .
        // decimals  = decimal_digit { decimal_digit } .
        // exponent  = ( "e" | "E" ) [ "+" | "-" ] decimals .
        trace!("interpret_float_lit");
        let mut res = BigRational::from_integer(BigInt::from(0u8));
        let mut chars = value.chars().peekable();
        let mut parse_exponent = false;
        let mut digits_after_dot = 0u32; // the number of digits after the dot we are
        while let Some(c) = chars.next() {
            if c == '.' {
                digits_after_dot = 1;
            } else if c == 'e' || c == 'E' {
                parse_exponent = true;
                break;
            } else {
                let digit = c.to_digit(10).expect("BUG: invalid char in float/imag lit");
                let digit_value = BigRational::from_integer(BigInt::from(digit));
                if digits_after_dot == 0 {
                    res = res * BigRational::from_integer(BigInt::from(10u8));
                    res = res + BigRational::from_integer(BigInt::from(digit));
                } else {
                    res = res +
                          digit_value /
                          BigRational::from_integer(BigInt::from(10u32.pow(digits_after_dot)));
                    digits_after_dot += 1;
                }
            }
        }
        if parse_exponent {
            let mut negative = false;
            if let Some(&c) = chars.peek() {
                if c == '+' {
                    chars.next();
                } else if c == '-' {
                    negative = true;
                    chars.next();
                }
            } else {
                // Empty exponent
                return Err(self.err(ErrorKind::other(format!("malformed {} exponent",
                                                             token_name))));
            }
            let mut exponent = 0;
            while let Some(c) = chars.next() {
                exponent *= 10;
                exponent += c.to_digit(10).expect("BUG: invalid char in float/imag lit exponent");
            }
            for _ in 0..exponent {
                if negative {
                    res = res / BigRational::from_integer(BigInt::from(10u8));
                } else {
                    res = res * BigRational::from_integer(BigInt::from(10u8));
                }
            }
        }
        Ok(res)
    }
fn interpret_float_lit ( & mut self , value : & str , token_name : & str ) -> PResult < BigRational > { // float_lit = decimals "." [ decimals ] [ exponent ] | //             decimals exponent | //             "." decimals [ exponent ] . // decimals  = decimal_digit { decimal_digit } . // exponent  = ( "e" | "E" ) [ "+" | "-" ] decimals . trace ! ( " " ) ; let mut res = BigRational :: from_integer ( BigInt :: from ( 0u8 ) ) ; let mut chars = value . chars ( ) . peekable ( ) ; let mut parse_exponent = false ; let mut digits_after_dot = 0u32 ; // the number of digits after the dot we are while let Some ( c ) = chars . next ( ) { if c == '.' { digits_after_dot = 1 ; } else if c == 'e' || c == 'E' { parse_exponent = true ; break ; } else { let digit = c . to_digit ( 10 ) . expect ( " " ) ; let digit_value = BigRational :: from_integer ( BigInt :: from ( digit ) ) ; if digits_after_dot == 0 { res = res * BigRational :: from_integer ( BigInt :: from ( 10u8 ) ) ; res = res + BigRational :: from_integer ( BigInt :: from ( digit ) ) ; } else { res = res + digit_value / BigRational :: from_integer ( BigInt :: from ( 10u32 . pow ( digits_after_dot ) ) ) ; digits_after_dot += 1 ; } } } if parse_exponent { let mut negative = false ; if let Some ( & c ) = chars . peek ( ) { if c == '+' { chars . next ( ) ; } else if c == '-' { negative = true ; chars . next ( ) ; } } else { // Empty exponent return Err ( self . err ( ErrorKind :: other ( format ! ( " " token_name ) ) ) ) ; } let mut exponent = 0 ; while let Some ( c ) = chars . next ( ) { exponent *= 10 ; exponent += c . to_digit ( 10 ) . expect ( " " ) ; } for _ in 0 .. exponent { if negative { res = res / BigRational :: from_integer ( BigInt :: from ( 10u8 ) ) ; } else { res = res * BigRational :: from_integer ( BigInt :: from ( 10u8 ) ) ; } } } Ok ( res ) }
Interpret the value of a float/imaginary literal and return the result as a BigRational.
Interpret the value of a float / imaginary literal and return the result as a BigRational .
&mut self
value
&str
token_name
&str