Optimized TypeScript target for ANTLR 4
TypeScript ANTLR Java JavaScript
Clone or download
BurtHarris Merge pull request #372 from Que3216/patch-1
Add `sideEffects: false` to package.json to support tree shaking
Latest commit e192e3f Jul 3, 2018
Failed to load latest commit information.
.vscode Fix the tsc watcher that runs when Ctrl+Shift+B is used in VS Code May 19, 2018
benchmark Merge pull request #370 from sharwell/no-unsafe-any May 27, 2018
reference Update reference to tunnelvisionlabs/antlr4@e44c0ec and apply changes Jan 8, 2017
src Merge pull request #371 from sharwell/api-cleanup May 30, 2018
target/src Add package-lock.json files created by npm 6.0.1 May 23, 2018
test Merge pull request #371 from sharwell/api-cleanup May 30, 2018
tool Rename the 'prepublish' script to 'prepare' to avoid npm warnings May 24, 2018
.appveyor.yml Use npm 6 for CI builds May 24, 2018
.editorconfig Update .editorconfig to include formatting for grammar files Nov 2, 2016
.gitattributes Fix the antlr4ts script for use on Linux systems Dec 18, 2016
.gitignore Move runtime-testsuite generated files Nov 8, 2016
.gitmodules Update the submodule URI to reference tunnelvisionlabs/antlr4 Jan 4, 2017
.travis.yml Use npm 6 for CI builds May 24, 2018
CONTRIBUTING.md + note about git submodule update Mar 7, 2017
CONVERSION.md Update CONVERSION.md May 23, 2018
LICENSE Update the copyright to read The ANTLR Project Dec 29, 2016
README.md Merge pull request #238 from sharwell/fix-group Nov 5, 2016
antlr4ts.njsproj Remove ProjectView property from the project file Oct 14, 2016
antlr4ts.sln Initial checkin of VS integration effort. Oct 5, 2016
package-lock.json Add types for std-mocks and remove unnecessary uses May 24, 2018
package.json Add `sideEffects: false` to package.json to support tree shaking Jun 29, 2018
tsconfig.json Port Lexer Tests to Mocha Nov 9, 2016
tslint.json Enable tslint 'no-unsafe-any' and fix remaining violations May 24, 2018


antlr4ts - TypeScript/JavaScript target for ANTLR 4

Join the chat at https://gitter.im/tunnelvisionlabs/antlr4ts

Build status



  • Releases: See the GitHub Releases page for release notes and links to the distribution
  • Feedback: Use GitHub Issues for issues (bugs, enhancements, features, and questions)


This project has separate requirements for developers and end users.

💡 The requirements listed on this page only cover user scenarios - that is, scenarios where developers wish to use ANTLR 4 for parsing tasks inside of a TypeScript application. If you are interested in contributing to ANTLR 4 itself, see CONTRIBUTING.md for contributor documentation.

End user requirements

Parsers generated by the ANTLR 4 TypeScript target have a runtime dependency on the antlr4ts package. The package is tested and known to work with Node.js 6.7.

Development requirements

The tool used to generate TypeScript code from an ANTLR 4 grammar is written in Java. To fully utilize the ANTLR 4 TypeScript target (including the ability to regenerate code from a grammar file after changes are made), a Java Runtime Environment (JRE) needs to be installed on the developer machine. The generated code itself uses several features new to TypeScript 2.0.

  • Java Runtime Environment 1.6+ (1.8+ recommended)
  • TypeScript 2.0+

Getting started

  1. Add antlr4ts to package.json as a runtime dependency

    "dependencies": {
      // ...
      "antlr4ts": "^0.2.0"
  2. Add antlr4ts-cli to package.json as a development dependency

    "devDependencies": {
      // ...
      "antlr4ts-cli": "^0.2.0"
  3. Add a grammar to your project, e.g. path/to/MyGrammar.g4

  4. Add a script to package.json for compiling your grammar to TypeScript

    "scripts": {
      // ...
      "antlr4ts": "antlr4ts -visitor path/to/MyGrammar.g4"
  5. Use your grammar in TypeScript

    import { ANTLRInputStream, CommonTokenStream } from 'antlr4ts';
    // Create the lexer and parser
    let inputStream = new ANTLRInputStream("text");
    let lexer = new MyGrammarLexer(inputStream);
    let tokenStream = new CommonTokenStream(lexer);
    let parser = new MyGrammarParser(tokenStream);
    // Parse the input, where `compilationUnit` is whatever entry point you defined
    let result = parser.compilationUnit();