Struct chisel_lexers::scanner::Scanner
source · pub struct Scanner<'a> { /* private fields */ }Expand description
Simple LA(1) scanner which wraps itself around a source of chars and converts raw characters into CharWithCoords structures. Also provides a running buffer which can be used to accumulate input characters, prior to extracting them and tokenising them.
Implementations§
source§impl<'a> Scanner<'a>
impl<'a> Scanner<'a>
An input adapter used by the lexer. A Scanner is responsible for managing input state to to provide access to segments (or individual characters) from within the source input.
sourcepub fn clear(&mut self)
pub fn clear(&mut self)
Reset the internal state of the scanner, without resetting the state of the underlying char iterator
sourcepub fn pushback(&mut self)
pub fn pushback(&mut self)
Push the last read character (and it’s coords) onto the pushback buffer
sourcepub fn front(&self) -> Option<CharWithCoords>
pub fn front(&self) -> Option<CharWithCoords>
Get the optional char at the front of the scanner buffer
sourcepub fn back(&self) -> Option<CharWithCoords>
pub fn back(&self) -> Option<CharWithCoords>
Get the optional char at the back of the scanner buffer
sourcepub fn advance(&mut self, skip_whitespace: bool) -> ScannerResult<()>
pub fn advance(&mut self, skip_whitespace: bool) -> ScannerResult<()>
Advance the scanner to the next available character, optionally skipping whitespace.
sourcepub fn try_lookahead(&mut self) -> Option<char>
pub fn try_lookahead(&mut self) -> Option<char>
Try and look ahead one char in the input stream
sourcepub fn advance_n(
&mut self,
n: usize,
skip_whitespace: bool
) -> ScannerResult<()>
pub fn advance_n( &mut self, n: usize, skip_whitespace: bool ) -> ScannerResult<()>
Advance the scanner over n available characters, returning a ScannerError if it’s not possible to do so. After calling this method the input state should be read using the other associated functions available for this type
sourcepub fn buffer_as_string_with_span(&mut self) -> StringWithSpan
pub fn buffer_as_string_with_span(&mut self) -> StringWithSpan
Extract the scanner buffer as a StringWithSpan. Will return an empty string if there’s nothing in the buffer
sourcepub fn buffer_as_char_array(&mut self) -> Vec<char>
pub fn buffer_as_char_array(&mut self) -> Vec<char>
Extract the scanner buffer as a char slice
sourcepub fn buffer_as_byte_array(&self) -> Vec<u8>
pub fn buffer_as_byte_array(&self) -> Vec<u8>
Extract the scanner buffer as a byte buffer. You just get an empty vec if the buffer is currently empty