JetBrains recently open sourced Nitra, a set of tooling for working with programming languages on the CLR. Developers can define grammers using Nemerle, which Nitra then uses to build parsers and generate classes to represent and navigate the AST.
An interesting feature in Nitra is the ability to build block grammers and reusing them across languages. Modules such as Whitespaces and CStyleComments ship with Nitra and can easily be reused in defining your own language grammer.
There are three parts to using Nitra -
- Building Nitra files to generate your parsers
- Debugging and testing your parsers using the visualizer
- Enabling IDE support for your language with Visual Studio using an Extension
Once you define the syntax along with AST and parsers, you also get syntax highlighting, code folding and errors higlighting within Visual Studio. Other features such as static analysis, refactoring, navigation and symbol lookup will be available shortly.
The project is quite ambitious - Nemerle developers (who are also the developers behind Nitra) are planning to rewrite Nemerle using Nitra once it is done. However, Nitra is still in preview, and it will take some time before it is fully ready, especially with features such as compilation currently missing.
JetBrains famously decided against using Roslyn for powering their Resharper features, especially because Resharper supports many other languages, whereas Roslyn is limited to C# and VB. Nitra seems to be a step in making this multi-lingual architecture even more extensible. Enabling language services by just defining the grammer in Nitra will allow JetBrains to support new languages faster, which is one of the key drivers for the project.
You can have a look at the Nitra source code or the documentation to know more.