treesitter_types_c_sharp/lib.rs
1//! Strongly-typed AST types for C#, auto-generated from
2//! [`tree-sitter-c-sharp`](https://docs.rs/tree-sitter-c-sharp)'s `node-types.json`.
3//!
4//! This crate is generated by [`treesitter-types`](https://docs.rs/treesitter-types) and is
5//! automatically kept up to date when a new version of the grammar crate is released.
6//!
7//! These types have been tested by parsing the
8//! [.NET Runtime](https://github.com/dotnet/runtime) source code.
9//!
10//! See the [Tree-sitter](https://tree-sitter.github.io/tree-sitter/) project for more
11//! information about the underlying parser framework.
12//!
13//! # Example
14//!
15//! ```
16//! use treesitter_types_c_sharp::*;
17//!
18//! // A minimal C# hello-world program (without using directives).
19//! let src = b"\
20//! class Hello {
21//! static void Main() {
22//! System.Console.WriteLine(\"Hello, World!\");
23//! }
24//! }
25//! ";
26//!
27//! // Parse the source with tree-sitter and convert into typed AST.
28//! let mut parser = tree_sitter::Parser::new();
29//! parser.set_language(&tree_sitter_c_sharp::LANGUAGE.into()).unwrap();
30//! let tree = parser.parse(src, None).unwrap();
31//! let cu = CompilationUnit::from_node(tree.root_node(), src).unwrap();
32//!
33//! // The compilation unit has one top-level child: the class declaration.
34//! assert_eq!(cu.children.len(), 1);
35//!
36//! let CompilationUnitChildren::TypeDeclaration(type_decl) = &cu.children[0] else {
37//! panic!("expected a type declaration");
38//! };
39//! let TypeDeclaration::ClassDeclaration(class) = type_decl.as_ref() else {
40//! panic!("expected a class declaration");
41//! };
42//! assert_eq!(class.name.text(), "Hello");
43//!
44//! // The class body contains one method.
45//! assert_eq!(class.body.as_ref().unwrap().children.len(), 1);
46//! ```
47
48pub use tree_sitter_c_sharp;
49pub use treesitter_types::tree_sitter;
50pub use treesitter_types::{FromNode, LeafNode, ParseError, Span, Spanned};
51
52mod generated;
53pub use generated::*;