fn int_number(number_string: &str, location: &FileLocation) -> Result<SafasCell, ParseError> {
    // Fetch the characters from the string
    let chrs        = number_string.chars().collect::<SmallVec<[_; 8]>>();
    let is_negative = chrs[0] == '-';
    let n_start     = if is_negative { 1 } else { 0 };

    // Format is '1111b8'
    let mut num = 0u128;
    let mut bits = 0u8;

    // Location of the 'b' indicating the number of bits in the number
    let b_pos = chrs.iter()
        .enumerate()
        .filter(|(_pos, chr)| **chr == 'u' || **chr == 'i')
        .map(|(pos, _chr)| pos)
        .nth(0)
        .unwrap_or_else(|| chrs.len());

    // Parse the bits themselves
    for idx in n_start..b_pos {
        num *= 10;

        let chr = chrs[idx];

        if chr >= '0' && chr <= '9' {
            num += ((chr as u8) - ('0' as u8)) as u128;
        } else {
            return Err(ParseError::NotAnIntegerNumber(location.clone(), number_string.to_string()));
        }
    }

    if is_negative {
        num = (-(num as i128)) as u128;
    }

    if b_pos < chrs.len() {
        // Parse the number of bits
        for idx in (b_pos+1)..chrs.len() {
            bits *= 10;
            if chrs[idx] >= '0' && chrs[idx] <= '9' {
                bits += ((chrs[idx] as u16) - ('0' as u16)) as u8;
            } else {
                return Err(ParseError::InvalidBitCount(location.clone(), number_string.to_string()));
            }
        }

        if chrs[b_pos] == 'i' {
            let num = if num & (1<<(bits-1)) != 0 {
                let sign_extend = -1i128 << bits;
                num | (sign_extend as u128)
            } else {
                num
            };

            Ok(SafasCell::Number(SafasNumber::SignedBitNumber(bits, num as i128)))
        } else {
            Ok(SafasCell::Number(SafasNumber::BitNumber(bits, num)))
        }
    } else {
        Ok(SafasCell::Number(SafasNumber::Plain(num)))
    }
}
///
/// Parses an int number (1234u8) as a cell
///
Parses an int number (1234u8) as a cell
Parses an int number ( 1234u8 ) as a cell
fn int_number(number_string: &str, location: &FileLocation) -> Result<SafasCell, ParseError> {
    // Fetch the characters from the string
    let chrs        = number_string.chars().collect::<SmallVec<[_; 8]>>();
    let is_negative = chrs[0] == '-';
    let n_start     = if is_negative { 1 } else { 0 };
    // Format is '1111b8'
    let mut num = 0u128;
    let mut bits = 0u8;
    // Location of the 'b' indicating the number of bits in the number
    let b_pos = chrs.iter()
        .enumerate()
        .filter(|(_pos, chr)| **chr == 'u' || **chr == 'i')
        .map(|(pos, _chr)| pos)
        .nth(0)
        .unwrap_or_else(|| chrs.len());
    // Parse the bits themselves
    for idx in n_start..b_pos {
        num *= 10;
        let chr = chrs[idx];
        if chr >= '0' && chr <= '9' {
            num += ((chr as u8) - ('0' as u8)) as u128;
        } else {
            return Err(ParseError::NotAnIntegerNumber(location.clone(), number_string.to_string()));
        }
    }
    if is_negative {
        num = (-(num as i128)) as u128;
    }
    if b_pos < chrs.len() {
        // Parse the number of bits
        for idx in (b_pos+1)..chrs.len() {
            bits *= 10;
            if chrs[idx] >= '0' && chrs[idx] <= '9' {
                bits += ((chrs[idx] as u16) - ('0' as u16)) as u8;
            } else {
                return Err(ParseError::InvalidBitCount(location.clone(), number_string.to_string()));
            }
        }
        if chrs[b_pos] == 'i' {
            let num = if num & (1<<(bits-1)) != 0 {
                let sign_extend = -1i128 << bits;
                num | (sign_extend as u128)
            } else {
                num
            };
            Ok(SafasCell::Number(SafasNumber::SignedBitNumber(bits, num as i128)))
        } else {
            Ok(SafasCell::Number(SafasNumber::BitNumber(bits, num)))
        }
    } else {
        Ok(SafasCell::Number(SafasNumber::Plain(num)))
    }
}
fn int_number ( number_string : & str , location : & FileLocation ) -> Result < SafasCell , ParseError > { // Fetch the characters from the string let chrs = number_string . chars ( ) . collect :: < SmallVec < [ _ ; 8 ] > > ( ) ; let is_negative = chrs [ 0 ] == '-' ; let n_start = if is_negative { 1 } else { 0 } ; // Format is '1111b8' let mut num = 0u128 ; let mut bits = 0u8 ; // Location of the 'b' indicating the number of bits in the number let b_pos = chrs . iter ( ) . enumerate ( ) . filter ( | ( _pos , chr ) | * * chr == 'u' || * * chr == 'i' ) . map ( | ( pos , _chr ) | pos ) . nth ( 0 ) . unwrap_or_else ( | | chrs . len ( ) ) ; // Parse the bits themselves for idx in n_start .. b_pos { num *= 10 ; let chr = chrs [ idx ] ; if chr >= '0' && chr <= '9' { num += ( ( chr as u8 ) - ( '0' as u8 ) ) as u128 ; } else { return Err ( ParseError :: NotAnIntegerNumber ( location . clone ( ) , number_string . to_string ( ) ) ) ; } } if is_negative { num = ( - ( num as i128 ) ) as u128 ; } if b_pos < chrs . len ( ) { // Parse the number of bits for idx in ( b_pos + 1 ) .. chrs . len ( ) { bits *= 10 ; if chrs [ idx ] >= '0' && chrs [ idx ] <= '9' { bits += ( ( chrs [ idx ] as u16 ) - ( '0' as u16 ) ) as u8 ; } else { return Err ( ParseError :: InvalidBitCount ( location . clone ( ) , number_string . to_string ( ) ) ) ; } } if chrs [ b_pos ] == 'i' { let num = if num & ( 1 << ( bits - 1 ) ) != 0 { let sign_extend = - 1i128 << bits ; num | ( sign_extend as u128 ) } else { num } ; Ok ( SafasCell :: Number ( SafasNumber :: SignedBitNumber ( bits , num as i128 ) ) ) } else { Ok ( SafasCell :: Number ( SafasNumber :: BitNumber ( bits , num ) ) ) } } else { Ok ( SafasCell :: Number ( SafasNumber :: Plain ( num ) ) ) } }
Parses an int number (1234u8) as a cell
Parses an int number ( 1234u8 ) as a cell
number_string
&str
location
&FileLocation
number_string
&str
location
&FileLocation