State

Struct State 

Source
pub struct State { /* private fields */ }
Expand description

This is the parser state data structure. It holds the to be read source code and keeps track of the parser head position.

Can be created using parser::State::new:

use wlambda::parser::State;

let code    = "{ 123 }";
let mut ps  = State::new(code, "filenamehere");

// ...

Implementations§

Source§

impl State

Source

pub fn err<E: Into<ParseErrorKind>>(&self, kind: E) -> ParseError

Source

pub fn syn_pos(&self, s: Syntax) -> SynPos

Creates a SynPos annotated with the current parse head position.

Source

pub fn syn_raw(&self, s: Syntax) -> VVal

Creates a VVal::Syn annotated with the current parse head position.

Source

pub fn syn(&self, s: Syntax) -> VVal

Creates an syntactic AST node.

Source

pub fn peek(&self) -> Option<char>

Returns the next character under the parse head. Returns None when the parse head is at EOF.

Source

pub fn at_end(&self) -> bool

Returns if the end of the input was reached.

Source

pub fn rest_len(&self) -> usize

Returns the remaining count of characters in the buffer.

Source

pub fn peek2(&self) -> Option<StrPart<'_>>

Returns the next 2 characters or None if EOF.

Source

pub fn peek3(&self) -> Option<StrPart<'_>>

Returns the next 3 characters or None if EOF.

Source

pub fn peek4(&self) -> Option<StrPart<'_>>

Returns the next 4 characters or None if EOF.

Source

pub fn peek_op_ws_la(&self, la: &str) -> Option<StrPart<'_>>

Tries to peek for an WLambda operator followed by the given look-ahead string.

Source

pub fn peek_op(&self) -> Option<StrPart<'_>>

Tries to peek for an WLambda operator. Returns None either at EOF or if no operator could be found.

Source

pub fn rest(&self) -> StrPart<'_>

Returns the rest of the code after the parse head, including the current character under the parse head.

Source

pub fn consume_while<F>(&mut self, pred: F) -> bool
where F: Fn(char) -> bool,

Consumes characters while pred returns a true value. Returns true if it matched and consumed at least once.

Source

pub fn consume_if_eq_wsc(&mut self, expected_char: char) -> bool

Consumes the expected_char and possibly following white space and comments following it. Returns true if expected_char was found.

Source

pub fn consume_if_eq_ws(&mut self, expected_char: char) -> bool

Consumes the expected_char and possibly following white space following it. Returns true if expected_char was found.

Source

pub fn consume_if_eq(&mut self, expected_char: char) -> bool

Source

pub fn take_while_wsc<F>(&mut self, pred: F) -> StrPart<'_>
where F: Fn(char) -> bool,

Source

pub fn take_while<F>(&mut self, pred: F) -> StrPart<'_>
where F: Fn(char) -> bool,

Source

pub fn indent_pos(&self) -> IndentPos

Source

pub fn last_token_char(&self) -> char

Source

pub fn find_char(&self, c: char) -> Option<usize>

Source

pub fn find_char_not_of(&self, c: char, not_of: &str) -> Option<usize>

Source

pub fn consume_lookahead(&mut self, s: &str) -> bool

Source

pub fn lookahead_one_of(&self, s: &str) -> bool

Source

pub fn lookahead(&mut self, s: &str) -> bool

Source

pub fn consume_wsc_n(&mut self, n: usize)

Source

pub fn consume_wsc(&mut self)

Source

pub fn consume_ws(&mut self)

Source

pub fn consume(&mut self)

Source

pub fn skip_ws(&mut self)

Source

pub fn skip_ws_and_comments(&mut self)

Source

pub fn new(code: &str, filename: &str) -> State

The constructor for the parser::State.

If you need to have a parser state for a syntax that with different white space and comment rules as WLambda please use State::new_verbatim.

use wlambda::parser::State;

let code    = "{ 123 }";
let mut ps  = State::new(code, "filenamehere");
// ...
wlambda::parser::parse_block(&mut ps, true, true, true);
// ...
Source

pub fn new_verbatim(code: &str, filename: &str) -> State

A constructor for the parser::State that does not imply white space and comment rules of the WLambda syntax.

use wlambda::parser::State;

let code    = "  { 123 }";
let mut ps  = State::new_verbatim(code, "filenamehere");
// ...
assert_eq!(ps.peek().unwrap(), ' ');
Source

pub fn is_pattern_ident_mode(&self) -> bool

Source

pub fn set_pattern_ident_mode(&mut self)

Source

pub fn expect_some<T>(&self, o: Option<T>) -> Result<T, ParseError>

Source

pub fn remember(&mut self) -> usize

Source

pub fn collect(&mut self, start: usize, end: usize) -> StrPart<'_>

Auto Trait Implementations§

§

impl Freeze for State

§

impl RefUnwindSafe for State

§

impl !Send for State

§

impl !Sync for State

§

impl Unpin for State

§

impl UnwindSafe for State

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

Source§

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

Source§

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.