Go ast: types for Go syntax trees
Answer: The ast package declares the types used to represent syntax trees for Go packages.
How trees are built
They are typically produced from Go source code by the parser.
All node types implement the Node interface.
Filtering and printing
A filter can drop import declarations from a file.
If the declaration is empty afterwards, the declaration is removed from the AST.
Unexported struct fields are never printed.
See also
Claims
- id: C1 claim: The package declares types for Go syntax trees. source: S1 evidence: "Package ast declares the types used to represent syntax trees for Go packages."
- id: C2 claim: Import declarations are always removed by that filter. source: S1 evidence: "Import declarations are always removed."
- id: C3 claim: All node types implement the Node interface. source: S2 evidence: "All node types implement the Node interface."
- id: C4 claim: A FuncType node represents a function type. source: S2 evidence: "A FuncType node represents a function type."
Sources
- [S1] go/ast. The Go Authors. https://pkg.go.dev/go/ast . License: BSD-3-Clause. Accessed 2026-11-25.
- [S2] go/ast source. The Go Authors. https://go.dev/src/go/ast/ast.go . License: BSD-3-Clause. Accessed 2026-11-25.
License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted). Sources: The Go Authors, go/ast; The Go Authors, go/ast source. BSD-3-Clause (https://go.dev/LICENSE). Copyright The Go Authors. Text was condensed and changed from the originals.
License: CC-BY-4.0 · Summary by iinventedlight (AI-assisted). Sources: The Go Authors, go/ast; The Go Authors, go/ast source. BSD-3-Clause (https://go.dev/LICENSE). Copyright The Go Authors.
Cite this
iinventedlight. 2026. "Go ast: types for Go syntax trees." iinventedlight Library, iil:note:tzr6m1tb, version of 2026-11-25. https://iinventedlight.com/library/notes/go-ast/. License: CC-BY-4.0.
@misc{iil_note_tzr6m1tb,
author = {{iinventedlight}},
title = {{Go ast: types for Go syntax trees}},
howpublished = {iinventedlight Library},
year = {2026},
date = {2026-11-25},
url = {https://iinventedlight.com/library/notes/go-ast/},
note = {Permanent ID iil:note:tzr6m1tb. License: CC-BY-4.0.},
}
Spotted a mistake? Use the MCP feedback tool or email hello@iinventedlight.com. Or Report a correction (no account needed).
Extra files beside this note
These files use this note's license, shown below. Paper extras retain their reproduction status; a link is not a reproduction.
- go-ast.schema.json (schema; CC-BY-4.0)
- go-ast.table.json (table; CC-BY-4.0)
For language models and agents: start at /llms.txt | /agents.md | /.well-known/agent-library.json. This page in Markdown: /library/notes/go-ast.md.