pub struct LexicalAnalyzer<LexemeType> { /* private fields */ }
Expand description
A lexical analyzer.
A lexical analyzer is a computation unit (an automaton), that is capable of reading a stream of characters, and separating it into Lexemes: atomic sequences units of meaningful text, tokens. See crate::lex for more detail.
Implementations§
Source§impl<LexemeType> LexicalAnalyzer<LexemeType>
impl<LexemeType> LexicalAnalyzer<LexemeType>
Sourcepub fn new(
lexeme_descriptors: Vec<LexemeDescriptor<LexemeType>>,
) -> LexicalAnalyzer<LexemeType>
pub fn new( lexeme_descriptors: Vec<LexemeDescriptor<LexemeType>>, ) -> LexicalAnalyzer<LexemeType>
Builds a new LexicalAnalyzer.
The different LexemeType
s that the analyzer will be capable of recognizing are described
by lexeme_descriptors
.
Sourcepub fn analyze<'a>(
&'a self,
reader: &'a mut impl Reader<u8>,
) -> impl Iterator<Item = Lexeme<LexemeType>> + 'a
pub fn analyze<'a>( &'a self, reader: &'a mut impl Reader<u8>, ) -> impl Iterator<Item = Lexeme<LexemeType>> + 'a
Parses a stream of input text specified by a reader
, and yields the lexemes it is consists
of.
§Conflict Resolution
- Longer lexemes are prioritized.
- Among the matching
LexemeType
s for a lexeme of a given length, priority is given to theLexemeType
whose LexemeDescriptor was listed first during the LexicalAnalyzer’s construction (see thelexeme_descriptors
argument of LexicalAnalyzer::new).
§Panics
If no known LexemeType
could be matched against a prefix of the remaining input.
Auto Trait Implementations§
impl<LexemeType> Freeze for LexicalAnalyzer<LexemeType>
impl<LexemeType> RefUnwindSafe for LexicalAnalyzer<LexemeType>where
LexemeType: RefUnwindSafe,
impl<LexemeType> Send for LexicalAnalyzer<LexemeType>where
LexemeType: Send,
impl<LexemeType> Sync for LexicalAnalyzer<LexemeType>where
LexemeType: Sync,
impl<LexemeType> Unpin for LexicalAnalyzer<LexemeType>where
LexemeType: Unpin,
impl<LexemeType> UnwindSafe for LexicalAnalyzer<LexemeType>where
LexemeType: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more