scnr

Struct Scanner

Source
pub struct Scanner { /* private fields */ }
Expand description

A Scanner. It consists of multiple DFAs that are used to search for matches.

Each DFA corresponds to a terminal symbol (token type) the lexer/scanner can recognize. The DFAs are advanced in parallel to search for matches. It further constists of at least one scanner mode. Scanners support multiple scanner modes. This feature is known from Flex as Start conditions and provides more flexibility by defining several scanners for several parts of your grammar. See https://www.cs.princeton.edu/~appel/modern/c/software/flex/flex.html#SEC11 for more information.

To create a scanner, you can use the ScannerBuilder to add scanner mode data. At least one scanner mode must be added to the scanner. This is usually the mode named INITIAL.

Implementations§

Source§

impl Scanner

Source

pub fn try_new(scanner_modes: Vec<ScannerMode>, use_nfa: bool) -> Result<Self>

Creates a new scanner. The scanner is created with the given scanner modes. The ScannerImpl is created from the scanner modes and the use_nfa flag determines if the scanner uses a DFAs or an NFAs for the pattern matching.

Source

pub fn find_iter<'h>(&self, input: &'h str) -> FindMatches<'h>

Returns an iterator over all non-overlapping matches. The iterator yields a Match value until no more matches could be found.

Source

pub fn log_compiled_automata_as_dot(&self, modes: &[ScannerMode]) -> Result<()>

Logs the compiled DFAs as a Graphviz DOT file with the help of the log crate. To enable debug output compliled DFA as dot file set the environment variable RUST_LOG to scnr::internal::scanner_impl=debug.

Source

pub fn generate_compiled_automata_as_dot( &self, modes: &[ScannerMode], target_folder: &Path, ) -> Result<()>

Generates the compiled DFAs as a Graphviz DOT files. The DOT files are written to the target folder. The file names are derived from the scanner mode names and the index of the DFA.

Trait Implementations§

Source§

impl Debug for Scanner

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl ScannerModeSwitcher for Scanner

Source§

fn current_mode(&self) -> usize

Returns the current scanner mode.

Source§

fn set_mode(&mut self, mode: usize)

Sets the current scanner mode.

A parser can explicitly set the scanner mode to switch to a different set of DFAs. Usually, the scanner mode is changed by the scanner itself based on the transitions defined in the active scanner mode.

Source§

fn mode_name(&self, index: usize) -> Option<&str>

Returns the name of the scanner mode with the given index. If the index is out of bounds, None is returned.

Auto Trait Implementations§

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.