[][src]Struct scanlex::Scanner

pub struct Scanner<'a> {
    pub lineno: u32,
    // some fields omitted
}

a struct for lexical scanning of a string

Fields

lineno: u32

Implementations

impl<'a> Scanner<'a>[src]

pub fn new(s: &'a str) -> Scanner<'a>

Notable traits for Scanner<'a>

impl<'a> Iterator for Scanner<'a> type Item = Token;
[src]

create a new scanner from a string slice.

Empty text is not a problem, but get will then return Token::End.

pub fn no_float(self) -> Scanner<'a>

Notable traits for Scanner<'a>

impl<'a> Iterator for Scanner<'a> type Item = Token;
[src]

this scanner will not recognize floats

"2.5" is tokenized as Int(2),Char('.'),Int(5)

pub fn line_comment(self, c: char) -> Scanner<'a>

Notable traits for Scanner<'a>

impl<'a> Iterator for Scanner<'a> type Item = Token;
[src]

ignore everything in a line after this char

pub fn scan_error(&self, msg: &str, cause: Option<&dyn Error>) -> ScanError[src]

pub fn skip_whitespace(&mut self) -> bool[src]

skip any whitespace characters - return false if we're at the end.

pub fn peek(&self) -> char[src]

look ahead at the next character

pub fn nextch(&mut self) -> char[src]

get the next character

pub fn get(&mut self) -> Token[src]

get the next token

pub fn grab_while<F>(&mut self, pred: F) -> String where
    F: Fn(char) -> bool
[src]

collect chars matching the condition, returning a string

let mut scan = scanlex::Scanner::new("hello + goodbye");
assert_eq!(scan.grab_while(|c| c != '+'), "hello ");

pub fn take_while_into<F>(&mut self, s: &mut String, pred: F) where
    F: Fn(char) -> bool
[src]

collect chars matching the condition into a given string

pub fn skip_until<F>(&mut self, pred: F) -> bool where
    F: Fn(char) -> bool
[src]

skip chars while the condition is false

let mut scan = scanlex::Scanner::new("hello and\nwelcome");
scan.skip_until(|c| c == '\n');
assert_eq!(scan.get_iden().unwrap(),"welcome");

pub fn take_rest(&mut self) -> String[src]

collect the rest of the chars

use scanlex::{Scanner,Token};

let mut scan = Scanner::new("42 the answer");
assert_eq!(scan.get(),Token::Int(42));
assert_eq!(scan.take_rest()," the answer");

pub fn take_until(&mut self, chars: &[char]) -> String[src]

collect until we match one of the chars

pub fn get_string(&mut self) -> Result<String, ScanError>[src]

get a String token, failing otherwise

pub fn get_iden(&mut self) -> Result<String, ScanError>[src]

get an Identifier token, failing otherwise

let mut scan = scanlex::Scanner::new("hello dolly");
assert_eq!(scan.get_iden().unwrap(),"hello");

pub fn get_number(&mut self) -> Result<f64, ScanError>[src]

get a number, failing otherwise

let mut scan = scanlex::Scanner::new("(42)");
scan.get(); // skip '('
assert_eq!(scan.get_number().unwrap(),42.0);

pub fn get_integer(&mut self) -> Result<i64, ScanError>[src]

get an integer, failing otherwise

pub fn get_int<I: Int>(&mut self) -> Result<I::Type, ScanError>[src]

get an integer of a particular type, failing otherwise

pub fn get_float(&mut self) -> Result<f64, ScanError>[src]

get an float, failing otherwise

pub fn get_char(&mut self) -> Result<char, ScanError>[src]

get a character, failing otherwise

pub fn get_ch_matching(&mut self, chars: &[char]) -> Result<char, ScanError>[src]

get a Character token that must be one of the given chars

pub fn skip_chars(&mut self, chars: &str) -> Result<(), ScanError>[src]

skip each character in the string.

pub fn grab_brackets(&mut self, pair: &str) -> Result<String, ScanError>[src]

grab 'balanced' text between some open and close chars

Trait Implementations

impl<'a> Iterator for Scanner<'a>[src]

type Item = Token

The type of the elements being iterated over.

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

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<I> IntoIterator for I where
    I: Iterator
[src]

type Item = <I as Iterator>::Item

The type of the elements being iterated over.

type IntoIter = I

Which kind of iterator are we turning this into?

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.