treesitter-types-c-sharp 0.1.1

Pre-generated strongly-typed AST types for C# (tree-sitter-c-sharp)
Documentation

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);