pub struct Reader<'a> { /* private fields */ }Expand description
Reader with look-ahead and look-behind methods.
As you read text, the part that you’ve read is accumulated
in current_range. The part that you haven’t seen yet is available
in tail_range:
valid range: a b c d e f g
^^^ - current range
^^^^^^^ - tail range
^ - prev char
^ - current char
^ - next charOnce you call reset_buff, current range is advanced to start
at the current char, and shrunk to zero length:
valid range: a b c d e f g
. - current range (empty, starts at `d`)
^^^^^^ - tail range
^ - prev char
^ - current char
^ - next charThe workflow in roughly this:
- you read characters, they’re put into
saved_range; - once you’re at a token boundary, you emit a token with
saved_range, then callreset_buff, - you continue onto the next token.
Implementations§
Source§impl<'a> Reader<'a>
impl<'a> Reader<'a>
pub fn new(text: &'a str) -> Self
pub fn new_with_range(text: &'a str, range: SourceRange) -> Self
pub fn bump(&mut self)
pub fn reset_buff(&mut self)
pub fn reset_buff_into_sub_reader(&mut self) -> Reader<'a>
pub fn is_eof(&self) -> bool
pub fn is_start_of_line(&self) -> bool
pub fn prev_char(&self) -> char
pub fn current_char(&self) -> char
pub fn next_char(&mut self) -> char
pub fn current_range(&self) -> SourceRange
pub fn tail_range(&self) -> SourceRange
pub fn current_text(&self) -> &'a str
pub fn tail_text(&self) -> &'a str
pub fn eat_when(&mut self, ch: char) -> usize
pub fn consume_char_n_times(&mut self, ch: char, count: usize) -> usize
pub fn consume_n_times<F>(&mut self, func: F, count: usize) -> usize
pub fn eat_while<F>(&mut self, func: F) -> usize
pub fn eat_till_end(&mut self) -> usize
pub fn get_source_text(&self) -> &'a str
pub fn get_current_end_pos(&self) -> usize
Trait Implementations§
Auto Trait Implementations§
impl<'a> Freeze for Reader<'a>
impl<'a> RefUnwindSafe for Reader<'a>
impl<'a> Send for Reader<'a>
impl<'a> Sync for Reader<'a>
impl<'a> Unpin for Reader<'a>
impl<'a> UnwindSafe for Reader<'a>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more