1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#![doc = include_str!("../README.md")]
#![cfg_attr(not(feature = "std"), no_std)]

mod peekable;

pub use peekable::PeekableLexer;

use logos::{Lexer, Logos, Source, Span};

pub trait LogosIter<'source, T>: Iterator<Item = T>
where
    T: Logos<'source>,
{
    fn span(&self) -> Span;

    fn slice(&self) -> &'source <T::Source as Source>::Slice;

    fn source(&self) -> &'source T::Source;

    fn remainder(&self) -> &'source <T::Source as Source>::Slice;

    fn bump(&mut self, n: usize);

    fn extras(&self) -> &T::Extras;

    fn extras_mut(&mut self) -> &mut T::Extras;

    /// See [`PeekableLexer`].
    // we don't use `peekable` name to avoid ambiguity (it's a compiler error)
    // between `LogosIter`'s method and `Iterator`'s one
    fn peekable_lexer(self) -> PeekableLexer<'source, Self, T>
    where
        Self: Sized,
    {
        PeekableLexer {
            lexer: self,
            peeked: None,
        }
    }
}

impl<'source, T> LogosIter<'source, T> for Lexer<'source, T>
where
    T: Logos<'source>,
{
    fn span(&self) -> Span {
        Lexer::span(self)
    }

    fn slice(&self) -> &'source <T::Source as Source>::Slice {
        Lexer::slice(self)
    }

    fn source(&self) -> &'source T::Source {
        Lexer::source(self)
    }

    fn remainder(&self) -> &'source <T::Source as Source>::Slice {
        Lexer::remainder(self)
    }

    fn bump(&mut self, n: usize) {
        Lexer::bump(self, n)
    }

    fn extras(&self) -> &T::Extras {
        &self.extras
    }

    fn extras_mut(&mut self) -> &mut T::Extras {
        &mut self.extras
    }
}