![Oracle Drags Its Feet in the JavaScript Trademark Dispute](https://cdn.sanity.io/images/cgdhsj6q/production/919c3b22c24f93884c548d60cbb338e819ff2435-1024x1024.webp?w=400&fit=max&auto=format)
Security News
Oracle Drags Its Feet in the JavaScript Trademark Dispute
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Part of the Next Generation ANTLR Project
Another Tool for Language Recognition
A tool/package that takes a defined language (provided in a grammar file) and generates parser and lexer classes in one of the supported target languages. These classes can be used in your project to parse input specified by the grammar file. Supported target languages are:
This project started as a TypeScript port of the old ANTLR4 tool (originally written in Java) and includes the entire feature set of the the Java version and is constantly enhanced.
Even though the tool is already pretty solid and generates exactly the same output like the old ANTLR4 jar, it is still not considered production ready. All (relevant) original unit tests have been ported and run successfully. Additionally, the tool was tested with all grammars in the grammars-v4 repository.
See the milestone 3 for the current status and the plan.
The tool currently runs only in a Node.js environment, but it is planned to make it run in browsers later.
There are different ways how to use the antlr-ng tool. All scenarios need Node.js being installed on your box. If you haven't done that yet get it from https://www.nodejs.org. Any version 20.x or later can be used and any platform which runs Node.js also can run antlr-ng.
Use cases:
Install the antlr-ng tool as a global command on your box by running:
npm i -g antlr-ng
This puts it in the global NPM cache and creates a link to it in a folder which is in your system PATH. Hence you can directly execute it:
antlr-ng -h
Usage: program [options] <grammar...>
Arguments:
grammar A list of grammar files.
Options:
-o, --output-directory <path> specify output directory where all output is generated
-lib, --lib-directory <path> specify location of grammars, tokens files
--atn [boolean] Generate rule augmented transition network diagrams. (default: false)
-e, --encoding <string> Specify grammar file encoding; e.g., ucs-2. (default: "utf-8")
-mf, --message-format [string] Specify output style for messages in antlr, gnu, vs2005. (choices: "antlr", "gnu", "vs2005", default: "antlr")
-lm, --long-messages [boolean] Show exception details when available for errors and warnings. (default: false)
-l, --generate-listener [boolean] Generate parse tree listener. (default: true)
-v, --generate-visitor [boolean] Generate parse tree visitor. (default: false)
-p, --package <name> Specify a package/namespace for the generated code.
-d, --generate-dependencies [boolean] Generate file dependencies. (default: false)
-D, --define <key=value...> Set/override a grammar-level option.
-w, --warnings-are-errors [boolean] Treat warnings as errors. (default: false)
-f, --force-atn [boolean] Use the ATN simulator for all predictions. (default: false)
--log [boolean] Dump lots of logging info to antlrng-timestamp.log. (default: false)
--exact-output-dir [boolean] All output goes into -o dir regardless of paths/package (default: false)
-V, --version output the version number
-h, --help display help for command
The parameter list should look very familiar, except that it defines a short hand version and a long version of each parameter. This is why you have to update your parameter list when replacing ANTLR4 by antlr-ng. A typical invocation looks like this:
antlr-ng -Dlanguage=TypeScript --exact-output-dir -o ./tests/generated ./tests/grammars/Java.g4
In this scenario you install the tool as another dev dependecy. In your project folder run:
npm i --save-dev antlr-ng
You can then create an NPM script in your package.json to handle your grammar(s):
"scripts": {
"generate-parser": "antlr-ng -Dlanguage=TypeScript --exact-output-dir -o ./src/generated ./src/grammars/MyGrammar.g4",
...
},
Using the generated parser in your project is subject to the target language of it. For TypeScript and JavaScript you need antlr4ng as target runtime. Read its readme file for an example how to use the generated parser.
Just note: antlr4ng-cli has not been updated to use antlr-ng yet. This will be done as soon as we have a production ready release of the tool. In fact antlr4ng-cli will be replaced by antlr-ng in the future.
This scenario allows you to run the generation process in memory. All unit tests in the package use this approach. Details of that will be laid out in a separate document later.
The sections below are meant for developers working on antlr-ng or are interested in the internals of this project.
A loose collection of thoughts.
This is a tricky field and not easy to re-design. The original decision to allow target (language) specific code in a grammar made (and makes) sharing/reusing grammars very difficult. Below are some ideas:
Maybe we can take all this a step further by defining "language packs", a single file or a collection of files for a specific target language, which is automatically picked up by the ANTLRng tool to generate target specific code.
What can we learn from other parser generators? For example tree-sitter has a concept of editing a parse tree, which internally will re-parse only the changed part (which is as close to incremental parsing as you can get). It also uses WebAssembly packages as loadable modules that fully handle a language. There's nothing like the ANTLR runtime in this concept. Debugging the parser could be tricky with that approach, however.
FAQs
Next generation ANTLR Tool
The npm package antlr-ng receives a total of 363 weekly downloads. As such, antlr-ng popularity was classified as not popular.
We found that antlr-ng demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.