← All notes

Go go/parser: a parser for Go source files

Answer: Package parser implements a parser for Go source files.

Entry points

ParseFile reads file input from a string, a byte slice, or a reader, and produces an abstract syntax tree of the file.

Position information is recorded in fset, which must not be nil.

The mode bits are passed to ParseFile unchanged.

ParseDir does not consider build tags when associating files with packages.

What the source comments say

This file contains the exported entry points for invoking the parser.

A Mode value is a set of flags, or zero.

Those flags control the amount of source code parsed and other optional parser functionality.

ParseFile parses the source code of a single Go source file and returns the corresponding file node.

See also

Claims

Sources

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/parser; The Go Authors, go/parser 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/parser; The Go Authors, go/parser source. BSD-3-Clause (https://go.dev/LICENSE). Copyright The Go Authors.

Cite this

Permanent ID: iil:note:efnhjpe2

iinventedlight. 2026. "Go go/parser: a parser for Go source files." iinventedlight Library, iil:note:efnhjpe2, version of 2026-11-24. https://iinventedlight.com/library/notes/go-parser/. License: CC-BY-4.0.

@misc{iil_note_efnhjpe2,
  author = {{iinventedlight}},
  title = {{Go go/parser: a parser for Go source files}},
  howpublished = {iinventedlight Library},
  year = {2026},
  date = {2026-11-24},
  url = {https://iinventedlight.com/library/notes/go-parser/},
  note = {Permanent ID iil:note:efnhjpe2. License: CC-BY-4.0.},
}

Markdown

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.

All artifact files (JSON index)

For language models and agents: start at /llms.txt | /agents.md | /.well-known/agent-library.json. This page in Markdown: /library/notes/go-parser.md.