3 ms·
Quite a few languages can access their own ASTs, but I don't know of one other than C# (and VB.NET--Roslyn is the compiler for both) where the API is so deeply
by mgdlbp 5y ago
Quite a few languages can access their own ASTs, but I don't know of one other than C# (and VB.NET--Roslyn is the compiler for both) where the API is so deeply integrated and hence useful.
The Roslyn SDK exposes its syntax tree, symbol table, and semantic model, with the primary use being for custom code analysis. I surprisingly easily made a linter ('analyzer') for a personal style preference, along with 'code fix' (lightbulb suggestion that appears in Visual Studio) through the quick-start tutorial. The resulting .NET assembly integrated impressively with msbuild and Visual Studio, my custom analyzer being indistinguishable in UX from the built-in ones. Seeing the actual syntax tree, especially where the compiler had recovered from syntax errors, also seemed a great learning experience for getting a feel of how the compiler treated errors.
It seems to now be fairly common for .NET projects to develop their own analyzers to enforce specialized best-practices; I wonder if other languages have similar customs?
https://docs.microsoft.com/en-us/dotnet/csharp/roslyn-sdk/ https://docs.microsoft.com/en-us/dotnet/csharp/roslyn-sdk/
- tusharsadhwani 5y agoThat's amazing. I'm interested in C# now
- eyelidlessness 5y ago> Quite a few languages can access their own ASTs, but I don't know of one other than C# (and VB.NET--Roslyn is the compiler for both) where the API is so deeply integrated and hence useful. Besides lisps?