Trait chomp::primitives::Primitives [] [src]

pub trait Primitives: Input {
    fn peek(&mut self) -> Option<Self::Token> { ... }
    fn pop(&mut self) -> Option<Self::Token> { ... }
    fn consume(&mut self, n: usize) -> Option<Self::Buffer> { ... }
    fn consume_while<F>(&mut self, f: F) -> Self::Buffer
    where
        F: FnMut(Self::Token) -> bool
, { ... } fn consume_from(&mut self, m: Self::Marker) -> Self::Buffer { ... } fn consume_remaining(&mut self) -> Self::Buffer { ... } fn skip_while<F>(&mut self, f: F)
    where
        F: FnMut(Self::Token) -> bool
, { ... } fn mark(&self) -> Self::Marker { ... } fn restore(self, m: Self::Marker) -> Self { ... } }

Trait enabling primitive actions on an Input type.

This trait is automatically implemented for all types implementing Input and acts as a gatekeeper to the state-modifying methods of Input.

Provided Methods

Peeks at the next token in the input without consuming it. None if no more input is available.

Note: Is allowed to refill automatically or any other appropriate action if the input does not contain any more data.

Pops a token off the start of the input. None if no more input is available.

Note: Is allowed to refill automatically or any other appropriate action if the input does not contain any more data.

Attempt to consume n tokens, if it fails do not advance the position but return None.

Note: Is allowed to refill automatically or any other appropriate action if the input does not contain any more data.

Runs the closure F on the tokens in order until it returns false, all tokens up to that token will be returned as a buffer and discarded from the current input. MUST never run the closure more than once on the exact same token.

If the end of the input is reached, the whole input is returned.

Note: Is allowed to refill automatically or any other appropriate action if the input does not contain any more data.

Returns the buffer from the marker to the current position, discarding the backtracking position carried by the marker.

Returns the remainder of the input in a buffer.

Note: Will refill the intenal buffer until no more data is available if the underlying implementation supports it.

Runs the closure F on the tokens in order until it returns false, all tokens up to that token will be discarded from the current input.

MUST never run the closure more than once on the exact same token.

If the end of the input is reached, the whole input is discarded.

Note: Default implementation uses consume_while and makes the assumption that it will optimize away the resulting Self::Buffer.

Marks the current position to be able to backtrack to it using restore.

Resumes from a previously marked state.

Implementors