pub trait IntStream {
    fn consume(&mut self);
    fn la(&mut self, i: isize) -> isize;
    fn mark(&mut self) -> isize;
    fn release(&mut self, marker: isize);
    fn index(&self) -> isize;
    fn seek(&mut self, index: isize);
    fn size(&self) -> isize;
    fn get_source_name(&self) -> String;
}
Expand description

A simple stream of symbols whose values are represented as integers. This interface provides marked ranges with support for a minimum level of buffering necessary to implement arbitrary lookahead during prediction.

Required Methods

Consumes the current symbol in the stream. Advances this stream to the next element.

This method has the following effects:

  • Forward movement: The value of index before calling this method is less than the value of index after calling this method.
  • Ordered lookahead: The value of {@code LA(1)} before calling this method becomes the value of {@code LA(-1)} after calling this method.

Note that calling this method does not guarantee that index() is incremented by exactly 1.

Allowed to panic if trying to consume EOF

Lookaheads (or loopbacks if i is negative)

Gets the value of the symbol at offset {@code i} from the current position. When {@code i==1}, this method returns the value of the current symbol in the stream (which is the next symbol to be consumed). When {@code i==-1}, this method returns the value of the previously read symbol in the stream. It is not valid to call this method with {@code i==0}, but the specific behavior is unspecified because this method is frequently called from performance-critical code.

Note that default Lexer does not call this method with anything other than -1 so it can be used for optimizations in downstream implementations.

Must return EOF if i points to position at or beyond the end of the stream

After this call subsequent calls to seek must succeed if seek index is greater than mark index

Returns marker that should be used later by release call to release this stream from

Releases marker

Returns current position of the input stream

If there is active marker from mark then calling seek later with result of this call should put stream in same state it is currently in.

Put stream back in state it was when it was in index position

Allowed to panic if index does not belong to marked region(via mark-release calls)

Returns the total number of symbols in the stream.

Returns name of the source this stream operates over if any

Implementors