Expand description
Strongly-typed AST types for Python, auto-generated from
tree-sitter-python’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 CPython source code.
See the Tree-sitter project for more information about the underlying parser framework.
§Example
use treesitter_types_python::*;
// A minimal Python hello-world program.
let src = b"\
def main():
print(\"Hello, World!\")
main()
";
// Parse the source with tree-sitter and convert into typed AST.
let mut parser = tree_sitter::Parser::new();
parser.set_language(&tree_sitter_python::LANGUAGE.into()).unwrap();
let tree = parser.parse(src, None).unwrap();
let module = Module::from_node(tree.root_node(), src).unwrap();
// The module has two top-level children.
assert_eq!(module.children.len(), 2);
// 1) The function definition — `def main(): ...`.
let ModuleChildren::CompoundStatement(stmt) = &module.children[0] else {
panic!("expected a compound statement");
};
let CompoundStatement::FunctionDefinition(func) = stmt.as_ref() else {
panic!("expected a function definition");
};
assert_eq!(func.name.text(), "main");
assert!(func.parameters.children.is_empty()); // no parameters
assert!(func.return_type.is_none()); // no return type annotation
// 2) The call expression — `main()`.
let ModuleChildren::SimpleStatement(call_stmt) = &module.children[1] else {
panic!("expected a simple statement");
};
let SimpleStatement::ExpressionStatement(expr) = call_stmt.as_ref() else {
panic!("expected an expression statement");
};
assert_eq!(expr.children.len(), 1);Re-exports§
pub use tree_sitter_python;pub use treesitter_types::tree_sitter;
Structs§
- Aliased
Import - Argument
List - AsPattern
- AsPattern
Target - Assert
Statement - Assignment
- Attribute
- Augmented
Assignment - Await
- Binary
Operator - Block
- Boolean
Operator - Break
Statement - Call
- Case
Clause - Case
Pattern - Chevron
- Class
Definition - Class
Pattern - Comment
- Comparison
Operator - Complex
Pattern - Concatenated
String - Conditional
Expression - Constrained
Type - Continue
Statement - Decorated
Definition - Decorator
- Default
Parameter - Delete
Statement - Dict
Pattern - Dictionary
- Dictionary
Comprehension - Dictionary
Splat - Dictionary
Splat Pattern - Dotted
Name - Elif
Clause - Ellipsis
- Else
Clause - Escape
Interpolation - Escape
Sequence - Except
Clause - Exec
Statement - Expression
List - Expression
Statement - False
- Finally
Clause - Float
- ForIn
Clause - ForStatement
- Format
Expression - Format
Specifier - Function
Definition - Future
Import Statement - Generator
Expression - Generic
Type - Global
Statement - Identifier
- IfClause
- IfStatement
- Import
From Statement - Import
Prefix - Import
Statement - Integer
- Interpolation
- Keyword
Argument - Keyword
Pattern - Keyword
Separator - Lambda
- Lambda
Parameters - Line
Continuation - List
- List
Comprehension - List
Pattern - List
Splat - List
Splat Pattern - Match
Statement - Member
Type - Module
- Named
Expression - None
- Nonlocal
Statement - NotOperator
- Pair
- Parameters
- Parenthesized
Expression - Parenthesized
List Splat - Pass
Statement - Pattern
List - Positional
Separator - Print
Statement - Raise
Statement - Relative
Import - Return
Statement - Set
- SetComprehension
- Slice
- Span
- Splat
Pattern - Splat
Type - String
- String
Content - String
End - String
Start - Subscript
- True
- TryStatement
- Tuple
- Tuple
Pattern - Type
- Type
Alias Statement - Type
Conversion - Type
Parameter - Typed
Default Parameter - Typed
Parameter - Unary
Operator - Union
Pattern - Union
Type - While
Statement - Wildcard
Import - With
Clause - With
Item - With
Statement - Yield
Enums§
- AnyNode
- Argument
List Children - AsPattern
Children - Assignment
Left - Assignment
Right - Augmented
Assignment Left - Augmented
Assignment Operator - Augmented
Assignment Right - Binary
Operator Operator - Block
Children - Boolean
Operator Operator - Call
Arguments - Case
Pattern Children - Class
Pattern Children - Comparison
Operator Operators - Complex
Pattern Children - Compound
Statement - Decorated
Definition Definition - Default
Parameter Name - Delete
Statement Children - Dict
Pattern Key - Dictionary
Children - Dictionary
Comprehension Children - Dictionary
Splat Pattern Children - Exec
Statement Code - Expression
- Expression
Statement Children - ForIn
Clause Left - ForIn
Clause Right - ForStatement
Left - ForStatement
Right - Format
Expression Expression - Future
Import Statement Name - Generator
Expression Children - Generic
Type Children - IfStatement
Alternative - Import
From Statement Module Name - Import
From Statement Name - Import
Statement Name - Interpolation
Expression - Keyword
Pattern Children - List
Children - List
Comprehension Children - List
Pattern Children - List
Splat Children - List
Splat Pattern Children - Member
Type Children - Module
Children - Parameter
- Parenthesized
Expression Children - Parenthesized
List Splat Children - Parse
Error - Pattern
- Primary
Expression - Raise
Statement Children - Relative
Import Children - Return
Statement Children - SetChildren
- SetComprehension
Children - Simple
Statement - String
Children - String
Content Children - Subscript
Subscript - TryStatement
Children - Tuple
Children - Tuple
Pattern Children - Type
Children - Typed
Parameter Children - Unary
Operator Operator - Union
Pattern Children - Yield
Children