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 *;
// 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 = new;
parser.set_language.unwrap;
let tree = parser.parse.unwrap;
let module = from_node.unwrap;
// The module has two top-level children.
assert_eq!;
// 1) The function definition — `def main(): ...`.
let CompoundStatement = &module.children else ;
let FunctionDefinition = stmt.as_ref else ;
assert_eq!;
assert!; // no parameters
assert!; // no return type annotation
// 2) The call expression — `main()`.
let SimpleStatement = &module.children else ;
let ExpressionStatement = call_stmt.as_ref else ;
assert_eq!;