/// Parses a bit string literal with an optional size already parsed. These
/// are of the form `<size>[B|O|X|D|UB|UO|UX|SB|SO|SX]"<bits>"`.
Parses a bit string literal with an optional size already parsed.
Parses a bit string literal with an optional size already parsed .
fn parse_bit_string_literal(
        &mut self,
        int: Option<Spanned<Name>>,
        base: Spanned<String>,
        mut value: Spanned<String>,
    ) -> Spanned<Token> {
        let (int, mut span) = match int {
            Some(Spanned { value, span }) => (Some(value), span),
            None => (None, base.span),
        };
        span.end = value.span.end;
        // Parse the base.
        let base = match base.value.to_uppercase().as_str() {
            "B" => BitStringBase::B,
            "O" => BitStringBase::O,
            "X" => BitStringBase::X,
            "D" => BitStringBase::D,
            "UB" => BitStringBase::UB,
            "UO" => BitStringBase::UO,
            "UX" => BitStringBase::UX,
            "SB" => BitStringBase::SB,
            "SO" => BitStringBase::SO,
            "SX" => BitStringBase::SX,
            _ => {
                self.emit(
                    DiagBuilder2::error(format!(
                        "`{}` is not a valid base for a bit string literal",
                        base.value
                    ))
                    .span(base.span)
                    .add_note("Valid bases are B, O, X, UB, UO, UX, SB, SO, SX, D"),
                );
                BitStringBase::B
            }
        };
        // Parse the value.
        let mut parsed_value = String::new();
        for c in value.value.drain(..) {
            if !c.is_whitespace() {
                if c != '_' {
                    parsed_value.push(c);
                }
            } else {
                self.emit(
                    DiagBuilder2::error(format!(
                        "Character `{}` may not appear in a bit string literal",
                        c
                    ))
                    .span(value.span),
                );
            }
        }
        let value = get_name_table().intern(&parsed_value, true);
        Spanned::new(Lit(Literal::BitString(int, base, value)), span)
    }
fn parse_bit_string_literal ( & mut self , int : Option < Spanned < Name > > , base : Spanned < String > , mut value : Spanned < String > , ) -> Spanned < Token > { let ( int , mut span ) = match int { Some ( Spanned { value , span } ) => ( Some ( value ) , span ) , None => ( None , base . span ) , } ; span . end = value . span . end ; // Parse the base. let base = match base . value . to_uppercase ( ) . as_str ( ) { " " => BitStringBase :: B , " " => BitStringBase :: O , " " => BitStringBase :: X , " " => BitStringBase :: D , " " => BitStringBase :: UB , " " => BitStringBase :: UO , " " => BitStringBase :: UX , " " => BitStringBase :: SB , " " => BitStringBase :: SO , " " => BitStringBase :: SX , _ => { self . emit ( DiagBuilder2 :: error ( format ! ( " " base value ) ) . span ( base . span ) . add_note ( " " ) , ) ; BitStringBase :: B } } ; // Parse the value. let mut parsed_value = String :: new ( ) ; for c in value . value . drain ( .. ) { if ! c . is_whitespace ( ) { if c != '_' { parsed_value . push ( c ) ; } } else { self . emit ( DiagBuilder2 :: error ( format ! ( " " c ) ) . span ( value . span ) , ) ; } } let value = get_name_table ( ) . intern ( & parsed_value , true ) ; Spanned :: new ( Lit ( Literal :: BitString ( int , base , value ) ) , span ) }
Parses a bit string literal with an optional size already parsed.
Parses a bit string literal with an optional size already parsed .
&mut self
int
Option<Spanned<Name>>
base
Spanned<String>
value
Spanned<String>