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
impl State
pub fn err<E: Into<ParseErrorKind>>(&self, kind: E) -> ParseError
Sourcepub fn syn_pos(&self, s: Syntax) -> SynPos
pub fn syn_pos(&self, s: Syntax) -> SynPos
Creates a SynPos annotated with the current parse head position.
Sourcepub fn syn_raw(&self, s: Syntax) -> VVal
pub fn syn_raw(&self, s: Syntax) -> VVal
Creates a VVal::Syn annotated with the current parse head position.
Sourcepub fn peek(&self) -> Option<char>
pub fn peek(&self) -> Option<char>
Returns the next character under the parse head.
Returns None when the parse head is at EOF.
Sourcepub fn peek_op_ws_la(&self, la: &str) -> Option<StrPart<'_>>
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.
Sourcepub fn peek_op(&self) -> Option<StrPart<'_>>
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.
Sourcepub fn rest(&self) -> StrPart<'_>
pub fn rest(&self) -> StrPart<'_>
Returns the rest of the code after the parse head, including the current character under the parse head.
Sourcepub fn consume_while<F>(&mut self, pred: F) -> bool
pub fn consume_while<F>(&mut self, pred: F) -> bool
Consumes characters while pred returns a true value.
Returns true if it matched and consumed at least once.
Sourcepub fn consume_if_eq_wsc(&mut self, expected_char: char) -> bool
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.
Sourcepub fn consume_if_eq_ws(&mut self, expected_char: char) -> bool
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.
pub fn consume_if_eq(&mut self, expected_char: char) -> bool
pub fn take_while_wsc<F>(&mut self, pred: F) -> StrPart<'_>
pub fn take_while<F>(&mut self, pred: F) -> StrPart<'_>
pub fn indent_pos(&self) -> IndentPos
pub fn last_token_char(&self) -> char
pub fn find_char(&self, c: char) -> Option<usize>
pub fn find_char_not_of(&self, c: char, not_of: &str) -> Option<usize>
pub fn consume_lookahead(&mut self, s: &str) -> bool
pub fn lookahead_one_of(&self, s: &str) -> bool
pub fn lookahead(&mut self, s: &str) -> bool
pub fn consume_wsc_n(&mut self, n: usize)
pub fn consume_wsc(&mut self)
pub fn consume_ws(&mut self)
pub fn consume(&mut self)
pub fn skip_ws(&mut self)
pub fn skip_ws_and_comments(&mut self)
Sourcepub fn new(code: &str, filename: &str) -> State
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);
// ...Sourcepub fn new_verbatim(code: &str, filename: &str) -> State
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(), ' ');