tree-sitter / tree-sitter-c-sharp

C# Grammar for tree-sitter
MIT License
177 stars 47 forks source link

Improve `#pragma` parsing #303

Open tamasvajk opened 1 year ago

tamasvajk commented 1 year ago

Invalid #pragma preprocessor directives produce warnings. The compiler is able to parse (and ignore) them. This is not the case currently with the tree-sitter grammar. For example the below produces an AST on sharplab.io:

#pragma warning disable 1     // Okay
#pragma warning disable CS1   // Okay
#pragma warning disable 1,2   // Okay

#pragma warning disable 1;2     // CS1696
#pragma warning suppress 1      // CS1634
#pragma                         // CS1633
#pragma anything can come here  // CS1633

;

I think these invalid directives come up fairly rarely. The only one that I've seen was #pragma warning suppress ....