AntlrVSIX is a tool to support editing, analysis, refactoring, and conversion of Antlr2, Antlr3, Antlr4, Bison and W3C EBNF grammars. It contains extensions for Visual Studio 2019, Visual Studio Code, Gnu Emacs, a Language Server Protocol (LSP) server, and a stand-alone command-line tool known as Trash for editing grammar files directly without Visual Studio, runnable on Windows or Linux. All clients use the LSP server implemented in this repository. The clients each are implemented elsewhere, but a thin shim is provided in this repository to get the client to work with the server. For Visual Studio 2019, the client is implemented using Microsoft's client. The server is implemented using Antlr, Antlr4BuildTasks, XPath2, S-expressions for Antlr parse trees, and a number of other tools. Most of the code is implemented in C#. The extension for VS Code is written in Typescript. Supported are colorized tagging, hover, go to def, find all refs, replace, and reformat. Beyond the basic LSP commands, the tool supports analysis, refactoring, and conversion.
Supported grammars and features
Antlrvsix supports Visual Studio 2019. I recommend that you use version 16.7 since it has the latest bug fixes. If you find this extension not to your liking, use VSCode and Mike Lischke's vscode-antlr4. Antlrvsix contains a command-line tool if you want to automate transformations on a Antlr grammar, or want to quickly run a parser over a grammar file and use XPath to query items in the parse tree.
If you are just building and running an Antlr application and don't care about editing features, then you just need Net Core 3.1. Builds are supported using Antlr4BuildTasks.
You can install the extension in one of four ways:
Guide to basic features
For information on how basic use, see the User Guide.
Running the Trash command-line engine
The Trash tool is a command-line interpreter for executing operations on grammar files. With it, you can read Antlr2, Antlr3, Antrl4, and Bison grammars, convert to Antlr4, find sub-trees in the parse tree for the grammar using XPath expressions, analyze, and refactor the grammar.
To run the tool, you will need to find the Trash.exe executable after installing the extension in Visual Studio 2019, or unpacking it directly from the downloaded .vsix--a ZIP file. It should be under "C:/Users/userid/AppData/Local/Microsoft/VisualStudio/.../AntlrVSIX/8.0/Trash/netcoreapp3.1/Trash.exe". Once you find the executable, execute it.
For a list of commands in Trash, see this documentation.
Antlrvsix provides a number of transformations that can help to make grammars cleaner (reformatting), more readable (reducing the length of the RHS of a rule), and more efficient (reducing the number of non-terminals) for Antlr.
Some of these refactorings are very specific for Antlr due to the way the parser works, e.g., converting a prioritized chain of productions recognizing an arithmetic expression to a recursive alternate form. The refactorings implemented are:
Raw tree editing
Splitting and combining
The source code for the extension is open source, free of charge, and free of ads. For the latest developments on the extension, check out my blog.
The extension is at ./Client/bin/Debug/AntlrVSIX.vsix after building successfully.
Current Release v8.0 (18 Aug 2020)
This release is a major organizational and feature change. For the extension itself, there are several new transforms and some bug fixes. But, the main goal has been to reposition the tool to be used for refactorings of the Java grammar from specification in an automated way. To that end, I also wrote ScrapeJavaSpec, a tool that scrapes the Java grammar directly from the online specification, and outputs an Antlr4 grammar. This works wonderfully not only for the existing grammars Java8, Java9, but also for versions 10, 11, 12, 13, and 14, in minutes! Added with this release of Antlrvsix are several new refactorings, like "unify", which I have tested on the Java grammar. The next step with the next release will be to add the rest of the refactorings and optimize the Java grammar for speed so that it is as fast as Parr's Java grammar. Also added to this release were conversions for Antlr2 and Antlr3 grammars. But, in order to write the conversion methods, I had to write Antlr4 grammars for these older syntaxes. Since it was not much trouble, I decided it was not too much effort to also provide LSP services for Antlr2, Antlr3, and Bison grammars! The other major software that is new with this release is an XPath2 engine. This was a port of the Java code for the Eclipse XPath engine to C#, and an added layer to wrap Antlr parse trees.
See this guide.
Planned for v8.1 (end Sept 2020):
Planned for v9 (mid Oct 2020)
Planned for v10 (mid Nov 2020)
Any questions, email me at ken.domino gmail.com