antlr4ng is an alternative, TypeScript-first runtime for ANTLR4 grammars, specifically designed to be used with the `antlr-ng` parser generation tool. Currently stable at version `3.0.16`, it receives frequent point releases addressing bugs and introducing minor enhancements. Unlike the original ANTLR4 JavaScript runtime, `antlr4ng` operates identically across Node.js and browser environments and is built with strict TypeScript nullability checks. It requires an ES2022 (ES6) compatible runtime for features like static initialization blocks and private class fields. While implementing nearly all features of the Java ANTLR4 runtime, it notably omits the `UnbufferedCharStream` class. Developers migrating from other ANTLR4 JavaScript runtimes will need to adjust code for stricter null handling and renamed internal members.
npm install antlr4ngVerified import paths — ran on the pinned version, not inferred.
Demonstrates parsing a simple arithmetic expression using generated lexer and parser, highlighting basic setup with `CharStream` and `CommonTokenStream` from `antlr4ng`.
Ensure your Node.js version is 16.x or higher, or configure your bundler/TypeScript compiler to target `ES2022` or higher.
Implement explicit null checks (`if (member !== null)`) or use TypeScript's non-null assertion operator (`member!`) where appropriate, prioritizing safety.
Update references to these renamed members throughout your custom parser logic, error handlers, or visitor/listener implementations.
Always use the `antlr-ng` tool to generate your lexer and parser files for optimal compatibility with the `antlr4ng` runtime.
Change `import { MyLexer } from './MyLexer';` to `import { MyLexer } from './MyLexer.js';` for generated files.Replace `parser._ctx` with `parser.context`. Similarly, change `_errHandler` to `errorHandler`, `_input` to `inputStream`, and `_interp` to `interpreter`.
Ensure your project is configured for ES Modules and use `import { CharStream } from 'antlr4ng';` instead of `const { CharStream } = require('antlr4ng');`.Verify the relative path to your `generated` folder. For ESM in Node.js, ensure the import statement includes the `.js` extension: `import { ExpressionLexer } from './generated/ExpressionLexer.js';`Upgrade your Node.js runtime to version 16.x or newer, or ensure your build tools (e.g., Babel, TypeScript compiler) are configured to transpile to a target that supports ES2022 or higher.
No dependency data recorded yet.