/// Parse any of the symbols in the language. `c0` comes from a
/// `Bundle::Special` that has already been parsed.
Parse any of the symbols in the language. `c0` comes from a
`Bundle::Special` that has already been parsed.
Parse any of the symbols in the language . ` c0 ` comes from a ` Bundle :: Special ` that has already been parsed .
fn parse_symbol(&mut self, c0: char, mut span: Span) -> Option<Spanned<Token>> {
        let n1 = self.inner.next();
        let n2 = self.inner.next();
        // Try to parse a three-character symbol.
        if let (
            &Some(Spanned {
                value: Bundle::Special(c1),
                ..
            }),
            &Some(Spanned {
                value: Bundle::Special(c2),
                span: sp,
            }),
        ) = (&n1, &n2)
        {
            if let Some(tkn) = match (c0, c1, c2) {
                ('?', '/', '=') => Some(MatchNeq),
                ('?', '<', '=') => Some(MatchLeq),
                ('?', '>', '=') => Some(MatchGeq),
                _ => None,
            } {
                span.expand(sp);
                return Some(Spanned::new(tkn, span));
            }
        }
        self.inner.undo(n2);
        // Try to parse a two-character symbol.
        if let &Some(Spanned {
            value: Bundle::Special(c1),
            span: sp,
        }) = &n1
        {
            if let Some(tkn) = match (c0, c1) {
                ('=', '>') => Some(Arrow),
                ('?', '?') => Some(Condition),
                ('<', '>') => Some(LtGt),
                (':', '=') => Some(VarAssign),
                ('<', '<') => Some(Lshift),
                ('>', '>') => Some(Rshift),
                ('/', '=') => Some(Neq),
                ('<', '=') => Some(Leq),
                ('>', '=') => Some(Geq),
                ('?', '=') => Some(MatchEq),
                ('?', '<') => Some(MatchLt),
                ('?', '>') => Some(MatchGt),
                ('*', '*') => Some(Pow),
                _ => None,
            } {
                span.expand(sp);
                return Some(Spanned::new(tkn, span));
            }
        }
        self.inner.undo(n1);
        // Try to parse a one-character symbol.
        if let Some(tkn) = match c0 {
            '(' => Some(OpenDelim(Paren)),
            ')' => Some(CloseDelim(Paren)),
            '[' => Some(OpenDelim(Brack)),
            ']' => Some(CloseDelim(Brack)),
            '.' => Some(Period),
            ',' => Some(Comma),
            ':' => Some(Colon),
            ';' => Some(Semicolon),
            '\'' => Some(Apostrophe),
            '&' => Some(Ampersand),
            '=' => Some(Eq),
            '<' => Some(Lt),
            '>' => Some(Gt),
            '+' => Some(Add),
            '-' => Some(Sub),
            '*' => Some(Mul),
            '/' => Some(Div),
            '|' => Some(Pipe),
            '?' => Some(Qmark),
            _ => None,
        } {
            return Some(Spanned::new(tkn, span));
        }
        // If we get here, we parsed something which is allowed in VHDL source
        // text, but is not a valid symbol on its own.
        self.emit(DiagBuilder2::error(format!("`{}` is not a valid symbol", c0)).span(span));
        None
    }
fn parse_symbol ( & mut self , c0 : char , mut span : Span ) -> Option < Spanned < Token > > { let n1 = self . inner . next ( ) ; let n2 = self . inner . next ( ) ; // Try to parse a three-character symbol. if let ( & Some ( Spanned { value : Bundle :: Special ( c1 ) , .. } ) , & Some ( Spanned { value : Bundle :: Special ( c2 ) , span : sp , } ) , ) = ( & n1 , & n2 ) { if let Some ( tkn ) = match ( c0 , c1 , c2 ) { ( '?' , '/' , '=' ) => Some ( MatchNeq ) , ( '?' , '<' , '=' ) => Some ( MatchLeq ) , ( '?' , '>' , '=' ) => Some ( MatchGeq ) , _ => None , } { span . expand ( sp ) ; return Some ( Spanned :: new ( tkn , span ) ) ; } } self . inner . undo ( n2 ) ; // Try to parse a two-character symbol. if let & Some ( Spanned { value : Bundle :: Special ( c1 ) , span : sp , } ) = & n1 { if let Some ( tkn ) = match ( c0 , c1 ) { ( '=' , '>' ) => Some ( Arrow ) , ( '?' , '?' ) => Some ( Condition ) , ( '<' , '>' ) => Some ( LtGt ) , ( ':' , '=' ) => Some ( VarAssign ) , ( '<' , '<' ) => Some ( Lshift ) , ( '>' , '>' ) => Some ( Rshift ) , ( '/' , '=' ) => Some ( Neq ) , ( '<' , '=' ) => Some ( Leq ) , ( '>' , '=' ) => Some ( Geq ) , ( '?' , '=' ) => Some ( MatchEq ) , ( '?' , '<' ) => Some ( MatchLt ) , ( '?' , '>' ) => Some ( MatchGt ) , ( '*' , '*' ) => Some ( Pow ) , _ => None , } { span . expand ( sp ) ; return Some ( Spanned :: new ( tkn , span ) ) ; } } self . inner . undo ( n1 ) ; // Try to parse a one-character symbol. if let Some ( tkn ) = match c0 { '(' => Some ( OpenDelim ( Paren ) ) , ')' => Some ( CloseDelim ( Paren ) ) , '[' => Some ( OpenDelim ( Brack ) ) , ']' => Some ( CloseDelim ( Brack ) ) , '.' => Some ( Period ) , ',' => Some ( Comma ) , ':' => Some ( Colon ) , ';' => Some ( Semicolon ) , '\'' => Some ( Apostrophe ) , '&' => Some ( Ampersand ) , '=' => Some ( Eq ) , '<' => Some ( Lt ) , '>' => Some ( Gt ) , '+' => Some ( Add ) , '-' => Some ( Sub ) , '*' => Some ( Mul ) , '/' => Some ( Div ) , '|' => Some ( Pipe ) , '?' => Some ( Qmark ) , _ => None , } { return Some ( Spanned :: new ( tkn , span ) ) ; } // If we get here, we parsed something which is allowed in VHDL source // text, but is not a valid symbol on its own. self . emit ( DiagBuilder2 :: error ( format ! ( " " c0 ) ) . span ( span ) ) ; None }
Parse any of the symbols in the language.
Parse any of the symbols in the language .
&mut self
c0
char
span
Span