[−][src]Struct muncher::Muncher
Methods
impl<'a> Muncher<'a>
[src]
pub fn new(input: &'a str) -> Self
[src]
Creates a new Muncher
of the given input.
Example
use muncher::Muncher; let input = "parsable input"; let munch = Muncher::new(input);
pub fn fork(&self) -> Fork
[src]
A peekable fork that does not alter the position of
the Muncher
Example
use muncher::Muncher; let input = "abcde"; let mut munch = Muncher::new(input); assert_eq!(munch.eat(), Some('a')); let fork = munch.fork(); assert_eq!(fork.peek(), Some(&'b')); assert_eq!(munch.eat(), Some('b')); assert_eq!(munch.eat(), Some('c'));
pub fn brace_stack(&self) -> Stack
[src]
Returns a Stack
that parses matching braces, making sure every
brace is closed.
Example
use muncher::Muncher; let input = "abcde"; let mut munch = Muncher::new(input); let stack = munch.brace_stack();
pub fn text(&self) -> &str
[src]
Returns the whole input text as &str
.
pub fn position(&self) -> usize
[src]
The position of Muncher
, not its peek position.
pub fn is_done(&self) -> bool
[src]
Returns true when next counter has exhausted input.
pub fn cursor_position(&self) -> (usize, usize)
[src]
Returns colum and line position, both start at (1, 1).
Example
use muncher::Muncher; let input = "abcde"; let mut munch = Muncher::new(input); munch.eat(); assert_eq!(munch.cursor_position(), (2, 1));
pub fn reset_peek(&self) -> usize
[src]
Resets Muncher.peek
to current Muncher.next
pub fn peek(&self) -> Option<&char>
[src]
Gets the char at Muncher.peek
index then increments Muncher.peek
by one
pub fn peek_until<P>(&self, pred: P) -> impl Iterator<Item = &char> where
P: FnMut(&char) -> bool,
[src]
P: FnMut(&char) -> bool,
Peek tokens until given predicate is true. Resets the peek position every time called.
Example
use muncher::Muncher; let input = "abcde"; let mut munch = Muncher::new(input); let text = munch.peek_until(|ch| ch == &'d').collect::<String>(); assert_eq!(text, "abc"); assert_eq!(munch.eat(), Some('a'));
pub fn peek_until_count<P>(&self, pred: P) -> (usize, usize) where
P: FnMut(&char) -> bool,
[src]
P: FnMut(&char) -> bool,
Peek tokens until given predicate is true returns start and end. Resets the peek position every time called.
Example
use muncher::Muncher; let input = "abcde"; let mut munch = Muncher::new(input); let (start, end) = munch.peek_until_count(|ch| ch == &'d'); assert_eq!(&munch.text()[start..end], "abc"); assert_eq!(munch.eat(), Some('a'));
pub fn peek_range_of(&self, needle: &str) -> (usize, usize)
[src]
Peeks tokens until needle is found returns start and end. Resets the peek position every time called.
Example
use muncher::Muncher; let input = "abcde"; let mut munch = Muncher::new(input); let (start, end) = munch.peek_range_of("d"); assert_eq!(&munch.text()[start..end], "abc"); assert_eq!(munch.eat(), Some('a'));
pub fn seek(&self, count: usize) -> Option<String>
[src]
Returns Some(&str)
if seek
does not run into the end
of the input.
Example
use muncher::Muncher; let input = "hello world"; let m = Muncher::new(input); assert_eq!(m.seek(5), Some("hello".to_string()));
pub fn eat(&mut self) -> Option<char>
[src]
Eats the next char if not at end of input
Example
use muncher::Muncher; let input = "abc"; let mut m = Muncher::new(input); assert_eq!(m.eat(), Some('a')); assert_eq!(m.eat(), Some('b')); assert_eq!(m.eat(), Some('c')); assert_eq!(m.eat(), None);
pub fn eat_ws(&mut self) -> bool
[src]
Eats next white space if next char is space and returns true.
pub fn eat_eol(&mut self) -> bool
[src]
Eats next newline if next char is newline and returns true. This handles both windows and unix line endings.
pub fn eat_eq(&mut self) -> bool
[src]
Eats =
and returns true, false if not found
pub fn eat_open_brc(&mut self) -> bool
[src]
Eats [
and returns true, false if not found
pub fn eat_close_brc(&mut self) -> bool
[src]
Eats ]
and returns true, false if not found
pub fn eat_open_curly(&mut self) -> bool
[src]
Eats {
and returns true, false if not found
pub fn eat_close_curly(&mut self) -> bool
[src]
Eats }
and returns true, false if not found
pub fn eat_open_paren(&mut self) -> bool
[src]
Eats (
and returns true, false if not found
pub fn eat_close_paren(&mut self) -> bool
[src]
Eats )
and returns true, false if not found
pub fn eat_double_quote(&mut self) -> bool
[src]
Eats "
and returns true, false if not found
pub fn eat_single_quote(&mut self) -> bool
[src]
Eats '
and returns true, false if not found
pub fn eat_comma(&mut self) -> bool
[src]
Eats ,
and returns true, false if not found
pub fn eat_hash(&mut self) -> bool
[src]
Eats #
and returns true, false if not found
pub fn eat_plus(&mut self) -> bool
[src]
Eats +
and returns true, false if not found
pub fn eat_minus(&mut self) -> bool
[src]
Eats -
and returns true, false if not found
pub fn eat_colon(&mut self) -> bool
[src]
Eats :
and returns true, false if not found
pub fn eat_dot(&mut self) -> bool
[src]
Eats .
and returns true, false if not found
pub fn eat_until<P>(&mut self, pred: P) -> impl Iterator<Item = char> where
P: FnMut(&char) -> bool,
[src]
P: FnMut(&char) -> bool,
Eat tokens until given predicate is true.
Example
use muncher::Muncher; let input = "abcde"; let mut munch = Muncher::new(input); let text = munch.eat_until(|ch| ch == &'d').collect::<String>(); assert_eq!(text, "abc"); assert_eq!(munch.eat(), Some('d'));
pub fn eat_until_count<P>(&mut self, pred: P) -> (usize, usize) where
P: FnMut(&char) -> bool,
[src]
P: FnMut(&char) -> bool,
Eats tokens until given predicate is true returns start and end.
Example
use muncher::Muncher; let input = "abcde"; let mut munch = Muncher::new(input); let (start, end) = munch.eat_until_count(|ch| ch == &'d'); assert_eq!(&munch.text()[start..end], "abc"); assert_eq!(munch.eat(), Some('d'));
pub fn eat_range_of(&mut self, needle: &str) -> (usize, usize)
[src]
Eat tokens until needle is found returns start and end. Resets the peek position every time called.
Example
use muncher::Muncher; let input = "abcde"; let mut munch = Muncher::new(input); let (start, end) = munch.eat_range_of("d"); assert_eq!(&munch.text()[start..end], "abc"); assert_eq!(munch.eat(), Some('d'));
Trait Implementations
Auto Trait Implementations
impl<'a> !RefUnwindSafe for Muncher<'a>
impl<'a> Send for Muncher<'a>
impl<'a> !Sync for Muncher<'a>
impl<'a> Unpin for Muncher<'a>
impl<'a> UnwindSafe for Muncher<'a>
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,