token-stream

WebJar for token-stream

License

License

MIT
GroupId

GroupId

org.webjars.npm
ArtifactId

ArtifactId

token-stream
Last Version

Last Version

0.0.1
Release Date

Release Date

Type

Type

jar
Description

Description

token-stream
WebJar for token-stream
Project URL

Project URL

http://webjars.org
Source Code Management

Source Code Management

https://github.com/pugjs/token-stream

Download token-stream

How to add to project

<!-- https://jarcasting.com/artifacts/org.webjars.npm/token-stream/ -->
<dependency>
    <groupId>org.webjars.npm</groupId>
    <artifactId>token-stream</artifactId>
    <version>0.0.1</version>
</dependency>
// https://jarcasting.com/artifacts/org.webjars.npm/token-stream/
implementation 'org.webjars.npm:token-stream:0.0.1'
// https://jarcasting.com/artifacts/org.webjars.npm/token-stream/
implementation ("org.webjars.npm:token-stream:0.0.1")
'org.webjars.npm:token-stream:jar:0.0.1'
<dependency org="org.webjars.npm" name="token-stream" rev="0.0.1">
  <artifact name="token-stream" type="jar" />
</dependency>
@Grapes(
@Grab(group='org.webjars.npm', module='token-stream', version='0.0.1')
)
libraryDependencies += "org.webjars.npm" % "token-stream" % "0.0.1"
[org.webjars.npm/token-stream "0.0.1"]

Dependencies

There are no dependencies for this project. It is a standalone project that does not depend on any other jars.

Project Modules

There are no modules declared in this project.

token-stream

Take an array of token and produce a more useful API to give to a parser.

Build Status Dependency Status NPM version

Installation

npm install token-stream

Usage

var TokenStream = require('token-stream');

var stream = new TokenStream([
  'a',
  'b',
  'c',
  'd'
]);
assert(stream.peek() === 'a');
assert(stream.lookahead(0) == 'a');
assert(stream.lookahead(1) == 'b');

assert(stream.advance() === 'a');
assert(stream.peek() === 'b');
assert(stream.lookahead(0) == 'b');
assert(stream.lookahead(1) == 'c');

stream.defer('z');
assert(stream.peek() === 'z');
assert(stream.lookahead(0) == 'z');
assert(stream.lookahead(1) == 'b');
assert(stream.advance() === 'z');
assert(stream.advance() === 'b');
assert(stream.advance() === 'c');
assert(stream.advance() === 'd');

// an error is thrown if you try and advance beyond the end of the stream
assert.throws(function () {
  stream.advance();
});

API

stream.peek()

Gets and returns the next item in the stream without advancing the stream's position.

stream.advance()

Returns the next item in the stream and advances the stream by one item.

stream.defer(token)

Put a token on the start of the stream (useful if you need to back track after calling advance).

stream.lookahead(index)

Return the item at index position from the start of the stream, but don't advance the stream. stream.lookahead(0) is equivalent to stream.peek().

License

MIT

org.webjars.npm

Pug

Versions

Version
0.0.1