
Lexical Scanning in Go - Rob Pike
About this video
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 it appears in the archive
HN returns to it for years as an elegant introduction to writing a lexer that is easy to follow even without a parsing background.
AI-generated summary and labels from the source dataset; verify important details against the video. Source & credits.
From the Hacker News discussion
Personally, I have a penchant for writing my own pull parsers. Its a mind-expanding exercise. The neat thing about Go is that parsers can return functions that consume the next token. Rob Pike has an excellent video about this: [VIDEO]
Read original comment ↗Rob Pike did a really good talk entitled 'Lexical Scanning In Go'[0], which covers how the lexing for text/template works. It's far more interesting than it sounds, and even if you don't know much about lexing/parsing it's easy to follow. [0] [VIDEO]
Read original comment ↗Lexical Scanning in Go by Rob Pike [VIDEO] I love everything about this talk. It walks you through building a lexer from scratch in a simple and elegant way, through a very interesting use of coroutines. I appreciate the bits of humor in the talk as well.
Read original comment ↗Related, I love Rob Pike's talk about lexical Scanning in Go (2011). Educational and elegant approach. [VIDEO]
Read original comment ↗As an aside: watching Pike's talk on lexing and parsing in Go really hits this point home. It shows how language support for cheap threads (goroutines) and channels really change the way you come up with an algorithm. [VIDEO]
Read original comment ↗> Building a lexer out of a recursive function type actually sounds like a really cool thing to try Rob Pike did just that for Go's text/template package ( [LINK] ). See the source lexer source code at [LINK] and note that stateFn is defined recursively. There's a video by Pike describing how he built the parser at [VIDEO] .
Read original comment ↗> What most people don't realize is that for concurrency to be useful, there must be parallelism. No, as far as I understand from this and other talks, Rob Pike argues that concurrency is useful even without parallelism: it's a better way to structure software. A nice example for this is shown in his talk about lexical scanning in Go: [VIDEO]
Read original comment ↗I'm not sure I like the idea of parsing templates with regular expressions. There is a better way, as demonstrated in Robe Pike's video[1] detailing how the Go template language is implemented. Edit: which isn't meant to detract from the fact that this is a great article. [1] [VIDEO]
Read original comment ↗