JSPM

  • Created
  • Published
  • Downloads 492496
  • Score
    100M100P100Q168967F
  • License BSD-3-Clause

ANTLR 4 runtime for JavaScript written in Typescript

Package Exports

  • antlr4ts
  • antlr4ts/ANTLRInputStream
  • antlr4ts/BailErrorStrategy
  • antlr4ts/CommonToken
  • antlr4ts/CommonTokenStream
  • antlr4ts/Decorators
  • antlr4ts/FailedPredicateException
  • antlr4ts/Lexer
  • antlr4ts/NoViableAltException
  • antlr4ts/Parser
  • antlr4ts/ParserRuleContext
  • antlr4ts/RecognitionException
  • antlr4ts/RuleContext
  • antlr4ts/RuleVersion
  • antlr4ts/Token
  • antlr4ts/VocabularyImpl
  • antlr4ts/atn
  • antlr4ts/atn/ATN
  • antlr4ts/atn/ATNDeserializer
  • antlr4ts/atn/LexerATNSimulator
  • antlr4ts/atn/ParserATNSimulator
  • antlr4ts/atn/PredictionMode
  • antlr4ts/misc
  • antlr4ts/misc/Interval
  • antlr4ts/misc/ParseCancellationException
  • antlr4ts/misc/Utils
  • antlr4ts/tree
  • antlr4ts/tree/AbstractParseTreeVisitor
  • antlr4ts/tree/ErrorNode
  • antlr4ts/tree/ParseTreeWalker
  • antlr4ts/tree/TerminalNode

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (antlr4ts) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

antlr4ts - TypeScript/JavaScript target for ANTLR 4

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

Build status

License

Overview

  • 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)

Requirements

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. Install antlr4ts as a runtime dependency using your preferred package manager.
npm install antlr4ts --save
yarn add antlr4ts
  1. Install antlr4ts-cli as a development dependency using your preferred package manager.
npm install antlr4ts-cli --save-dev
yarn add -D antlr4ts-cli
  1. Add a grammar to your project, e.g. path/to/MyGrammar.g4

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

    "scripts": {
      // ...
      "antlr4ts": "antlr4ts -visitor path/to/MyGrammar.g4"
    }
  3. 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();