Expand description
Strongly-typed AST types for Go, auto-generated from
tree-sitter-go’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 Go compiler source code.
See the Tree-sitter project for more information about the underlying parser framework.
§Example
use treesitter_types_go::*;
// A minimal Go hello-world program.
let src = b"\
package main
import \"fmt\"
func main() {
fmt.Println(\"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_go::LANGUAGE.into()).unwrap();
let tree = parser.parse(src, None).unwrap();
let source_file = SourceFile::from_node(tree.root_node(), src).unwrap();
// The source file has three top-level children.
assert_eq!(source_file.children.len(), 3);
// 1) The package clause — `package main`.
let SourceFileChildren::PackageClause(pkg) = &source_file.children[0] else {
panic!("expected a package clause");
};
assert_eq!(pkg.children.text(), "main");
// 2) The import declaration — `import "fmt"`.
let SourceFileChildren::ImportDeclaration(import) = &source_file.children[1] else {
panic!("expected an import declaration");
};
let ImportDeclarationChildren::ImportSpec(spec) = &import.children else {
panic!("expected a single import spec");
};
assert!(spec.name.is_none()); // no alias
// 3) The function declaration — `func main() { ... }`.
let SourceFileChildren::FunctionDeclaration(func) = &source_file.children[2] else {
panic!("expected a function declaration");
};
assert_eq!(func.name.text(), "main");
assert!(func.parameters.children.is_empty()); // no parameters
assert!(func.result.is_none()); // no return type
assert!(func.body.is_some()); // has a bodyRe-exports§
pub use tree_sitter_go;pub use treesitter_types::tree_sitter;
Structs§
- Argument
List - Array
Type - Assignment
Statement - Binary
Expression - Blank
Identifier - Block
- Break
Statement - Call
Expression - Channel
Type - Comment
- Communication
Case - Composite
Literal - Const
Declaration - Const
Spec - Continue
Statement - DecStatement
- Default
Case - Defer
Statement - Dot
- Empty
Statement - Escape
Sequence - Expression
Case - Expression
List - Expression
Statement - Expression
Switch Statement - Fallthrough
Statement - False
- Field
Declaration - Field
Declaration List - Field
Identifier - Float
Literal - ForClause
- ForStatement
- Func
Literal - Function
Declaration - Function
Type - Generic
Type - GoStatement
- Goto
Statement - Identifier
- IfStatement
- Imaginary
Literal - Implicit
Length Array Type - Import
Declaration - Import
Spec - Import
Spec List - IncStatement
- Index
Expression - IntLiteral
- Interface
Type - Interpreted
String Literal - Interpreted
String Literal Content - Iota
- Keyed
Element - Label
Name - Labeled
Statement - Literal
Element - Literal
Value - MapType
- Method
Declaration - Method
Elem - Negated
Type - Nil
- Package
Clause - Package
Identifier - Parameter
Declaration - Parameter
List - Parenthesized
Expression - Parenthesized
Type - Pointer
Type - Qualified
Type - Range
Clause - RawString
Literal - RawString
Literal Content - Receive
Statement - Return
Statement - Rune
Literal - Select
Statement - Selector
Expression - Send
Statement - Short
VarDeclaration - Slice
Expression - Slice
Type - Source
File - Span
- Statement
List - Struct
Type - True
- Type
Alias - Type
Arguments - Type
Assertion Expression - Type
Case - Type
Constraint - Type
Conversion Expression - Type
Declaration - Type
Elem - Type
Identifier - Type
Instantiation Expression - Type
Parameter Declaration - Type
Parameter List - Type
Spec - Type
Switch Statement - Unary
Expression - VarDeclaration
- VarSpec
- VarSpec
List - Variadic
Argument - Variadic
Parameter Declaration
Enums§
- AnyNode
- Argument
List Children - Assignment
Statement Operator - Binary
Expression Operator - Communication
Case Communication - Composite
Literal Type - Const
Spec Name - Expression
- Expression
Switch Statement Children - Field
Declaration Tag - Field
Declaration Type - ForStatement
Children - Func
Literal Result - Function
Declaration Result - Function
Type Result - Generic
Type Type - IfStatement
Alternative - Import
Declaration Children - Import
Spec Name - Import
Spec Path - Interface
Type Children - Interpreted
String Literal Children - Literal
Element Children - Literal
Value Children - Method
Declaration Result - Method
Elem Result - Parameter
List Children - Parse
Error - Select
Statement Children - Simple
Statement - Simple
Type - Source
File Children - Statement
- Type
- Type
Case Type - Type
Declaration Children - Type
Switch Statement Children - Unary
Expression Operator - VarDeclaration
Children