[][src]Struct saltwater::Lexer

pub struct Lexer { /* fields omitted */ }

A Lexer takes the source code and turns it into tokens with location information.

Tokens are either literals, keywords, identifiers, or builtin operations. This allows the parser to worry about fewer things at a time. Location information is irritating to deal with but allows for better error messages. This is the reason the filename is mandatory, so that it can be shown in errors. You may also find the warn and error functions in utils.rs to be useful.

Lexer implements iterator, so you can loop over the tokens.

Implementations

impl Lexer[src]

pub fn new<S: Into<Rc<str>>>(file: FileId, chars: S, debug: bool) -> Lexer

Important traits for Lexer

impl Iterator for Lexer type Item = Result<Locatable<Token>, Locatable<LexError>>;
[src]

Creates a Lexer from a filename and the contents of a file

pub fn next_non_whitespace(
    &mut self
) -> Option<Result<Locatable<Token>, Locatable<LexError>>>
[src]

Returns next token in stream which is not whitespace

Trait Implementations

impl Debug for Lexer[src]

impl Iterator for Lexer[src]

type Item = Result<Locatable<Token>, Locatable<LexError>>

The type of the elements being iterated over.

fn next(&mut self) -> Option<Self::Item>[src]

Return the next token in the stream.

This iterator never resumes after it is depleted, i.e. once it returns None once, it will always return None.

Any item may be an error, but items will always have an associated location. The file may be empty to start, in which case the iterator will return None.

Auto Trait Implementations

impl !RefUnwindSafe for Lexer

impl !Send for Lexer

impl !Sync for Lexer

impl Unpin for Lexer

impl UnwindSafe for Lexer

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<I> IteratorRandom for I where
    I: Iterator
[src]

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.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,