Expand description
Strongly-typed AST types for C, auto-generated from
tree-sitter-c’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 Git source code.
See the Tree-sitter project for more information about the underlying parser framework.
§Example
use treesitter_types_c::*;
// A minimal C hello-world program.
let src = b"\
#include <stdio.h>
int main() {
printf(\"Hello, World!\\n\");
return 0;
}
";
// Parse the source with tree-sitter and convert into typed AST.
let mut parser = tree_sitter::Parser::new();
parser.set_language(&tree_sitter_c::LANGUAGE.into()).unwrap();
let tree = parser.parse(src, None).unwrap();
let tu = TranslationUnit::from_node(tree.root_node(), src).unwrap();
// The translation unit has two top-level children.
assert_eq!(tu.children.len(), 2);
// 1) The #include directive.
let TranslationUnitChildren::PreprocInclude(include) = &tu.children[0] else {
panic!("expected a preproc include");
};
assert_eq!(include.span.start.row, 0);
// 2) The `main` function definition with return type `int`.
let TranslationUnitChildren::FunctionDefinition(func) = &tu.children[1] else {
panic!("expected a function definition");
};
let TypeSpecifier::PrimitiveType(return_type) = &func.r#type else {
panic!("expected a primitive type");
};
assert_eq!(return_type.text(), "int");
// The declarator holds the function name and parameter list.
let Declarator::FunctionDeclarator(decl) = &func.declarator else {
panic!("expected a function declarator");
};
assert!(decl.parameters.children.is_empty()); // no parametersRe-exports§
pub use tree_sitter_c;pub use treesitter_types::tree_sitter;
Structs§
- Abstract
Array Declarator - Abstract
Function Declarator - Abstract
Parenthesized Declarator - Abstract
Pointer Declarator - Alignas
Qualifier - Alignof
Expression - Argument
List - Array
Declarator - Assignment
Expression - Attribute
- Attribute
Declaration - Attribute
Specifier - Attributed
Declarator - Attributed
Statement - Binary
Expression - Bitfield
Clause - Break
Statement - Call
Expression - Case
Statement - Cast
Expression - Char
Literal - Character
- Comma
Expression - Comment
- Compound
Literal Expression - Compound
Statement - Concatenated
String - Conditional
Expression - Continue
Statement - Declaration
- Declaration
List - DoStatement
- Else
Clause - Enum
Specifier - Enumerator
- Enumerator
List - Escape
Sequence - Expression
Statement - Extension
Expression - False
- Field
Declaration - Field
Declaration List - Field
Designator - Field
Expression - Field
Identifier - ForStatement
- Function
Declarator - Function
Definition - Generic
Expression - GnuAsm
Clobber List - GnuAsm
Expression - GnuAsm
Goto List - GnuAsm
Input Operand - GnuAsm
Input Operand List - GnuAsm
Output Operand - GnuAsm
Output Operand List - GnuAsm
Qualifier - Goto
Statement - Identifier
- IfStatement
- Init
Declarator - Initializer
List - Initializer
Pair - Labeled
Statement - Linkage
Specification - Macro
Type Specifier - MsBased
Modifier - MsCall
Modifier - MsDeclspec
Modifier - MsPointer
Modifier - MsRestrict
Modifier - MsSigned
PtrModifier - MsUnaligned
PtrModifier - MsUnsigned
PtrModifier - Null
- Number
Literal - Offsetof
Expression - Parameter
Declaration - Parameter
List - Parenthesized
Declarator - Parenthesized
Expression - Pointer
Declarator - Pointer
Expression - Preproc
Arg - Preproc
Call - Preproc
Def - Preproc
Defined - Preproc
Directive - Preproc
Elif - Preproc
Elifdef - Preproc
Else - Preproc
Function Def - Preproc
If - Preproc
Ifdef - Preproc
Include - Preproc
Params - Primitive
Type - Return
Statement - SehExcept
Clause - SehFinally
Clause - SehLeave
Statement - SehTry
Statement - Sized
Type Specifier - Sizeof
Expression - Span
- Statement
Identifier - Storage
Class Specifier - String
Content - String
Literal - Struct
Specifier - Subscript
Designator - Subscript
Expression - Subscript
Range Designator - Switch
Statement - System
LibString - Translation
Unit - True
- Type
Definition - Type
Descriptor - Type
Identifier - Type
Qualifier - Unary
Expression - Union
Specifier - Update
Expression - Variadic
Parameter - While
Statement
Enums§
- Abstract
Array Declarator Size - Abstract
Declarator - Abstract
Parenthesized Declarator Children - Abstract
Pointer Declarator Children - Alignas
Qualifier Children - AnyNode
- Argument
List Children - Array
Declarator Declarator - Array
Declarator Size - Assignment
Expression Left - Assignment
Expression Operator - Attributed
Declarator Children - Attributed
Statement Children - Binary
Expression Left - Binary
Expression Operator - Binary
Expression Right - Case
Statement Children - Char
Literal Children - Comma
Expression Right - Compound
Statement Children - Concatenated
String Children - Conditional
Expression Consequence - Declaration
Children - Declaration
Declarator - Declaration
List Children - Declarator
- Enumerator
List Children - Expression
- Expression
Statement Children - Field
Declaration Children - Field
Declaration List Children - Field
Declarator - Field
Expression Operator - ForStatement
Condition - ForStatement
Initializer - ForStatement
Update - Function
Declarator Children - Function
Declarator Declarator - Function
Definition Children - Generic
Expression Children - GnuAsm
Clobber List Register - GnuAsm
Expression Assembly Code - Init
Declarator Value - Initializer
List Children - Initializer
Pair Designator - Initializer
Pair Value - Labeled
Statement Children - Linkage
Specification Body - MsPointer
Modifier Children - Parameter
Declaration Children - Parameter
Declaration Declarator - Parameter
List Children - Parenthesized
Declarator Children - Parenthesized
Expression Children - Parse
Error - Pointer
Declarator Children - Pointer
Declarator Declarator - Pointer
Expression Operator - Preproc
Elif Alternative - Preproc
Elif Children - Preproc
Elif Condition - Preproc
Elifdef Alternative - Preproc
Elifdef Children - Preproc
Else Children - Preproc
IfAlternative - Preproc
IfChildren - Preproc
IfCondition - Preproc
Ifdef Alternative - Preproc
Ifdef Children - Preproc
Include Path - Return
Statement Children - SehTry
Statement Children - Sized
Type Specifier Type - Statement
- String
Literal Children - Struct
Specifier Children - Translation
Unit Children - Type
Declarator - Type
Definition Children - Type
Specifier - Unary
Expression Argument - Unary
Expression Operator - Union
Specifier Children - Update
Expression Operator