Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

antlr4ng

Package Overview
Dependencies
Maintainers
0
Versions
38
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

antlr4ng - npm Package Compare versions

Comparing version 3.0.4 to 3.0.5

dist/tree/pattern/CannotInvokeStartRuleError.d.ts

10

dist/BufferedTokenStream.d.ts

@@ -103,5 +103,9 @@ import { Token } from "./Token.js";

/**
* Given a starting index, return the index of the previous token on channel.
* Return i if tokens[i] is on channel. Return -1 if there are no tokens
* on channel between i and 0.
* Given a starting index, return the index of the previous token on
* channel. Return `i` if `tokens[i]` is on channel. Return -1
* if there are no tokens on channel between `i` and 0.
*
* If `i` specifies an index at or after the EOF token, the EOF token
* index is returned. This is due to the fact that the EOF token is treated
* as though it were on every channel.
*/

@@ -108,0 +112,0 @@ previousTokenOnChannel(i: number, channel: number): number;

import { type Interval } from "./misc/Interval.js";
import { IntStream } from "./IntStream.js";
export interface CharStream extends IntStream {
name: string;
/**

@@ -5,0 +6,0 @@ * Reset the stream so that it's in the same state it was

@@ -74,2 +74,3 @@ import { CharStream } from "./CharStream.js";

get inputStream(): CharStream | null;
set inputStream(input: CharStream | null);
/**

@@ -76,0 +77,0 @@ * Constructs a new {@link CommonToken} as a copy of another {@link Token}.

@@ -84,3 +84,7 @@ import type { ATNConfigSet } from "../atn/ATNConfigSet.js";

static equals(a: Partial<DFAState>, b: Partial<DFAState>): boolean;
/**
* @returns the set of all alts mentioned by all ATN configurations in this DFA state.
*/
getAltSet(): Set<number> | null;
toString(): string;
}

@@ -231,3 +231,2 @@ import { Token } from "./Token.js";

precpred(_localctx: ParserRuleContext | null, precedence: number): boolean;
inContext(_context: string): boolean;
/**

@@ -234,0 +233,0 @@ * Checks whether or not `symbol` can follow the current state in the

@@ -14,2 +14,3 @@ import { ATNState } from "./atn/ATNState.js";

rootContext: InterpreterRuleContext;
overrideDecisionRoot: InterpreterRuleContext | null;
protected parentContextStack: Array<[ParserRuleContext | null, number]>;

@@ -25,3 +26,4 @@ constructor(grammarFileName: string, vocabulary: Vocabulary, ruleNames: string[], atn: ATN, input: TokenStream);

addDecisionOverride(decision: number, tokenIndex: number, forcedAlt: number): void;
get overrideDecisionRoot(): InterpreterRuleContext | null;
get overrideDecision(): number;
get overrideDecisionInputIndex(): number;
enterRecursionRule(localctx: ParserRuleContext, state: number, ruleIndex: number, precedence: number): void;

@@ -28,0 +30,0 @@ protected visitState(p: ATNState): void;

@@ -55,5 +55,5 @@ import { type CharStream } from "./CharStream.js";

/**
* Gets the {@link CharStream} from which this token was derived.
* Gets or sets the {@link CharStream} from which this token was derived.
*/
get inputStream(): CharStream | null;
inputStream: CharStream | null;
}

@@ -60,0 +60,0 @@ export declare namespace Token {

@@ -1,2 +0,1 @@

import { ParserRuleContext } from "../ParserRuleContext.js";
import { ErrorNode } from "./ErrorNode.js";

@@ -8,8 +7,8 @@ import { ParseTree } from "./ParseTree.js";

visit(tree: ParseTree): T | null;
visitChildren(node: ParserRuleContext): T | null;
visitChildren(node: ParseTree): T | null;
visitTerminal(_node: TerminalNode): T | null;
visitErrorNode(_node: ErrorNode): T | null;
protected defaultResult(): T | null;
protected shouldVisitNextChild(_node: ParserRuleContext, _currentResult: T | null): boolean;
protected shouldVisitNextChild(_node: ParseTree, _currentResult: T | null): boolean;
protected aggregateResult(aggregate: T | null, nextResult: T | null): T | null;
}
import { type ErrorNode } from "./ErrorNode.js";
import { type ParseTree } from "./ParseTree.js";
import { type TerminalNode } from "./TerminalNode.js";
import { type ParseTree } from "./ParseTree.js";
import { type ParserRuleContext } from "../ParserRuleContext.js";
/**

@@ -28,3 +27,3 @@ * This interface defines the basic notion of a parse tree visitor. Generated

*/
visitChildren(node: ParserRuleContext): T | null;
visitChildren(node: ParseTree): T | null;
/**

@@ -31,0 +30,0 @@ * Visit a terminal node, and return a user-defined result of the operation.

@@ -9,1 +9,3 @@ export * from "./Chunk.js";

export * from "./TokenTagToken.js";
export * from "./CannotInvokeStartRuleError.js";
export * from "./StartRuleDoesNotConsumeFullPatternError.js";

@@ -1,2 +0,1 @@

/// <reference types="node" resolution-mode="require"/>
import type { Lexer } from "../../Lexer.js";

@@ -69,30 +68,2 @@ import type { Parser } from "../../Parser.js";

export declare class ParseTreePatternMatcher {
static CannotInvokeStartRule: {
new (e: Error): {
name: string;
message: string;
stack?: string | undefined;
cause?: unknown;
};
captureStackTrace(targetObject: object, constructorOpt?: Function | undefined): void;
prepareStackTrace?: ((err: Error, stackTraces: NodeJS.CallSite[]) => any) | undefined;
stackTraceLimit: number;
};
static StartRuleDoesNotConsumeFullPattern: {
new (message?: string | undefined): {
name: string;
message: string;
stack?: string | undefined;
cause?: unknown;
};
new (message?: string | undefined, options?: ErrorOptions | undefined): {
name: string;
message: string;
stack?: string | undefined;
cause?: unknown;
};
captureStackTrace(targetObject: object, constructorOpt?: Function | undefined): void;
prepareStackTrace?: ((err: Error, stackTraces: NodeJS.CallSite[]) => any) | undefined;
stackTraceLimit: number;
};
protected start: string;

@@ -99,0 +70,0 @@ protected stop: string;

@@ -0,1 +1,2 @@

import { ParserRuleContext } from "../ParserRuleContext.js";
import { ParseTree } from "./ParseTree.js";

@@ -21,2 +22,6 @@ import { Parser } from "../Parser.js";

static getAncestors(t: ParseTree): ParseTree[];
/**
* Return true if t is u's parent or a node on path to root from u.
*/
static isAncestorOf(t: ParseTree | null, u: ParseTree | null): boolean;
static findAllTokenNodes(t: ParseTree, ttype: number): ParseTree[];

@@ -26,3 +31,16 @@ static findAllRuleNodes(t: ParseTree, ruleIndex: number): ParseTree[];

static descendants(t: ParseTree): ParseTree[];
/**
* Find smallest subtree of t enclosing range startTokenIndex..stopTokenIndex
* inclusively using post order traversal. Recursive depth-first-search.
*/
static getRootOfSubtreeEnclosingRegion(t: ParseTree, startTokenIndex: number, stopTokenIndex: number): ParserRuleContext | null;
/**
* Replace any subtree siblings of root that are completely to left
* or right of lookahead range with a CommonToken(Token.INVALID_TYPE,"...")
* node. The source interval for t is not altered to suit smaller range!
*
* WARNING: destructive to t.
*/
static stripChildrenOutOfRange(t: ParserRuleContext | null, root: ParserRuleContext, startIndex: number, stopIndex: number): void;
private static doFindAllNodes;
}
{
"name": "antlr4ng",
"version": "3.0.4",
"version": "3.0.5",
"type": "module",

@@ -29,15 +29,15 @@ "description": "Alternative JavaScript/TypeScript runtime for ANTLR4",

"@types/jest": "29.5.12",
"@types/node": "20.11.28",
"@types/node": "20.14.9",
"@types/unicode-properties": "1.3.2",
"@typescript-eslint/eslint-plugin": "7.2.0",
"@typescript-eslint/parser": "7.2.0",
"esbuild": "0.20.2",
"@typescript-eslint/eslint-plugin": "8.0.0",
"@typescript-eslint/parser": "7.18.0",
"esbuild": "0.23.0",
"eslint": "8.57.0",
"eslint-plugin-import": "2.29.1",
"eslint-plugin-jsdoc": "48.2.1",
"eslint-plugin-jsdoc": "48.10.2",
"eslint-plugin-prefer-arrow": "1.2.3",
"jest": "29.7.0",
"ts-jest": "29.1.2",
"ts-jest": "29.1.4",
"ts-node": "10.9.2",
"typescript": "5.4.2",
"typescript": "5.5.4",
"unicode-properties": "1.4.1"

@@ -44,0 +44,0 @@ },

@@ -15,2 +15,4 @@ [![GitHub Workflow Status (with event)](https://img.shields.io/github/actions/workflow/status/mike-lischke/antlr4ng/nodejs.yml?style=for-the-badge&logo=github)](https://github.com/mike-lischke/antlr4ng/actions/workflows/nodejs.yml)

> The package requires ES2022 (ES6) or newer, for features like static initialization blocks in classes and private properties (`#field`). It is recommended to use the latest TypeScript version.
## Installation

@@ -42,4 +44,2 @@

The package requires ES2022 or newer, for features like static initialization blocks in classes and private fields (`#field`). It is recommended to use the latest TypeScript version.
## Usage

@@ -158,15 +158,15 @@

The following table shows the results of the benchmarks that were executed in the [antlr4wasm project](https://github.com/mike-lischke/antlr4wasm/tree/master/benchmarks/mysql). The column for antlr4ng, however, contains the current results of this runtime.
The following table shows the results of the benchmarks from the [antlr4wasm project](https://github.com/mike-lischke/antlr4wasm/tree/master/benchmarks/mysql). Only the antlr4ng results came from this repository to reflect the current state. They show how the antlr4ng runtime dominates every other JS/TS runtime by a margin of 9% (for simple input) up to 35% (for complex input), measuring against the closest value for that benchmark.
| | C++ |antlr4ng|antlr4|antlr4ts|antlr4wasm|
|---:|---:|---:|---:|---:|---:|
|Query Collection (cold)|1340 ms| <ins>187/2232 (2420) ms</ins>| 7984 ms| 3402 ms| 3331 ms|
| Bitrix Queries (cold)| 195 ms| <ins>68/283 (351) ms</ins>| 1134 ms| 444 ms| 998 ms|
| Large Inserts (cold)|4981 ms|<ins>6295/2277 (8572) ms</ins>|10695 ms|11483 ms|34243 ms|
|Total (cold) |6546 ms|<ins>6551/4792 (11343) ms</ins>|19878 ms|15403 ms|38641 ms|
|Query Collection (cold)| 941 ms| <ins>177/2004 (2180) ms</ins>| 7789 ms| 3353 ms| 3217 ms|
| Bitrix Queries (cold)| 143 ms| <ins>66/223 (289) ms</ins>| 1105 ms| 450 ms| 899 ms|
| Large Inserts (cold)|3590 ms|<ins>6152/931 (7083) ms</ins>|10607 ms|11539 ms|30466 ms|
|Total (cold) |4696 ms|<ins>6394/3158 (9632) ms</ins>|19532 ms|15371 ms|34612 ms|
|||||||
|Query Collection (warm)| 133 ms| 130/102 (232) ms| <ins>223 ms</ins>| 259 ms| 1177 ms|
| Bitrix Queries (warm)| 70 ms| 63/73 (136) ms| <ins>110 ms</ins>| 131 ms| 815 ms|
| Large Inserts (warm)|4971 ms|<ins>6281/2281 (8562) ms</ins>|10593 ms|11287 ms|36317 ms|
|Total (warm) |5198 ms|<ins>6474/2456 (8931) ms</ins>|10944 ms|11697 ms|38329 ms|
|Query Collection (warm)| 95 ms| <ins>128/52 (179) ms</ins>| 215 ms| 266 ms| 1041 ms|
| Bitrix Queries (warm)| 52 ms| <ins>62/35 (97) ms</ins>| 107 ms| 137 ms| 715 ms|
| Large Inserts (warm)|3564 ms|<ins>6199/927 (7126) ms</ins>|10539 ms|11461 ms|32425 ms|
|Total (warm) |3733 ms|<ins>6388/1015 (7403) ms</ins>|10889 ms|11889 ms|34216 ms|

@@ -208,14 +208,14 @@ Underlined entries are the smallest (not counting C++, which beats them all). For antlr4ng, the times are split into lexing and parsing. Note the high lexer execution times, caused by the large number of predicates (126) + lexer actions (40) in the MySQL lexer.

```bash
loadNewUTF8 average time 353µs size 29191b over 3500 loads of 29191 symbols from Parser.java
loadNewUTF8 average time 75µs size 7552b over 3500 loads of 7552 symbols from RuleContext.java
loadNewUTF8 average time 121µs size 31784b over 3500 loads of 13379 symbols from udhr_hin.txt
loadNewUTF8 average time 318µs size 29191b over 3500 loads of 29191 symbols from Parser.java
loadNewUTF8 average time 72µs size 7552b over 3500 loads of 7552 symbols from RuleContext.java
loadNewUTF8 average time 122µs size 31784b over 3500 loads of 13379 symbols from udhr_hin.txt
lexNewJavaUTF8 average time 706µs over 2000 runs of 29191 symbols
lexNewJavaUTF8 average time 1961µs over 2000 runs of 29191 symbols DFA cleared
lexNewJavaUTF8 average time 699µs over 2000 runs of 29191 symbols
lexNewJavaUTF8 average time 1887µs over 2000 runs of 29191 symbols DFA cleared
lexNewGraphemeUTF8 average time 7836µs over 400 runs of 6614 symbols from udhr_kor.txt
lexNewGraphemeUTF8 average time 7946µs over 400 runs of 6614 symbols from udhr_kor.txt DFA cleared
lexNewGraphemeUTF8 average time 12945µs over 400 runs of 13379 symbols from udhr_hin.txt
lexNewGraphemeUTF8 average time 13079µs over 400 runs of 13379 symbols from udhr_hin.txt DFA cleared
lexNewGraphemeUTF8 average time 203µs over 400 runs of 85 symbols from emoji.txt
lexNewGraphemeUTF8 average time 7843µs over 400 runs of 6614 symbols from udhr_kor.txt
lexNewGraphemeUTF8 average time 7970µs over 400 runs of 6614 symbols from udhr_kor.txt DFA cleared
lexNewGraphemeUTF8 average time 12763µs over 400 runs of 13379 symbols from udhr_hin.txt
lexNewGraphemeUTF8 average time 12779µs over 400 runs of 13379 symbols from udhr_hin.txt DFA cleared
lexNewGraphemeUTF8 average time 202µs over 400 runs of 85 symbols from emoji.txt
lexNewGraphemeUTF8 average time 233µs over 400 runs of 85 symbols from emoji.txt DFA cleared

@@ -228,158 +228,2 @@ ```

### 3.0.4
- Fixed visitor example in this readme file and added build instructions.
- Added back all debug output in the simulators and the prediction context. Useful for finding low level problems.
- Fixed bug #47 Antlr4ng fails to parse codeql/examples/alias.qll
- Fixed bug #46 ParserRulecontext.parent() incorrectly typed
### 3.0.2 - 3.0.3
Fixed a number of smaller issues that have been found after the previous release.
### 3.0.1
Had to make `Lexer.modeStack` public again and allow reading and writing the current lexer mode.
### 3.0.0
This release completes the conversion of the Java (and JavaScript) ANTLR4 runtime to TypeScript. It's a significant improvement over the existing TS (and JS) runtimes, as it includes now all relevant parts from the Java runtime and has been optimized for performance. It's now twice as fast for cold runs and 20% faster with a warm parser/lexer. See also the benchmark section below.
This makes it the fastest TypeScript (and JS) runtime currently available. The ANTLR4 JavaScript runtime still is slightly faster in short time tests (e.g. 228ms vs 223ms for the query collection test), where system load and other factors have however much more impact compared to tests that run around 10 seconds.
So, what has changed in this new major release? In detail:
- Everything that makes sense in the TypeScript environment has been converted (for example `ListTokenSource`, `RuntimeMetaData` and parse tree pattern matching, to name a few). That excludes things like the code point char streams, which directly deal with file and (Java) stream input - aspects that don't matter in TypeScript. Consequently the class `CharStreams` has been removed. Use `CharStream.fromString` to feed your lexer.
- Neither `BailErrorStrategy` nor `ParserRuleContext` track the original exception in error cases anymore. Instead it is wrapped in the exception thrown (for bailing out) or passed to the error listeners.
- The runtime has been profiled both with VS Code and Node.js directly, to identify bottlenecks. This showed excessive object creation and release, because of the way DFA generation is implemented. That led to big object initialization and garbage collection penalties. This has been improved and now most time is spent in generated code (which could be improved later). Several measures have been taken to improve speed:
- Method and constructor overloading in hot paths can be a performance killer, because of the frequent parameter checks. To counter that, class factories and individual method names have been introduced (e.g. `getTextFromContext` and `getTextFromRange` instead of a single `getText` method).
- Pure data holder classes have been converted to interfaces, which appear at runtime as plain objects and safe some of the initialization times.
- Some intermediate objects (like temporary `Interval` and `ATNState` instances) have been removed.
- Bitsets now use typed arrays instead of array of numbers.
- The hash implementation (MurmurHash) has been stripped down to the minimum required code to keep this hot path fast as well.
- Hash codes are now cached wherever possible.
- The `instanceof` operator is relatively expensive, so it was replaced with checks using a member discriminator in hot paths, where possible (e.g. transition and ATN state types).
- `Switch` statements in hot paths have been replaced by factory arrays that reduce determination what to create to a simple array value lookup.
- A number of public members have been renamed, to match common TypeScript code style (e.g. `INSTANCE` to `instance` or `_parseListener` to `parseListener`).
- Methods that can return null/undefined now explicitly say so (Java has no explicit type to mark possible null results and the ANTLR4 Java runtime is a bit lax in this regard). This requires now that users of the new runtime have to do more checks for undefined results.
- The lexer can now be configured at runtime to control what is cached in the DFA (in the Java runtime it's always only ASCII chars) and which code points are acceptable (in the Java runtime always the entire Unicode range).
- Separated enumeration values (e.g. ATN state types, transition types) have been moved back as public static constants to their respective classes.
- Accessibility of class members has been adjusted (strict public, protected and private visibility).
- Duplicated public members (as property and as getter/setter method) have been resolved in favor of the property variant.
- Most use of `null` has been converted to `undefined` (except in places where null marks special conditions) for a more natural handling in TypeScript.
- The JS doc in code has been reworked and all unsupported markup been removed.
- A lot of other code cleanup happened.
- Test improvements:
- Runtime tests have been ported to TypeScript, so they can be debugged and provide a much quicker turnaround.
- Benchmarks now take separated measurements for lexer and parser runs, which much better shows how high the impact of predicates and actions in the lexer is (e.g. 2/3 of the time in the large inserts benchmark is used for lexing input).
- The release build is no longer minified (and hence larger than before) to avoid trouble with other build tools like terser or webpack.
### 2.0.11
- Fixed bug #30 ReferenceError: Super constructor may only be called once
- The entire runtime test library from the Java runtime has now been ported to TypeScript and is used from now on to check the correctness of this runtime.
- The bit set class used bigint to store the values, which is a problem with bundlers like webpack that have no support for bigint. For this reason that type has been replaced (PR #40 feat: replace bigint and BigUint64Array).
- The bundle is no longer minified and hence larger than before. Bundling a minified bundle with other bundlers (like terser) in dependent projects might cause trouble. Additionally, minifying a bundle has no benefit in execution time, it's just a size difference (related bugs: #31, #34, #38).
### 2.0.10
Fixed bug #26 getRuleContext is incompatible with generated code (2.0.5)
### 2.0.9
- Added exports for the profiling classes.
- Reverted some changes that failed the Java runtime tests.
### 2.0.8
- Fixed string construction with class names (which doesn't work when bundling the sources).
### 2.0.7
- Added an InterpreterDataReader implementation (copied from the vscode-antlr4 extension).
- Benchmark values listed here are now computed from 5 runs, instead just one.
- Added `RuleContext.toStringTree()` overload.
### 2.0.6
- Optimizations in HashMap and HashSet (from Peter van Gulik). This can have dramatic speed improvements, depending on the grammar. In the unit tests this shows mostly by a faster cold start.
- Added CommonJS builds back. Especially when running unit tests using Node.js a CommonJS variant is simpler to handle.
- Added clearDFA() methods in the simulators.
### 2.0.5
- Profiler port (from backspace <backspace@backblog.me>)
- Changed context getters in `ParserRuleContext` for retrieving sub contexts to accept any constructor parameter, for more flexibility.
### 2.0.4
- Code generation improvements, especially for local rule attributes. Attributes in a rule (which are implemented as local variables in the generated code) can be unassigned and need extra null-safety checks (the ? operator) or non-null assertions. The code generator now adds these checks automatically.
- `ParserRuleContext.getChild` now accepts any constructor type.
### 2.0.3
- Removed last reference to a Node.js specific type (Buffer), which avoids the automatic reference to the Node.js typings and an "resolution-mode" assertion for "require" (CommonJS).
- Upgraded the ANTLR4 jar, which now produces optional attributes in rule contexts.
### 2.0.1 - 2.0.2
- There are changes in the package content (typings are now in the dist folder too, instead of source).
- There are now index.ts files in every folder and used for the final export index.ts. This makes it easier to see if something is missing and to include new or renamed files.
- And there are some build changes/fixes as preparation for profiling the runtime.
### 2.0.0
The entire runtime now exclusively uses TypeScript. It was tested with the standard ANTLR4 runtime tests and completed the test suite successfully.
### 1.1.3 - 1.1.7
These releases contain mostly internal changes and bug fixes. The antlr4ng-cli tool dependency has been updated to the latest version and build + test processes has been improved (esbuild instead of webpack, Jest instead of Jasmine).
There are also some smaller fixes in `Interval` and `ParseTreeVisitor`. The latter now has the same implementation as the Java runtime.
- Fixed Bug #8 Wrong property name, using `numberOfSyntaxErrors` now.
### 1.1.1 - 1.1.2
Bug fix releases. They contain many bugs found while integrating the runtime into a large project.
### 1.1.0
This release includes a lot of cleanup.
- Generated parser rules that can appear as either returning a single parse context or a list of that no longer use the `__list()` appendix in their name. Instead method overloading is used now to distinguish between the two cases.
- The members `getTypedRuleContext` and `getTypedRuleContexts` have been renamed to `getRuleContext` and `getRuleContexts` respectively, just as in the Java runtime.
- There are more renames (`_errHandler` -> 'errorHandler`, `_input` -> `inputStream` and more).
- The package has been stripped down to just a single bundle file. This is an ESM module now, so it can be used in both, node and browser environments. No differentiation is made anymore between the two.
- The internal folder structure has been changed to match the Java runtime.
- Extended some classes, added new type definitions and exported some more classes.
- Improved `BitSet` to use less memory.
### 1.0.6 - 1.0.7
- Fixed recognizer token type and rule index maps.
- Fixed `getTokens()` in `BufferedTokenStream`.
- Added new peer dependency `antlr4ng-cli`, which is the tool to generate parser files compatible with this runtime.
### 1.0.5
- Added benchmarks.
- Introduced the `IntStream` interface as the base for `CharStream` and `TokenStream`. This avoids duplicate code in the stream type definitions.
- Removed `FileStream` as a preparation to get rid of the separate package files for node and browser. If something needs to be loaded from a file, the particular environment should provide the code for that.
### 1.0.2 - 1.0.4
- Github build action
- Updated package.json
- Exported `ErrorNode`, `InputMismatchException`
- Some smaller fixes
### 1.0.1
- Added and/or replaced all copyrights to a common ANTLR version.
- Removed all individual default exports. Only the final lib exports contain both, default and non-default exports. This avoids namespace access like `antlr4.atn`. Everything is available under a top level import.
- Renamed ErrorListener to BaseErrorListener, as that is what it is actually when comparing it to the Java runtime.
### 1.0.0
- Initial release.
See [release-notes](release-notes.md).

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc