Trait combpop::stream::Stream [] [src]

pub trait Stream {
    type Item;
    fn lookahead(&mut self, len: usize) -> ParseResult<()>;
fn get(&self, idx: usize) -> &Self::Item;
fn advance(&mut self, len: usize);
fn mark(&mut self) -> StreamMark;
fn rollback(&mut self, pos: StreamMark);
fn commit(&mut self); }

Stream is a stream of tokens with lookahead/rollback ability.

Semantics

A stream is thought to be a set of the following data:

  • The sequence of tokens S
  • The monotone sequence of marks M
  • The current position i, which is not less than any marks
  • The lookahead position j, which is not less than the current position

The actual streams have to remember only the part of the tokens, due to the contract described in the Stream::get method below.

Associated Types

The type of the token. Note that Stream::get actually returns a reference to I.

Required Methods

Tries to push the lookahead position forward.

  • If i + len <= j, then it does nothing.
  • If i + len > j and it hit an I/O error, then it returns Err.
  • If i + len > j and it hit an EOF, then it returns Err(ParseError::EOF).
  • Otherwise, it updates j to i + len and returns Ok.

Retrieves the looked-ahead token.

The caller must ensure that i + idx < j. Otherwise it may panic.

Advances the current position.

The caller must ensure that i + idx < j. Otherwise it may panic.

Pushes the current position to the mark stack M.

Pops i from the mark stack M.

pos argument must match to the corresponding Stream::mark call.

Pops a value from the mark stack M and discard it.

The mark stack M must not be empty.

Implementors