The antlr-format
package provides a small library to format your ANTLR4 grammar in a wide variety of ways. It has a companion named antlr-format-cli
which provides a terminal command for running the formatter in batch files and so on. You can read more about it in its own Readme.
Nothing special here, just use NPM (or any other package manager):
npm i antlr-format
Read the formatter documentation for further details and a code example.
Updated dependencies
Fixed bug #2 antlr-format produces output that isn't a fixed point, removes comments
Made useTab
false by default. No idea why I made this true by default. I hate tabs in source files.
Fixed a problem related to getting raw content for output in the formatter (e.g. action text). Also changed a number of imports/settings to fix a problem with debugging the formatter in VS Code.
Added missing type definition entry in package.json.
BREAKING CHANGE:
The package has been split into a cli wrapper and the actual formatter class. This avoids inclusion of otherwise unnecessary packages, when importing this package and works around a problem with esbuild when mixing ESM and CommonJS modules running in Node.js (for example using Jest with ts-jest).
Additionally, the GrammarFormatter
class now accepts a string with the grammar content and does the tokenization on its own. This avoids that you have to run the ANTLRv4 lexer manually (or even care for it at all).
This is the initial release of the package.