This repository has been archived by the owner. It is now read-only.
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.


HlslParser is a SM5.0 HLSL parser for .NET. The grammar and parser are built using JetBrains' Nitra project. Currently, it only parses HLSL code into an AST. Once Nitra adds support for it (planned for a future milestone), I plan to extend HlslParser to support full HLSL intellisense in Visual Studio.

HlslParser is currently capable of parsing most / all of the sample shaders in the Direct3D SDK, as well as several other shaders - see the test suite.

(On a nerd note, Nitra makes it possible to define the grammar in a nice concise way; so far, I prefer it to other parser generators that I've used. Here is the HLSL grammar file.)


var sourceSnapshot = new SourceSnapshot(sourceCode);
var parserHost = new ParserHost();
var compilationUnit = HlslGrammar.CompilationUnit(sourceSnapshot, parserHost);

Assert.That(compilationUnit.IsSuccess, Is.True);

var parseTree = compilationUnit.CreateParseTree();
var parsedCode = parseTree.ToString();


Because HlslParser is based on Nitra, you'll need to install the following before you can build HlslParser on your own machine:

  1. Nemerle
  2. Nitra

I haven't built an HLSL preprocessor. Instead, I make use of the Direct3D HLSL preprocessor, through SharpDX. SharpDX requires a specific DirectX runtime, so if you want to run the HlslParser test suite, you'll need to install that too:


HlslParser is released under the MIT License.