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
impl Scanner
Sourcepub fn try_new(scanner_modes: Vec<ScannerMode>, use_nfa: bool) -> Result<Self>
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.
Sourcepub fn find_iter<'h>(&self, input: &'h str) -> FindMatches<'h> ⓘ
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.
Sourcepub fn log_compiled_automata_as_dot(&self, modes: &[ScannerMode]) -> Result<()>
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.
Sourcepub fn generate_compiled_automata_as_dot(
&self,
modes: &[ScannerMode],
target_folder: &Path,
) -> Result<()>
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 ScannerModeSwitcher for Scanner
impl ScannerModeSwitcher for Scanner
Source§fn current_mode(&self) -> usize
fn current_mode(&self) -> usize
Returns the current scanner mode.