---
source: logos-codegen/tests/codegen.rs
expression: formatted
---
impl<'s> ::logos::Logos<'s> for Token {
    type Error = ();
    type Extras = ();
    type Source = [u8];
    fn lex(
        lex: &mut ::logos::Lexer<'s, Self>,
    ) -> std::option::Option<
        std::result::Result<Self, <Self as ::logos::Logos<'s>>::Error>,
    > {
        use ::logos::internal::{
            LexerInternal, CallbackRetVal, CallbackResult, SkipRetVal, SkipResult,
        };
        use std::result::Result as _Result;
        use std::option::Option as _Option;
        use ::logos::Logos;
        type _Lexer<'s> = ::logos::Lexer<'s, Token>;
        macro_rules! _fast_loop {
            ($lex:ident, $test:ident, $offset:ident) => {
                'fast_loop : { while let Some(arr) = $lex .read:: < & [u8; 8usize] >
                ($offset) { if $test (arr[0usize]) { $offset += 0usize; break 'fast_loop;
                } if $test (arr[1usize]) { $offset += 1usize; break 'fast_loop; } if
                $test (arr[2usize]) { $offset += 2usize; break 'fast_loop; } if $test
                (arr[3usize]) { $offset += 3usize; break 'fast_loop; } if $test
                (arr[4usize]) { $offset += 4usize; break 'fast_loop; } if $test
                (arr[5usize]) { $offset += 5usize; break 'fast_loop; } if $test
                (arr[6usize]) { $offset += 6usize; break 'fast_loop; } if $test
                (arr[7usize]) { $offset += 7usize; break 'fast_loop; } $offset += 8usize;
                } while let Some(byte) = $lex .read:: < u8 > ($offset) { if $test (byte)
                { break 'fast_loop; } $offset += 1; } }
            };
        }
        macro_rules! _take_action {
            ($lex:ident, $offset:ident, $context:ident, $state:ident) => {
                { let action = _get_action($lex, $offset, $context); match action {
                CallbackResult::Emit(tok) => { return Some(Ok(tok)); },
                CallbackResult::Skip => { $lex .trivia(); $offset = $lex .offset();
                $context = None; return state3($lex, $offset, $context); },
                CallbackResult::Error(err) => { return Some(Err(err)); },
                CallbackResult::DefaultError => { return Some(Err(_make_error($lex))); },
                } }
            };
        }
        #[inline]
        fn _make_error<'s>(lex: &mut _Lexer<'s>) -> <Token as Logos<'s>>::Error {
            <Token as Logos<'s>>::Error::default()
        }
        #[inline]
        fn _get_action<'s>(
            lex: &mut _Lexer<'s>,
            offset: usize,
            context: _Option<LogosLeaf>,
        ) -> CallbackResult<'s, Token> {
            match context {
                None => {
                    lex.end_to_boundary(offset.max(lex.offset() + 1));
                    CallbackResult::Error(_make_error(lex))
                }
                Some(LogosLeaf::Leaf0) => CallbackResult::Emit(Token::Newline),
                Some(LogosLeaf::Leaf1) => CallbackResult::Emit(Token::AnyUnicode),
                Some(LogosLeaf::Leaf2) => CallbackResult::Emit(Token::Any),
            }
        }
        #[derive(Clone, Copy)]
        enum LogosLeaf {
            Leaf0 = 0isize,
            Leaf1 = 1isize,
            Leaf2 = 2isize,
        }
        fn state0<'s>(
            lex: &mut _Lexer<'s>,
            mut offset: usize,
            mut context: _Option<LogosLeaf>,
        ) -> _Option<_Result<Token, <Token as Logos<'s>>::Error>> {
            let other = lex.read::<u8>(offset);
            if let Some(byte) = other {
                if (matches!(byte, 128u8..= 191u8)) {
                    offset += 1;
                    return state1(lex, offset, context);
                }
            } else {}
            _take_action!(lex, offset, context, state)
        }
        fn state1<'s>(
            lex: &mut _Lexer<'s>,
            mut offset: usize,
            mut context: _Option<LogosLeaf>,
        ) -> _Option<_Result<Token, <Token as Logos<'s>>::Error>> {
            let other = lex.read::<u8>(offset);
            if let Some(byte) = other {
                if (matches!(byte, 128u8..= 191u8)) {
                    offset += 1;
                    return state2(lex, offset, context);
                }
            } else {}
            _take_action!(lex, offset, context, state)
        }
        fn state2<'s>(
            lex: &mut _Lexer<'s>,
            mut offset: usize,
            mut context: _Option<LogosLeaf>,
        ) -> _Option<_Result<Token, <Token as Logos<'s>>::Error>> {
            lex.end(offset);
            context = Some(LogosLeaf::Leaf1);
            let other = lex.read::<u8>(offset);
            if let Some(byte) = other {} else {}
            _take_action!(lex, offset, context, state)
        }
        fn state3<'s>(
            lex: &mut _Lexer<'s>,
            mut offset: usize,
            mut context: _Option<LogosLeaf>,
        ) -> _Option<_Result<Token, <Token as Logos<'s>>::Error>> {
            let other = lex.read::<u8>(offset);
            if let Some(byte) = other {
                #[derive(Copy, Clone)]
                enum LogosNextState {
                    ___,
                    State2,
                    State4,
                    State5,
                    State6,
                    State7,
                    State8,
                    State9,
                    State10,
                    State11,
                    State12,
                }
                const TABLE: [LogosNextState; 256] = {
                    use LogosNextState::*;
                    [
                        State2,
                        State2,
                        State2,
                        State2,
                        State2,
                        State2,
                        State2,
                        State2,
                        State2,
                        State2,
                        State8,
                        State2,
                        State2,
                        State2,
                        State2,
                        State2,
                        State2,
                        State2,
                        State2,
                        State2,
                        State2,
                        State2,
                        State2,
                        State2,
                        State2,
                        State2,
                        State2,
                        State2,
                        State2,
                        State2,
                        State2,
                        State2,
                        State2,
                        State2,
                        State2,
                        State2,
                        State2,
                        State2,
                        State2,
                        State2,
                        State2,
                        State2,
                        State2,
                        State2,
                        State2,
                        State2,
                        State2,
                        State2,
                        State2,
                        State2,
                        State2,
                        State2,
                        State2,
                        State2,
                        State2,
                        State2,
                        State2,
                        State2,
                        State2,
                        State2,
                        State2,
                        State2,
                        State2,
                        State2,
                        State2,
                        State2,
                        State2,
                        State2,
                        State2,
                        State2,
                        State2,
                        State2,
                        State2,
                        State2,
                        State2,
                        State2,
                        State2,
                        State2,
                        State2,
                        State2,
                        State2,
                        State2,
                        State2,
                        State2,
                        State2,
                        State2,
                        State2,
                        State2,
                        State2,
                        State2,
                        State2,
                        State2,
                        State2,
                        State2,
                        State2,
                        State2,
                        State2,
                        State2,
                        State2,
                        State2,
                        State2,
                        State2,
                        State2,
                        State2,
                        State2,
                        State2,
                        State2,
                        State2,
                        State2,
                        State2,
                        State2,
                        State2,
                        State2,
                        State2,
                        State2,
                        State2,
                        State2,
                        State2,
                        State2,
                        State2,
                        State2,
                        State2,
                        State2,
                        State2,
                        State2,
                        State2,
                        State2,
                        State2,
                        State9,
                        State9,
                        State9,
                        State9,
                        State9,
                        State9,
                        State9,
                        State9,
                        State9,
                        State9,
                        State9,
                        State9,
                        State9,
                        State9,
                        State9,
                        State9,
                        State9,
                        State9,
                        State9,
                        State9,
                        State9,
                        State9,
                        State9,
                        State9,
                        State9,
                        State9,
                        State9,
                        State9,
                        State9,
                        State9,
                        State9,
                        State9,
                        State9,
                        State9,
                        State9,
                        State9,
                        State9,
                        State9,
                        State9,
                        State9,
                        State9,
                        State9,
                        State9,
                        State9,
                        State9,
                        State9,
                        State9,
                        State9,
                        State9,
                        State9,
                        State9,
                        State9,
                        State9,
                        State9,
                        State9,
                        State9,
                        State9,
                        State9,
                        State9,
                        State9,
                        State9,
                        State9,
                        State9,
                        State9,
                        State9,
                        State9,
                        State10,
                        State10,
                        State10,
                        State10,
                        State10,
                        State10,
                        State10,
                        State10,
                        State10,
                        State10,
                        State10,
                        State10,
                        State10,
                        State10,
                        State10,
                        State10,
                        State10,
                        State10,
                        State10,
                        State10,
                        State10,
                        State10,
                        State10,
                        State10,
                        State10,
                        State10,
                        State10,
                        State10,
                        State10,
                        State10,
                        State11,
                        State12,
                        State12,
                        State12,
                        State12,
                        State12,
                        State12,
                        State12,
                        State12,
                        State12,
                        State12,
                        State12,
                        State12,
                        State7,
                        State12,
                        State12,
                        State4,
                        State5,
                        State5,
                        State5,
                        State6,
                        State9,
                        State9,
                        State9,
                        State9,
                        State9,
                        State9,
                        State9,
                        State9,
                        State9,
                        State9,
                        State9,
                    ]
                };
                offset += 1;
                match TABLE[byte as usize] {
                    LogosNextState::State2 => {
                        return state2(lex, offset, context);
                    }
                    LogosNextState::State4 => {
                        return state4(lex, offset, context);
                    }
                    LogosNextState::State5 => {
                        return state5(lex, offset, context);
                    }
                    LogosNextState::State6 => {
                        return state6(lex, offset, context);
                    }
                    LogosNextState::State7 => {
                        return state7(lex, offset, context);
                    }
                    LogosNextState::State8 => {
                        return state8(lex, offset, context);
                    }
                    LogosNextState::State9 => {
                        return state9(lex, offset, context);
                    }
                    LogosNextState::State10 => {
                        return state10(lex, offset, context);
                    }
                    LogosNextState::State11 => {
                        return state11(lex, offset, context);
                    }
                    LogosNextState::State12 => {
                        return state12(lex, offset, context);
                    }
                    LogosNextState::___ => {}
                }
                offset -= 1;
            } else {
                if lex.offset() == offset {
                    return None;
                }
            }
            _take_action!(lex, offset, context, state)
        }
        fn state4<'s>(
            lex: &mut _Lexer<'s>,
            mut offset: usize,
            mut context: _Option<LogosLeaf>,
        ) -> _Option<_Result<Token, <Token as Logos<'s>>::Error>> {
            lex.end(offset);
            context = Some(LogosLeaf::Leaf2);
            let other = lex.read::<u8>(offset);
            if let Some(byte) = other {
                if (matches!(byte, 144u8..= 191u8)) {
                    offset += 1;
                    return state0(lex, offset, context);
                }
            } else {}
            _take_action!(lex, offset, context, state)
        }
        fn state5<'s>(
            lex: &mut _Lexer<'s>,
            mut offset: usize,
            mut context: _Option<LogosLeaf>,
        ) -> _Option<_Result<Token, <Token as Logos<'s>>::Error>> {
            lex.end(offset);
            context = Some(LogosLeaf::Leaf2);
            let other = lex.read::<u8>(offset);
            if let Some(byte) = other {
                if (matches!(byte, 128u8..= 191u8)) {
                    offset += 1;
                    return state0(lex, offset, context);
                }
            } else {}
            _take_action!(lex, offset, context, state)
        }
        fn state6<'s>(
            lex: &mut _Lexer<'s>,
            mut offset: usize,
            mut context: _Option<LogosLeaf>,
        ) -> _Option<_Result<Token, <Token as Logos<'s>>::Error>> {
            lex.end(offset);
            context = Some(LogosLeaf::Leaf2);
            let other = lex.read::<u8>(offset);
            if let Some(byte) = other {
                if (matches!(byte, 128u8..= 143u8)) {
                    offset += 1;
                    return state0(lex, offset, context);
                }
            } else {}
            _take_action!(lex, offset, context, state)
        }
        fn state7<'s>(
            lex: &mut _Lexer<'s>,
            mut offset: usize,
            mut context: _Option<LogosLeaf>,
        ) -> _Option<_Result<Token, <Token as Logos<'s>>::Error>> {
            lex.end(offset);
            context = Some(LogosLeaf::Leaf2);
            let other = lex.read::<u8>(offset);
            if let Some(byte) = other {
                if (matches!(byte, 128u8..= 159u8)) {
                    offset += 1;
                    return state1(lex, offset, context);
                }
            } else {}
            _take_action!(lex, offset, context, state)
        }
        fn state8<'s>(
            lex: &mut _Lexer<'s>,
            mut offset: usize,
            mut context: _Option<LogosLeaf>,
        ) -> _Option<_Result<Token, <Token as Logos<'s>>::Error>> {
            lex.end(offset);
            context = Some(LogosLeaf::Leaf0);
            let other = lex.read::<u8>(offset);
            if let Some(byte) = other {} else {}
            _take_action!(lex, offset, context, state)
        }
        fn state9<'s>(
            lex: &mut _Lexer<'s>,
            mut offset: usize,
            mut context: _Option<LogosLeaf>,
        ) -> _Option<_Result<Token, <Token as Logos<'s>>::Error>> {
            lex.end(offset);
            context = Some(LogosLeaf::Leaf2);
            let other = lex.read::<u8>(offset);
            if let Some(byte) = other {} else {}
            _take_action!(lex, offset, context, state)
        }
        fn state10<'s>(
            lex: &mut _Lexer<'s>,
            mut offset: usize,
            mut context: _Option<LogosLeaf>,
        ) -> _Option<_Result<Token, <Token as Logos<'s>>::Error>> {
            lex.end(offset);
            context = Some(LogosLeaf::Leaf2);
            let other = lex.read::<u8>(offset);
            if let Some(byte) = other {
                if (matches!(byte, 128u8..= 191u8)) {
                    offset += 1;
                    return state2(lex, offset, context);
                }
            } else {}
            _take_action!(lex, offset, context, state)
        }
        fn state11<'s>(
            lex: &mut _Lexer<'s>,
            mut offset: usize,
            mut context: _Option<LogosLeaf>,
        ) -> _Option<_Result<Token, <Token as Logos<'s>>::Error>> {
            lex.end(offset);
            context = Some(LogosLeaf::Leaf2);
            let other = lex.read::<u8>(offset);
            if let Some(byte) = other {
                if (matches!(byte, 160u8..= 191u8)) {
                    offset += 1;
                    return state1(lex, offset, context);
                }
            } else {}
            _take_action!(lex, offset, context, state)
        }
        fn state12<'s>(
            lex: &mut _Lexer<'s>,
            mut offset: usize,
            mut context: _Option<LogosLeaf>,
        ) -> _Option<_Result<Token, <Token as Logos<'s>>::Error>> {
            lex.end(offset);
            context = Some(LogosLeaf::Leaf2);
            let other = lex.read::<u8>(offset);
            if let Some(byte) = other {
                if (matches!(byte, 128u8..= 191u8)) {
                    offset += 1;
                    return state1(lex, offset, context);
                }
            } else {}
            _take_action!(lex, offset, context, state)
        }
        state3(lex, lex.offset(), None)
    }
}
