This is a
playground to test code. It runs a full
Node.js environment and already has all of
npm’s 400,000 packages pre-installed, including
antlr4-graps with all
npm packages installed. Try it out:
This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.
ANTLR4 graps (Grammar Parsing Service) is a TypeScript node module using the TypeScript ANTLR runtime (antlr4ts) created by Sam Harwell. At the time being this runtime is still considered alpha, while it works already quite well.
At its core this module manages source contexts for each ANTLR4 grammar source an application provides (usually files, but can also be strings in memory). It manages grammar dependencies and automatically loads them as required (either from the same folder as the requesting grammar or from a common lib folder).
A context is identfied by a unique string, which is usually the absolute file name, but can be any unique string (e.g. a UUID). Using a file name has the advantage that the module can load file content transparently, if no grammar code is given as string (especially important for dependencies).
The module comes with jars for parser generation (the main ANTLR jar and a derived one only for typescript) and can so generate all parser and lexer files for you (targets: Java, C++, C#, JS, Python, Typescript, Swift, Go). It will then parse all error messages and provide diagnostic informations, if problems were reported. Additionally the module does its own syntactic and semantic checks and can so provide a subset of the diagnostics available from ANTLR. These are provided on each reparse call, while ANTLR diagnostics are only available after a generation call (in this case the interal diagnostics are replaced by the external ones).
Here's a feature summary of the module:
You can find details about (interactive) use and all available public functions and structures in the api reference file.
The GIT repository contains a test setup, which you can execute from the module root folder by running
tsc, but better is to launch the tests with additional parameters like this:
mocha --compilers ts:ts-node/register,tsx:ts-node/register
Additionally, there is a 'Mocha' setup for Visual Studio Code, which even allows to debug the tests. Tests are however not shipped in the published node module.
see bug tracker
Also, the code completion feature is not fully ready yet and needs some improvements. Use it only for testing small grammars for now.
I'd love to see code contributions, to make the module evolve quicker.
For release details see Git commit history.