chevrotain-allstar review
chevrotain-allstar 0.5.0 swaps Chevrotain 13's bounded token prediction for an ALL(*) strategy based on the algorithm used by ANTLR4. A parser still uses Chevrotain tokens, rules, CSTs or embedded actions; the only integration point is LLStarLookaheadStrategy in the parser constructor. The strategy builds an augmented transition network and adaptive DFA during self-analysis, then reads as far ahead as a difficult decision requires. Our browser bundle measured 136.9 KB minified and 39.7 KB gzipped, a visible client cost for one parser feature.
chevrotain-allstar 0.5.0 installed in 3.7 seconds with 0 audit findings, but its browser bundle reached 39.7 KB gzipped in our sandbox. Install it for a tested Chevrotain 13 grammar that truly needs adaptive lookahead; keep the standard strategy when left factoring or a small maxLookahead solves the same decision.
We installed it
| Install | ✓ · 3.7s | 8 packages on disk · 6 MB |
| Import | ✓ | ESM import works · require() works · ESM package with exports map |
| Browser | 39.7 KB | gzipped (136.9 KB minified), bundled with esbuild |
| Types | ✓ | TypeScript types bundled |
| Known vulns | 0 | 0 critical · 0 high · 0 moderate · 0 low (npm audit) |
Answers from our run
Does chevrotain-allstar install cleanly?
Yes. In a fresh container with an empty cache, npm install chevrotain-allstar finished in 4 seconds, leaving 8 packages and 6 MB on disk. npm audit reported no known vulnerabilities.
How much does chevrotain-allstar add to a browser bundle?
39.7 KB gzipped (136.9 KB minified) when the whole package is bundled for the browser with esbuild. Importing only part of it is usually smaller.
Does chevrotain-allstar work with both ESM and CommonJS?
Yes. Both import 'chevrotain-allstar' and require('chevrotain-allstar') worked in Node 22 in our run. The package is published as ESM with an exports map.
Does chevrotain-allstar include TypeScript types?
Yes, type declarations ship inside the package, so no @types install is needed.
chevrotain-allstar or chevrotain: which should you use?
chevrotain: Choose the built-in lookahead when a bounded, validated grammar handles the input. chevrotain-allstar 0.5.0 installed in 3.7 seconds with 0 audit findings, but its browser bundle reached 39.7 KB gzipped in our sandbox.
When should you not use chevrotain-allstar?
The grammar becomes LL(1) or LL(k) after ordinary left factoring. Built-in Chevrotain prediction avoids the plugin's ATN and DFA machinery.
Use it if
- A Chevrotain 13 grammar has recursive or long common prefixes that exceed a sensible fixed maxLookahead.
- You want adaptive prediction without replacing Chevrotain's lexer, rule DSL, recovery, or visitor code.
- An editor parser needs the optional incomplete-input mode to choose a plausible branch when tokens end mid-rule.
- Your team can test ambiguous paths against a real corpus and watch the strategy's runtime diagnostics.
- The grammar becomes LL(1) or LL(k) after ordinary left factoring. Built-in Chevrotain prediction avoids the plugin's ATN and DFA machinery.
- The project cannot move to Chevrotain ^13.0.0, which version 0.5.0 declares as its peer dependency.
- You need ambiguity rejected during self-analysis. The implementation suppresses Chevrotain's ambiguous-alternative checks and reports unresolved choices while parsing.
- A 39.7 KB gzipped browser cost is too much for client-side parsing. That is what our full-package esbuild measurement produced.
- You need a standalone parser generator or grammar-file compiler. This package supplies one lookahead strategy and assumes you already know Chevrotain's parser API.
Setup reality
We installed chevrotain-allstar 0.5.0 in a fresh Node 22 Bookworm sandbox in 3.7 seconds. The install left 8 packages and 6 MB on disk, and npm audit found 0 known vulnerabilities. The package itself has 1 direct dependency, 1 peer dependency, 232 KB unpacked, an MIT license, and bundled TypeScript declarations. Both require() and ESM import worked in our Node 22.23.2 checks despite the package declaring type: module.
Install Chevrotain ^13.0.0 alongside it because the parser library is a peer. There are no credentials, generated files, native builds, or config files. Construct LLStarLookaheadStrategy before performSelfAnalysis(), and use a separate strategy instance for each grammar so its rule-derived automata are not shared across unrelated parsers.
Simple LL(1) decisions retain a fast path. Conflicting alternatives use adaptive prediction and may inspect an unbounded prefix, so test pathological inputs as well as normal files. The 136.9 KB minified, 39.7 KB gzipped browser result matters if parsing runs in an editor tab.
Runtime ambiguity is observable behavior. The strategy logs the tie and chooses the lowest viable alternative number; route its logging callback into tests or diagnostics. incomplete: true changes end-of-input decisions for unfinished editor text, while lexer errors, recovery settings, CST visitors, and semantic gate behavior remain your responsibility.
Patterns
Select adaptive lookahead enable-allstar
import { EmbeddedActionsParser } from 'chevrotain';
import { LLStarLookaheadStrategy } from 'chevrotain-allstar';
class Parser extends EmbeddedActionsParser {
constructor(tokens) {
super(tokens, { lookaheadStrategy: new LLStarLookaheadStrategy() });
// Define RULE calls here.
this.performSelfAnalysis();
}
}Chevrotain 13 must be installed as a peer, and all rules must exist before performSelfAnalysis() builds the lookahead state.
Tokenize and invoke an entry rule parse-token-stream
const lexing = lexer.tokenize(source);
if (lexing.errors.length) throw lexing.errors[0];
const parser = new Parser(allTokens);
parser.input = lexing.tokens;
const result = parser.document();
if (parser.errors.length) throw parser.errors[0];Version 0.5.0 changes prediction only; lexer errors and parser.errors still need separate checks.
Collect runtime ambiguity messages capture-ambiguities
const ambiguities = [];
const strategy = new LLStarLookaheadStrategy({
logging: (message) => ambiguities.push(message),
});
super(tokens, { lookaheadStrategy: strategy });An unresolved choice is logged at runtime and the lowest numbered viable alternative wins, so fail a corpus test when this array is nonempty.
Parse unfinished editor text accept-incomplete-input
super(tokens, {
lookaheadStrategy: new LLStarLookaheadStrategy({
incomplete: true,
logging: reportAmbiguity,
}),
recoveryEnabled: true,
});incomplete: true permits a best-effort branch at end of input; avoid it for strict file validation where truncation must fail.
Keep alternatives with a long prefix parse-common-prefix
this.RULE('statement', () => {
this.OR([
{ ALT: () => this.SUBRULE(this.assignment) },
{ ALT: () => this.SUBRULE(this.call) },
]);
});ALL(*) may read past shared tokens, but Chevrotain occurrence suffixes remain required for repeated DSL methods inside one top-level rule.
Apply a semantic predicate gate-an-alternative
this.OR([
{
GATE: () => this.languageVersion >= 2,
ALT: () => this.SUBRULE(this.modernSyntax),
},
{ ALT: () => this.SUBRULE(this.legacySyntax) },
]);Version 0.5.0 evaluates GATE functions during prediction, so keep predicates deterministic and cheap.
Retain Chevrotain recovery enable-recovery
super(tokens, {
recoveryEnabled: true,
lookaheadStrategy: new LLStarLookaheadStrategy(),
});The strategy selects alternatives; Chevrotain still owns token insertion, deletion, resynchronization, and the parser error list.
Use adaptive prediction with a CST build-cst
class QueryParser extends CstParser {
constructor(tokens) {
super(tokens, { lookaheadStrategy: new LLStarLookaheadStrategy() });
this.RULE('query', () => this.CONSUME(Identifier));
this.performSelfAnalysis();
}
}CST output and visitors follow normal Chevrotain 13 APIs; the plugin does not add a tree format.
Combine dynamic tokens and ALL(*) use-dynamic-tokens
super(tokens, {
dynamicTokensEnabled: true,
lookaheadStrategy: new LLStarLookaheadStrategy(),
});Dynamic tokens bypass the static LL(1) shortcut in the implementation, so measure this configuration with representative files.
Create a strategy per grammar isolate-grammar-state
function parserOptions() {
return { lookaheadStrategy: new LLStarLookaheadStrategy() };
}Initialization stores grammar-specific ATN and DFA data on the strategy instance; do not reuse one instance across different parser classes.
Fail tests on runtime ties test-ambiguity-free
const messages = [];
const parser = createParser({ logging: (message) => messages.push(message) });
for (const fixture of fixtures) parseFixture(parser, fixture);
expect(messages).toEqual([]);Static ambiguity validation is suppressed, making a realistic 1,000-file corpus more useful than a constructor-only smoke test.
Put the preferred interpretation first order-fallbacks
this.OR([
{ ALT: () => this.SUBRULE(this.preferredMeaning) },
{ ALT: () => this.SUBRULE(this.compatibilityMeaning) },
]);When version 0.5.0 cannot separate viable branches, alternative order decides the result after the ambiguity is logged.
Alternatives
| Package | Registry | Pick it when |
|---|---|---|
| chevrotain | npm | Choose the built-in lookahead when a bounded, validated grammar handles the input. |
| nearley | npm | Choose a grammar-file workflow when ambiguous grammars and multiple parse results are acceptable. |
| moo | npm | Choose it only for tokenization; pair it with a parser when Chevrotain's combined toolkit is unnecessary. |
More cli & tooling guides
chalk · commander · typescript · esbuild · yargs · click · the whole shelf →
How this guide is made: grounded in the library's documentation, release notes, changelog, and issue history, on a fixed rubric — not a hands-on install of every release. The 50 most-downloaded entries are additionally install-verified in clean containers. Corrections: contact the desk.

