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>

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.

source

pub fn new(chars: &'a mut dyn Iterator<Item = char>) -> Self

New instance, based on an Iterator of char

source

pub fn clear(&mut self)

Reset the internal state of the scanner, without resetting the state of the underlying char iterator

source

pub fn pushback(&mut self)

Push the last read character (and it’s coords) onto the pushback buffer

source

pub fn position(&self) -> Coords

Get the absolute position in the underlying input

source

pub fn front(&self) -> Option<CharWithCoords>

Get the optional char at the front of the scanner buffer

source

pub fn back(&self) -> Option<CharWithCoords>

Get the optional char at the back of the scanner buffer

source

pub fn advance(&mut self, skip_whitespace: bool) -> ScannerResult<()>

Advance the scanner to the next available character, optionally skipping whitespace.

source

pub fn try_lookahead(&mut self) -> Option<char>

Try and look ahead one char in the input stream

source

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

source

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

source

pub fn buffer_as_char_array(&mut self) -> Vec<char>

Extract the scanner buffer as a char slice

source

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

Auto Trait Implementations§

§

impl<'a> !RefUnwindSafe for Scanner<'a>

§

impl<'a> !Send for Scanner<'a>

§

impl<'a> !Sync for Scanner<'a>

§

impl<'a> Unpin for Scanner<'a>

§

impl<'a> !UnwindSafe for Scanner<'a>

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>,

§

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>,

§

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.