Skip to main content

Crate treesitter_types_go

Crate treesitter_types_go 

Source
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 body

Re-exports§

pub use tree_sitter_go;
pub use treesitter_types::tree_sitter;

Structs§

ArgumentList
ArrayType
AssignmentStatement
BinaryExpression
BlankIdentifier
Block
BreakStatement
CallExpression
ChannelType
Comment
CommunicationCase
CompositeLiteral
ConstDeclaration
ConstSpec
ContinueStatement
DecStatement
DefaultCase
DeferStatement
Dot
EmptyStatement
EscapeSequence
ExpressionCase
ExpressionList
ExpressionStatement
ExpressionSwitchStatement
FallthroughStatement
False
FieldDeclaration
FieldDeclarationList
FieldIdentifier
FloatLiteral
ForClause
ForStatement
FuncLiteral
FunctionDeclaration
FunctionType
GenericType
GoStatement
GotoStatement
Identifier
IfStatement
ImaginaryLiteral
ImplicitLengthArrayType
ImportDeclaration
ImportSpec
ImportSpecList
IncStatement
IndexExpression
IntLiteral
InterfaceType
InterpretedStringLiteral
InterpretedStringLiteralContent
Iota
KeyedElement
LabelName
LabeledStatement
LiteralElement
LiteralValue
MapType
MethodDeclaration
MethodElem
NegatedType
Nil
PackageClause
PackageIdentifier
ParameterDeclaration
ParameterList
ParenthesizedExpression
ParenthesizedType
PointerType
QualifiedType
RangeClause
RawStringLiteral
RawStringLiteralContent
ReceiveStatement
ReturnStatement
RuneLiteral
SelectStatement
SelectorExpression
SendStatement
ShortVarDeclaration
SliceExpression
SliceType
SourceFile
Span
StatementList
StructType
True
TypeAlias
TypeArguments
TypeAssertionExpression
TypeCase
TypeConstraint
TypeConversionExpression
TypeDeclaration
TypeElem
TypeIdentifier
TypeInstantiationExpression
TypeParameterDeclaration
TypeParameterList
TypeSpec
TypeSwitchStatement
UnaryExpression
VarDeclaration
VarSpec
VarSpecList
VariadicArgument
VariadicParameterDeclaration

Enums§

AnyNode
ArgumentListChildren
AssignmentStatementOperator
BinaryExpressionOperator
CommunicationCaseCommunication
CompositeLiteralType
ConstSpecName
Expression
ExpressionSwitchStatementChildren
FieldDeclarationTag
FieldDeclarationType
ForStatementChildren
FuncLiteralResult
FunctionDeclarationResult
FunctionTypeResult
GenericTypeType
IfStatementAlternative
ImportDeclarationChildren
ImportSpecName
ImportSpecPath
InterfaceTypeChildren
InterpretedStringLiteralChildren
LiteralElementChildren
LiteralValueChildren
MethodDeclarationResult
MethodElemResult
ParameterListChildren
ParseError
SelectStatementChildren
SimpleStatement
SimpleType
SourceFileChildren
Statement
Type
TypeCaseType
TypeDeclarationChildren
TypeSwitchStatementChildren
UnaryExpressionOperator
VarDeclarationChildren

Traits§

FromNode
Every generated struct and enum implements this.
LeafNode
Implemented by every generated leaf type (identifiers, literals, etc.)
Spanned
Implemented by every generated type that has a source location.