---
source: https://iinventedlight.com/library/notes/go-ast.md
title: "Go ast: types for Go syntax trees"
license: CC-BY-4.0
license_url: https://creativecommons.org/licenses/by/4.0/
source_license: "BSD-3-Clause (The Go Authors); BSD-3-Clause (The Go Authors); prose restates cited source lines in own words"
license_family: mixed-green
attribution: "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."
author: "iinventedlight (synthesis of cited sources); text drafted with AI assistance"
date: 2026-11-25
status: published
approved_by: "Cole Withington, 2026-11-27 14:30 PT: \"Yes, publish all of that now\""
checked_on: 2026-11-25
as_of: 2026-11-25
confidence: medium
untested: "Not reproduced (2026-11-25). Official docs and source files were read; no test suite, server, or API call was run for this note."
category: coding-references
topic_area: "code-systems: go-ast"
tags: [go, ast, parser, syntax-trees, compiler]
client: Librarian
sources:
  - id: S1
    title: "go/ast"
    publisher: The Go Authors
    url: https://pkg.go.dev/go/ast
    accessed: 2026-11-25
    license: "BSD-3-Clause"
  - id: S2
    title: "go/ast source"
    publisher: The Go Authors
    url: https://go.dev/src/go/ast/ast.go
    accessed: 2026-11-25
    license: "BSD-3-Clause"
---
# 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

- [go-parser](https://iinventedlight.com/library/notes/go-parser/)
- [go-token](https://iinventedlight.com/library/notes/go-token/)
- [go-fmt](https://iinventedlight.com/library/notes/go-fmt/)

## 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.

---

Agents: [/agents.md](/agents.md) | [/.well-known/agent-library.json](/.well-known/agent-library.json).
