Documentation

Stream

Represents an input stream. This allows us to have different types of input, each with their own optimizations.

Tags
psalm-immutable

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
psalm-mutation-free
Return values
string

isEOF()

Test if the stream is at its end.

public isEOF() : bool
Tags
psalm-mutation-free
Return values
bool

take1()

Extract a single token from the stream. Throw if the stream is empty.

public take1() : TakeResult
Tags
throws
EndOfStream
psalm-mutation-free
Return values
TakeResult

takeN()

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:

  1. If the requested length <= 0, the empty token and the original stream should be returned.
  2. If the requested length > 0 and the stream is empty, throw EndOfStream.
  3. 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
throws
EndOfStream
psalm-mutation-free
Return values
TakeResult

takeWhile()

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
Tags
TODO

This method isn't strictly necessary but let's see.

psalm-param

pure-callable(string):bool $predicate

psalm-mutation-free
Return values
TakeResult

        
On this page

Search results