npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

ts-antlr4-scanner

v0.1.0

Published

A scanner for antlr-based lexers.

Downloads

1,297

Readme

ts-antlr4-scanner

Alt Text

A scanner for antlr4-based lexers.

Alt Text

Features

  • Lookahead support
  • Lookback support
  • Advance to position
  • Advance to token type

Installation

yarn add ts-antlr4-scanner
# or
npm install ts-antlr4-scanner

Usage

import { CommonTokenStream, ANTLRInputStream } from 'antlr4ts'
import { MySQLLexer } from 'ts-mysql-parser'
import { Scanner } from 'ts-antlr4-scanner'

const text = 'SELECT * FROM users'

const inputStream = new ANTLRInputStream(text)
const lexer = new MySQLLexer(inputStream) // Or any antlr4 lexer
const tokenStream = new CommonTokenStream(lexer)
const scanner = new Scanner(tokenStream)

// Move to character L of SELECT
scanner.advanceToPosition(3)

const tokenText = scanner.tokenText()
console.log(tokenText) // SELECT

API

new Scanner(tokenStream)

Creates a new instance of Scanner with the given token stream.

.next()

Advances to the next token.

scanner.next()

.previous()

Returns to the previous token.

scanner.previous()

.advanceToPosition(offset)

Advances to the token that covers the given zero-based offset.

scanner.advanceToPosition(4)

.advanceToType(type)

Advances to the next token with the given lexical type.

scanner.advanceToType(14)

.skipTokenSequence(sequence)

Steps over a number of tokens and positions.

scanner.skipTokenSequence([1, 5, 8])

.lookAhead()

Returns the type of the next token without changing the internal state.

scanner.lookAhead()

.lookBack()

Look back in the stream (physical order) what was before the current token, without modifying the current position.

scanner.lookBack()

.reset()

Resets the walker to be at the original location.

scanner.reset()

.push()

Store the current node on the stack, so we can easily come back when needed.

scanner.push()

.pop()

Returns to the location at the top of the token stack (if any).

scanner.pop()

.tokenText()

Returns the textual expression of the current token.

scanner.tokenText()

.tokenType()

Returns the type of the current token.

scanner.tokenType()

.tokenIndex()

Returns the (zero-based) index of the current token within the input.

scanner.tokenIndex()

.tokenLine()

Returns the (one-based) line number of the token.

scanner.tokenLine()

.tokenStart()

Returns the offset of the current token in its source string.

scanner.tokenStart()

.tokenLength()

Returns the length of the current token in bytes.

scanner.tokenLength()

.tokenChannel()

Returns the channel of the current token.

scanner.tokenChannel()

.tokenSubText()

Returns all the input text from the current token to the end.

scanner.tokenSubText()

Related

License

MIT


stevenmiller888.github.io  ·  GitHub @stevenmiller888  ·  Twitter @stevenmiller888