Lexical Scanning in Go - Rob Pike
What it is
Rob Pike shows how the Go text/template lexer is built, using state functions, goroutines and channels. The talk was given at a Google Technology User Group in Sydney in 2011.
Why Hacker News recommends it
HN returns to it for years as an elegant introduction to writing a lexer that is easy to follow even without a parsing background.
- 13 people recommended it
- 12 different months
- 4 strong recommendations
- first 2012, last 2025
What HN commenters said
“Rob Pike has an excellent video about this”
Pike on parsers returning functions that consume the next token.
willvarfar, 2012-06 · Strong recommendation · in “Parsing huge XML files with Go”
“It's far more interesting than it sounds, and even if you don't know much about lexing/parsing it's easy to follow.”
Explains lexing in text/template; easy to follow even without parsing background.
TomNomNom, 2014-05 · Strong recommendation · in “Templating in Go”
“I love everything about this talk.”
Builds a lexer from scratch simply and elegantly using coroutines, with humor.
grose, 2016-10 · Strong recommendation · in “Ask HN: What's your favorite tech talk?”
“I love Rob Pike's talk about lexical Scanning in Go (2011). Educational and elegant approach.”
Educational and elegant approach to lexical scanning.
hu3, 2024-11 · Strong recommendation · in “Rust for tokenising and parsing”
“watching Pike's talk on lexing and parsing in Go really hits this point home.”
Shows how goroutines and channels change how you design algorithms.
drbawb, 2012-03 · Recommendation · in “Go is amazing, period.”
“There's a video by Pike describing how he built the parser at”
Pike describes building the text/template lexer using recursive state functions.
jbarham, 2013-02 · Recommendation · in “Function types in Go”
“A nice example for this is shown in his talk about lexical scanning in Go”
Example of concurrency as a way to structure software, without parallelism.
mseepgood, 2013-02 · Recommendation · in “Concurrency is not Parallelism. Rob Pike at Waza 2012 [video]”
“There is a better way, as demonstrated in Robe Pike's video[1] detailing how the Go template language is implemented.”
Shows a better alternative to regex for parsing templates.
thisishugo, 2013-04 · Recommendation · in “Building a toy template engine in Python”
Excerpts from Hacker News comments, linked to the originals. Summaries and labels were written by a language model from those comments.
Topics: go, lexer, rob pike, state machines, concurrency, parsing
Also recommended by the same people
talkGoogle I/O 2012 - Go Concurrency PatternsGoogle for Developers · 9 HN recommenders · 2012–2025
talkOrigins of Go Concurrency style by Rob Pikejasonofthel33t · 3 HN recommenders · 2013–2025
explainerHow Analog Color TV Works: The BeginningsTechnology Connections · 2 HN recommenders · 2019–2026
talkPitfall: A Classic Game PostmortemGDC Festival of Gaming · 2 HN recommenders · 2021–2024
talkBob Nystrom - Is There More to Game Architecture than ECS?Roguelike Celebration · 3 HN recommenders · 2020–2026
talkFailing to Fail: The Spiderweb Software WayGDC Festival of Gaming · 11 HN recommenders · 2018–2025
talkZFS Native Encryption by Tom CaputiOpenZFS · 2 HN recommenders · 2016–2022
demoPrimitive Technology: Tiled Roof HutPrimitive Technology · 3 HN recommenders · 2015–2018