Registry / serialization / chevrotain-allstar

chevrotain-allstar

JSON →
library0.4.1jsnpmunverified

Chevrotain Allstar is a specialized plugin for the Chevrotain parser library, designed to enhance its lookahead capabilities. It implements the ALL(*) lookahead algorithm, a technique initially introduced for ANTLR4. Unlike Chevrotain's default LL(*k*) behavior, which has a bounded lookahead, ALL(*) offers unbounded lookahead, allowing the parser to resolve ambiguities in more complex grammars by examining an arbitrary number of upcoming tokens. The current stable version is 0.4.1. This library is specifically tailored for users who require more powerful lookahead than Chevrotain's built-in strategies provide, typically when dealing with highly ambiguous or context-sensitive grammar rules. Its release cadence is generally tied to the development of the Langium project and Chevrotain itself, making updates less frequent than a core library.

npm install chevrotain-allstar
INSTALL
IMPORT
SIG · CHEVROTAIN-ALLSTAR
C
chevrotain-allstar
serializationjavascriptv0.4.1
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

LLStarLookaheadStrategy
import { LLStarLookaheadStrategy } from 'chevrotain-allstar'
const LLStarLookaheadStrategy = require('chevrotain-allstar').LLStarLookaheadStrategy
The library primarily uses ES module syntax. While CommonJS might work with transpilation, direct require is less common and might lead to issues in pure ESM environments. It's designed for use with TypeScript.
LLStarLookaheadStrategy (type)
import type { ILookaheadStrategy } from 'chevrotain'
While LLStarLookaheadStrategy is a class, its instance conforms to Chevrotain's ILookaheadStrategy interface. Directly importing types from chevrotain-allstar might not be necessary if only the class is instantiated.
EmbeddedActionsParser
import { EmbeddedActionsParser } from 'chevrotain'
Used in conjunction with `chevrotain-allstar` as demonstrated in the quickstart, this is a core Chevrotain class, not part of `chevrotain-allstar`.

This quickstart demonstrates how to integrate `LLStarLookaheadStrategy` into a Chevrotain parser, showing a simple grammar with a choice that can utilize the unbounded lookahead. It defines tokens, a parser class, and then parses a sample input.

import { Lexer, createToken, EmbeddedActionsParser } from 'chevrotain'; import { LLStarLookaheadStrategy } from 'chevrotain-allstar'; const A = createToken({ name: "A", pattern: /A/ }); const B = createToken({ name: "B", pattern: /B/ }); const C = createToken({ name: "C", pattern: /C/ }); const WhiteSpace = createToken({ name: "WhiteSpace", pattern: /\s+/, group: Lexer.SKIPPED }); const allTokens = [WhiteSpace, A, B, C]; class MyParser extends EmbeddedActionsParser { constructor() { super(allTokens, { lookaheadStrategy: new LLStarLookaheadStrategy() }); this.performSelfAnalysis(); } // Example production demonstrating a choice that might benefit from unbounded lookahead public statement = this.RULE('statement', () => { this.OR([ { ALT: () => { this.CONSUME(A); this.CONSUME(B); } }, { ALT: () => { this.CONSUME(A); this.CONSUME(C); } } ]); }); } const lexer = new Lexer(allTokens); const parser = new MyParser(); // Example usage with a simple input const inputText = "AC"; const lexingResult = lexer.tokenize(inputText); parser.input = lexingResult.tokens; const cst = parser.statement(); if (parser.errors.length > 0) { console.error("Parsing errors:\n" + parser.errors.map(err => err.message).join('\n')); } else { console.log("Parsing successful. CST:\n", JSON.stringify(cst, null, 2)); }
Debug
Known issues
gotchaThe ALL(*) lookahead strategy can introduce significant performance overhead compared to Chevrotain's default LL(*k*) bounded lookahead. Unbounded lookahead means the parser might examine a large portion of the input stream to resolve ambiguities, potentially slowing down parsing dramatically for complex grammars or large inputs. It should be used only when strictly necessary.
fix
Profile your parser's performance with and without ALL(*) and consider if your grammar can be refactored to reduce ambiguity or if a bounded lookahead is sufficient. Only use ALL(*) for specific rules that genuinely require it.
affects: >=0.1.0
breakingAs a plugin for Chevrotain, `chevrotain-allstar`'s compatibility is tightly coupled to Chevrotain's major versions. A new major version of Chevrotain (e.g., v13) might introduce breaking changes in its parser API that could render older versions of `chevrotain-allstar` incompatible.
fix
Always check the `chevrotain-allstar` release notes and `peerDependencies` when upgrading your core Chevrotain library. Ensure both packages are compatible versions.
affects: All versions
gotchaThe ALL(*) algorithm fundamentally changes how Chevrotain performs lookahead. This might lead to different parsing decisions than expected if you are migrating from an existing Chevrotain parser using LL(*k*) without fully understanding the implications of unbounded lookahead. Subtle ambiguities might be resolved differently.
fix
Thoroughly test your grammar and inputs after integrating ALL(*). Be aware of the theoretical underpinnings of ALL(*) and how it interacts with your grammar's specific ambiguities.
affects: >=0.1.0
Errors
Common errors & fixes
Cannot find module 'chevrotain' or its corresponding type declarations.
The `chevrotain` package is a peer dependency and must be installed explicitly.
fix
Install chevrotain: `npm install chevrotain` or `yarn add chevrotain`.
The 'lookaheadStrategy' property is not assignable to type 'ILookaheadStrategy'.
Type mismatch, often due to incompatible versions of `chevrotain-allstar` and `chevrotain` or incorrect import.
fix
Ensure that `chevrotain-allstar` and `chevrotain` are compatible versions as specified in `chevrotain-allstar`'s peer dependencies. Update both packages if necessary.
Error: This grammar does not belong to the Chevrotain Allstar parser class hierarchy.
This is a hypothetical error indicating an internal issue or misuse where the parser instance is not correctly recognized by the strategy.
fix
Ensure your parser class extends `EmbeddedActionsParser` (or `CstParser`) from `chevrotain` and that `LLStarLookaheadStrategy` is correctly instantiated and passed in the constructor options, as shown in the quickstart.
Upgrade
Version history
0.4.1latest on npm
Audit
Dependencies
chevrotainrequiredCore parser library that this package extends; required as a peer dependency.
Agent activity
10 hits · last 30 days
node
8
OpenAI (training)
1
Resources
chevrotain-allstar — npm install chevrotain-allstar · libregistry