ast-grep-tree-sitter-c-sharp
C# grammar for tree-sitter based upon the Roslyn grammar with changes in order to:
- Deal with differences between the parsing technologies
- Work around some bugs in that grammar
- Handle
#if
,#else
,#elif
,#endif
blocks - Support syntax highlighting/parsing of fragments
- Simplify the output tree
Status
Comprehensive supports C# 1 through 10.0 with the following exceptions:
-
async
,var
andawait
cannot be used as identifiers everywhere they are valid
C# 9.0 (complete)
- Covariant returns
- Extending partial methods
- Extension GetEnumerator
- Function pointers
- Init properties
- Lambda discard parameters
- Local function attributes
- Module initializers
- Native integers
- Patterns
- Simple type patterns
- Relational patterns
- Logical patterns
- Records
- Skip Locals Init
- Static anonymous functions
- Target-typed conditional expression
- Target-typed new
- Top-level statements
C# 10.0
- global using directives
- File-scoped namespace declaration
- Extended property patterns
- Allow const interpolated strings
- Record types can seal ToString()
- Allow both assignment and declaration in the same deconstruction
- Allow AsyncMethodBuilder attribute on methods
- Record structs
- Lambda improvements
C# 11.0 (under development)
- Generic attributes
- Static abstract members in interfaces
- Newlines in string interpolations
- List patterns
- Slice pattern
- Required members
- Raw string literals
References
- Official C# 6 Language Spec provides chapters that formally define the language grammar.
- Roslyn C# language grammar export
- SharpLab (web-based syntax tree playground based on Roslyn)