Go text/scanner: tokenize UTF-8 text with repeated Scan calls
Answer: Package scanner provides a scanner and tokenizer for UTF-8-encoded text.
Defaults
The NUL character is not allowed, for compatibility with existing tools.
A UTF-8 encoded byte order mark at the start of the source is discarded.
In the default setup, white space and Go comments are ignored, and the literal forms in the Go language specification are recognized.
It may be customized to recognize only a subset of those literals and different identifier characters.
Using it
Repeated Scan calls tokenize the source.
See also
Claims
- id: C1 claim: The package scans and tokenizes UTF-8-encoded text. source: S1 evidence: "Package scanner provides a scanner and tokenizer for UTF-8-encoded text."
- id: C2 claim: The NUL character is not allowed. source: S1 evidence: "The NUL character is not allowed."
- id: C3 claim: Init prepares a Scanner and can invalidate a stored position. source: S2 evidence: "Calling Init or Next invalidates the position"
Sources
- [S1] text/scanner. The Go Authors. https://pkg.go.dev/text/scanner . License: BSD-3-Clause. Accessed 2026-11-26.
- [S2] text/scanner source. The Go Authors. https://go.dev/src/text/scanner/scanner.go . License: BSD-3-Clause. Accessed 2026-11-26.
License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted). Sources: The Go Authors, text/scanner; The Go Authors, text/scanner 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, text/scanner; The Go Authors, text/scanner source. BSD-3-Clause (https://go.dev/LICENSE). Copyright The Go Authors.
Cite this
iinventedlight. 2026. "Go text/scanner: tokenize UTF-8 text with repeated Scan calls." iinventedlight Library, iil:note:pgn02bft, version of 2026-11-26. https://iinventedlight.com/library/notes/go-text-scanner/. License: CC-BY-4.0.
@misc{iil_note_pgn02bft,
author = {{iinventedlight}},
title = {{Go text/scanner: tokenize UTF-8 text with repeated Scan calls}},
howpublished = {iinventedlight Library},
year = {2026},
date = {2026-11-26},
url = {https://iinventedlight.com/library/notes/go-text-scanner/},
note = {Permanent ID iil:note:pgn02bft. 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-text-scanner.schema.json (schema; CC-BY-4.0)
- go-text-scanner.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-text-scanner.md.