Registry / devops / antlr-format

antlr-format

JSON →
library2.1.5jsnpmunverified

A library for formatting ANTLR4 grammar files, supporting a wide variety of formatting options. Current stable version is 2.1.5, released on a modest cadence with bug fixes and dependency updates. It is the only dedicated formatter for ANTLR4 grammars, offering fine-grained control over whitespace, alignment, and comment placement. The companion CLI package antlr-format-cli provides a command-line interface for batch processing.

npm install antlr-format
INSTALL
IMPORT
SIG · ANTLR-FORMAT
A
antlr-format
devopsjavascriptv2.1.5
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

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

GrammarFormatter
import { GrammarFormatter } from 'antlr-format'
import GrammarFormatter from 'antlr-format'
Default export is not available; use named import.
FormatOption
import { GrammarFormatter } from 'antlr-format'; const formatter = new GrammarFormatter(grammarText, options);
const { GrammarFormatter } = require('antlr-format');
Package is ESM-only since v2. CommonJS require() fails. Use dynamic import() if needed.
FormatterOptions
import type { FormatterOptions } from 'antlr-format'
import { FormatterOptions } from 'antlr-format'
FormatterOptions is only a type, not a runtime value. Use type-only import for TS.

Shows how to import GrammarFormatter, instantiate with grammar string and options, then format and output.

import { GrammarFormatter } from 'antlr-format'; const grammarText = `grammar Expr; prog: expr EOF ; expr: expr ('*'|'/') expr | expr ('+'|'-') expr | INT ; INT : [0-9]+ ; WS : [ \t\r\n]+ -> skip ;`; const formatter = new GrammarFormatter(grammarText, { useTab: false, tabSize: 4, alignTrailingComments: true, maxLineLength: 120 }); const formatted = formatter.format(); console.log(formatted);
Debug
Known issues
breakingPackage now requires ESM imports. CommonJS require() will throw.
fix
Use import syntax or dynamic import().
affects: >=2.0.0
breakingGrammarFormatter constructor now takes a grammar string instead of a token stream. The ANTLR4 lexer is invoked internally.
fix
Pass grammar content as string directly.
affects: >=2.0.0
deprecateduseTab option default changed from true to false in v2.1.0.
fix
If tabs were desired, set useTab: true explicitly.
affects: >=2.1.0
gotchaFormatter may not be idempotent for grammars with block comments or certain edge cases (see bug #2 fixed in 2.1.1).
fix
Upgrade to 2.1.1 or later.
affects: <2.1.1
gotcha3rd party libs are bundled in versions <2.1.3, which may conflict with host projects.
fix
Upgrade to 2.1.3 or later to exclude bundled dependencies.
affects: <2.1.3
Errors
Common errors & fixes
Cannot find module 'antlr-format'
Missing package install or wrong import path.
fix
Run `npm install antlr-format` and ensure import is correct: `import { GrammarFormatter } from 'antlr-format'`
GrammarFormatter is not a constructor
Using default import instead of named import.
fix
Use `import { GrammarFormatter } from 'antlr-format'`
TypeError: antlr_format_1.GrammarFormatter is not a function
Using CommonJS require() on ESM-only package.
fix
Switch to ESM import or use dynamic `import('antlr-format').then(...)`.
Upgrade
Version history
2.1.5latest on npm
Audit
Dependencies
antlr4ngrequiredTokenization and grammar parsing
Agent activity
11 hits · last 30 days
node
10
OpenAI (training)
1
Resources
antlr-format — npm install antlr-format · libregistry