Expand description
Strongly-typed AST types for C#, auto-generated from
tree-sitter-c-sharp’s node-types.json.
This crate is generated by treesitter-types and is
automatically kept up to date when a new version of the grammar crate is released.
These types have been tested by parsing the .NET Runtime source code.
See the Tree-sitter project for more information about the underlying parser framework.
§Example
use treesitter_types_c_sharp::*;
// A minimal C# hello-world program (without using directives).
let src = b"\
class Hello {
static void Main() {
System.Console.WriteLine(\"Hello, World!\");
}
}
";
// Parse the source with tree-sitter and convert into typed AST.
let mut parser = tree_sitter::Parser::new();
parser.set_language(&tree_sitter_c_sharp::LANGUAGE.into()).unwrap();
let tree = parser.parse(src, None).unwrap();
let cu = CompilationUnit::from_node(tree.root_node(), src).unwrap();
// The compilation unit has one top-level child: the class declaration.
assert_eq!(cu.children.len(), 1);
let CompilationUnitChildren::TypeDeclaration(type_decl) = &cu.children[0] else {
panic!("expected a type declaration");
};
let TypeDeclaration::ClassDeclaration(class) = type_decl.as_ref() else {
panic!("expected a class declaration");
};
assert_eq!(class.name.text(), "Hello");
// The class body contains one method.
assert_eq!(class.body.children.len(), 1);Structs§
- Accessor
Declaration - Accessor
List - Alias
Qualified Name - AndPattern
- Anonymous
Method Expression - Anonymous
Object Creation Expression - Argument
- Argument
List - Array
Creation Expression - Array
Rank Specifier - Array
Type - Arrow
Expression Clause - AsExpression
- Assignment
Expression - Attribute
- Attribute
Argument - Attribute
Argument List - Attribute
List - Attribute
Target Specifier - Await
Expression - Base
List - Binary
Expression - Block
- Boolean
Literal - Bracketed
Argument List - Bracketed
Parameter List - Break
Statement - Calling
Convention - Cast
Expression - Catch
Clause - Catch
Declaration - Catch
Filter Clause - Character
Literal - Character
Literal Content - Checked
Expression - Checked
Statement - Class
Declaration - Comment
- Compilation
Unit - Conditional
Access Expression - Conditional
Expression - Constant
Pattern - Constructor
Constraint - Constructor
Declaration - Constructor
Initializer - Continue
Statement - Conversion
Operator Declaration - Declaration
Expression - Declaration
List - Declaration
Pattern - Default
Expression - Delegate
Declaration - Destructor
Declaration - Discard
- DoStatement
- Element
Access Expression - Element
Binding Expression - Empty
Statement - Enum
Declaration - Enum
Member Declaration - Enum
Member Declaration List - Escape
Sequence - Event
Declaration - Event
Field Declaration - Explicit
Interface Specifier - Expression
Statement - Extern
Alias Directive - Field
Declaration - File
Scoped Namespace Declaration - Finally
Clause - Fixed
Statement - ForStatement
- Foreach
Statement - From
Clause - Function
Pointer Parameter - Function
Pointer Type - Generic
Name - Global
Attribute - Global
Statement - Goto
Statement - Group
Clause - Identifier
- IfStatement
- Implicit
Array Creation Expression - Implicit
Object Creation Expression - Implicit
Parameter - Implicit
Stackalloc Expression - Implicit
Type - Indexer
Declaration - Initializer
Expression - Integer
Literal - Interface
Declaration - Interpolated
String Expression - Interpolation
- Interpolation
Alignment Clause - Interpolation
Brace - Interpolation
Format Clause - Interpolation
Quote - Interpolation
Start - Invocation
Expression - IsExpression
- IsPattern
Expression - Join
Clause - Join
Into Clause - Labeled
Statement - Lambda
Expression - LetClause
- List
Pattern - Local
Declaration Statement - Local
Function Statement - Lock
Statement - Makeref
Expression - Member
Access Expression - Member
Binding Expression - Method
Declaration - Modifier
- Namespace
Declaration - Negated
Pattern - Null
Literal - Nullable
Type - Object
Creation Expression - Operator
Declaration - OrPattern
- Order
ByClause - Parameter
- Parameter
List - Parenthesized
Expression - Parenthesized
Pattern - Parenthesized
Variable Designation - Pointer
Type - Positional
Pattern Clause - Postfix
Unary Expression - Predefined
Type - Prefix
Unary Expression - Preproc
Arg - Preproc
Define - Preproc
Elif - Preproc
Else - Preproc
Endregion - Preproc
Error - Preproc
If - Preproc
Line - Preproc
Nullable - Preproc
Pragma - Preproc
Region - Preproc
Undef - Preproc
Warning - Primary
Constructor Base Type - Property
Declaration - Property
Pattern Clause - Qualified
Name - Query
Expression - Range
Expression - RawString
Content - RawString
End - RawString
Literal - RawString
Start - Real
Literal - Record
Declaration - Recursive
Pattern - RefExpression
- RefType
- Reftype
Expression - Refvalue
Expression - Relational
Pattern - Return
Statement - Scoped
Type - Select
Clause - Shebang
Directive - Sizeof
Expression - Span
- Stackalloc
Expression - String
Content - String
Literal - String
Literal Content - String
Literal Encoding - Struct
Declaration - Subpattern
- Switch
Body - Switch
Expression - Switch
Expression Arm - Switch
Section - Switch
Statement - Throw
Expression - Throw
Statement - TryStatement
- Tuple
Element - Tuple
Expression - Tuple
Pattern - Tuple
Type - Type
Argument List - Type
Parameter - Type
Parameter Constraint - Type
Parameter Constraints Clause - Type
Parameter List - Type
Pattern - Typeof
Expression - Unary
Expression - Unsafe
Statement - Using
Directive - Using
Statement - VarPattern
- Variable
Declaration - Variable
Declarator - Verbatim
String Literal - When
Clause - Where
Clause - While
Statement - With
Expression - With
Initializer - Yield
Statement
Enums§
- Accessor
Declaration Body - Accessor
Declaration Children - Accessor
Declaration Name - Alias
Qualified Name Name - AndPattern
Operator - Anonymous
Method Expression Children - Anonymous
Object Creation Expression Children - AnyNode
- Argument
Children - Array
Type Type - AsExpression
Operator - Assignment
Expression Operator - Attribute
Argument Children - Attribute
List Children - Attribute
Name - Base
List Children - Binary
Expression Left - Binary
Expression Operator - Binary
Expression Right - Bracketed
Parameter List Children - Bracketed
Parameter List Type - Catch
Clause Children - Character
Literal Children - Class
Declaration Children - Compilation
Unit Children - Conditional
Access Expression Children - Constant
Pattern Children - Constructor
Declaration Body - Constructor
Declaration Children - Conversion
Operator Declaration Body - Conversion
Operator Declaration Children - Declaration
- Declaration
Pattern Children - Delegate
Declaration Children - Destructor
Declaration Body - Enum
Declaration Children - Enum
Member Declaration List Children - Event
Declaration Children - Event
Field Declaration Children - Explicit
Interface Specifier Children - Expression
- Expression
Statement Children - Field
Declaration Children - File
Scoped Namespace Declaration Name - Fixed
Statement Children - ForStatement
Initializer - ForStatement
Update - Foreach
Statement Left - Function
Pointer Parameter Type - Function
Pointer Type Children - Generic
Name Children - Implicit
Object Creation Expression Children - Indexer
Declaration Children - Interface
Declaration Children - Interpolated
String Expression Children - Interpolation
Children - IsExpression
Operator - Join
Clause Children - Labeled
Statement Children - Lambda
Expression Body - Lambda
Expression Children - Lambda
Expression Parameters - LetClause
Children - Literal
- Local
Declaration Statement Children - Local
Function Statement Body - Local
Function Statement Children - Lock
Statement Children - Lvalue
Expression - Member
Access Expression Expression - Member
Access Expression Name - Member
Binding Expression Name - Method
Declaration Body - Method
Declaration Children - Namespace
Declaration Name - NonLvalue
Expression - Nullable
Type Type - Operator
Declaration Body - Operator
Declaration Children - Operator
Declaration Operator - OrPattern
Operator - Parameter
Children - Parameter
List Children - Parameter
List Type - Parenthesized
Expression Children - Parenthesized
Variable Designation Children - Parse
Error - Pattern
- Pointer
Type Type - Preproc
Elif Alternative - Preproc
Elif Children - Preproc
Elif Condition - Preproc
Else Children - Preproc
IfAlternative - Preproc
IfChildren - Preproc
IfCondition - Preproc
Line Children - Preproc
Pragma Children - Primary
Constructor Base Type Type - Property
Declaration Children - Property
Declaration Value - Qualified
Name Name - Qualified
Name Qualifier - Query
Expression Children - RawString
Literal Children - Record
Declaration Children - Recursive
Pattern Children - Scoped
Type Type - Statement
- String
Literal Children - Struct
Declaration Children - Subpattern
Children - Switch
Expression ArmChildren - Switch
Expression Children - Switch
Section Children - Switch
Statement Value - TryStatement
Children - Tuple
Pattern Children - Type
- Type
Declaration - Type
Parameter Constraints Clause Children - Unary
Expression Argument - Unary
Expression Operator - Using
Statement Children - VarPattern
Children - Variable
Declarator Children - With
Expression Children - With
Initializer Children