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

antlr4-autosuggest-ts

v0.0.28

Published

Autosuggest engine for ANTLR4 grammars

Downloads

75

Readme

JavaScript autosuggest engine for ANTLR4 grammars

Oran Epelbaum

npm version Codacy Badge

Getting the antlr-autosuggest JavaScript Module

npm install --save antlr4-autosuggest

Example

// Load the lexer and parser modules generated by antlr4
const lexerModule = require('./myGrammarLexer');
const parserModule = require('./myGrammarParser');

// Create an autosuggester, providing it with the lexer and parser classes
const autosuggest = require('antlr4-autosuggest');
const autosuggester = autosuggest.autosuggester(lexerModule.myGrammarLexer, parserModule.myGrammarParser);

// Suggest completions for the string "ABC"
let suggestions = autosuggester.autosuggest("ABC");

Advanced Features

Case Preference

Sometimes grammars support both uppercase and lowercase tokens, but completions are expected in just uppercase or lowercase. Specify an UPPER or LOWER case preference to limit suggestions to just uppercase or lowercase:

const autosuggester = autosuggest.autosuggester(lexerModule.myGrammarLexer, parserModule.myGrammarParser, 'LOWER');

How It Works

See explanation in the Java project.

Building & Contributing

To get started:

  • Clone the antlr-autosuggest-js repository.
  • Install Node and NPM (tested with 8)
  • Run the command npm test.

Code contributions are most welcome, but need to maintain a high bar of code cleanliness and test coverage. At a minimum, before submitting a pull request, please run npm test and npm run-script lint to verify that your changes didn't break anything.

It's very important for grammar-related features and fixes to be covered by focused, narrow unit tests. Each unit test must include a short grammar, an even shorter input text, and an expected list of auto-complete suggestions. Unfortunately it's not really possible to write such tests directly in JavaScript, because antlr4's JavaScript engine requires test grammars to have their code generated in advance (i.e., it doesn't provide a runtime grammar interpreter).

To overcome this limitation and write good tests, we actually start out by coding and testing on the Java project first. In Java, antlr4 does offer an interpreter, and therefore unit tests are pretty neat! Once the code and tests are ready in Java, we port the tests automatically to JavaScript with code generation, using the make_js.py utility. The resulting JavaScript tests also looks quite neat despite being completely auto-generated. In the spirit of TDD, once we have failing tests in JavaScript, we manually port the code changes that fix them from Java.

Credits

Written by Oran Epelbaum at Intigua. When starting to write this, studied the following blog posts (though much has changed since):

  • RAPID7: How to Implement ANTLR4 Autocomplete
  • TOMASETTI: Building autocompletion for an editor based on ANTLR by Federico Tomassetti