Struct LexicalAnalyzer

Source
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>
where LexemeType: Hash + Eq + Clone,

Source

pub fn new( lexeme_descriptors: Vec<LexemeDescriptor<LexemeType>>, ) -> LexicalAnalyzer<LexemeType>

Builds a new LexicalAnalyzer.

The different LexemeTypes that the analyzer will be capable of recognizing are described by lexeme_descriptors.

Source

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 LexemeTypes for a lexeme of a given length, priority is given to the LexemeType whose LexemeDescriptor was listed first during the LexicalAnalyzer’s construction (see the lexeme_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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.