Home Manual Reference Source
public class | source

Tape

Class that wraps a callable with a tape. Do not use directly. Use fromCallable instead.

Constructor Summary

Public Constructor
public

constructor(callable: Function)

The constructor.

Member Summary

Public Members
public

Buffer used to implement Tape#unread.

public

The callable yielding values to put on the tape.

public

eof: any

The eof symbol.

Method Summary

Public Methods
public

[Symbol.asyncIterator](): AsyncIterator

Returns an async iterator on the tokens of the tape.

public

Explicitely throws when trying to access iterator symbol.

public

async read(): Promise

Returns the next token on the tape or Tape#eof if the tape has been exhausted.

public

async skip()

Skips the next token on the tape.

public

async skipMany(n: number)

Skip the next n tokens on the tape.

public

unread(token: any)

Puts a token back on the tape.

Public Constructors

public constructor(callable: Function) source

The constructor. Stores the callable that yields values to put on the tape.

Params:

NameTypeAttributeDescription
callable Function

The callable to use.

Public Members

public buffer: Array source

Buffer used to implement Tape#unread.

public callable: Function source

The callable yielding values to put on the tape.

public eof: any source

The eof symbol.

Public Methods

public [Symbol.asyncIterator](): AsyncIterator source

Returns an async iterator on the tokens of the tape.

Return:

AsyncIterator

Iterator on the tokens of the tape.

Example:

fromString('abc');
for await ( const token of tape ) console.log(token) ;

public [Symbol.iterator]() source

Explicitely throws when trying to access iterator symbol.

Throw:

Error

Always.

public async read(): Promise source

Returns the next token on the tape or Tape#eof if the tape has been exhausted.

Return:

Promise

The next token on the tape or Tape#eof.

public async skip() source

Skips the next token on the tape.

public async skipMany(n: number) source

Skip the next n tokens on the tape.

Params:

NameTypeAttributeDescription
n number

The number of tokens to skip.

public unread(token: any) source

Puts a token back on the tape. If Tape#read is used just after, this token will be returned.

Params:

NameTypeAttributeDescription
token any

The token to put back on the tape.