C# grammar for tree-sitter based on an export of the Roslyn grammar export with various changes in order to:
- Deal with differences between the parsing technologies
- Work around some bugs in that grammar
- Handle
#if,#else,#elif,#endifblocks - Support syntax highlighting/parsing of fragments
- Simplify the output tree
Comprehensive support for C# exists with the following exceptions:
-
asyncandawaitcannot be used as identifiers
- Tuples
- Discards
- Basic pattern matching
- Recursive pattern matching
- Ref locals and return
- Local function statements
- Expression bodied constructors
- Expression bodied destructors/finalizers
- Throw expressions
- Binary and
_literal support
-
asyncmain method - Default literals (as
default_expression) - Inferred tuple element names
- Generic type pattern matching
-
inparameter modifiers -
ref readonlymethod returns -
readonly struct -
ref struct - Non-trailing named arguments
-
_leading binary and hex literals -
private protectedmodifier - Conditional
refexpressions
-
stackallocarray initializers -
unmanagedgeneric type parameter constraint - Attributes attached to auto property backing fields
-
outsupport for parameters on initializers, constructors etc.
-
readonlymembers - Default interface methods
-
switchexpressions -
switchproperty patterns -
switchtuple patterns -
staticlocal functions - Nullable reference types
- Null-forgiving operator
- Null-coalescing assignment
- 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
- 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)