Stream
in
Represents an input stream. This allows us to have different types of input, each with their own optimizations.
Tags
Table of Contents
Methods
- __toString() : string
- isEOF() : bool
- Test if the stream is at its end.
- take1() : TakeResult
- Extract a single token from the stream. Throw if the stream is empty.
- takeN() : TakeResult
- Try to extract a chunk of length $n, or if the stream is too short, the rest of the stream.
- takeWhile() : TakeResult
- Extract a chunk of the stream, by taking tokens as long as the predicate holds. Return the chunk and the rest of the stream.
Methods
__toString()
public
__toString() : string
We will need to get rid of this again at some point, we can't assume all streams will be strings
Tags
Return values
stringisEOF()
Test if the stream is at its end.
public
isEOF() : bool
Tags
Return values
booltake1()
Extract a single token from the stream. Throw if the stream is empty.
public
take1() : TakeResult
Tags
Return values
TakeResulttakeN()
Try to extract a chunk of length $n, or if the stream is too short, the rest of the stream.
public
takeN(int $n) : TakeResult
Valid implementation should follow the rules:
- If the requested length <= 0, the empty token and the original stream should be returned.
- If the requested length > 0 and the stream is empty, throw EndOfStream.
- In other cases, take a chunk of length $n (or shorter if the stream is not long enough) from the input stream and return the chunk along with the rest of the stream.
Parameters
- $n : int
Tags
Return values
TakeResulttakeWhile()
Extract a chunk of the stream, by taking tokens as long as the predicate holds. Return the chunk and the rest of the stream.
public
takeWhile(callable $predicate) : TakeResult
Parameters
- $predicate : callable