Lexical Scanning in Go - Rob Pike
GoogleFOSSSydney13 HN recommenders · recommended in 12 months, 2012-2025
162K views · 15 years ago · talk · evergreen
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.
HN returns to it for years as an elegant introduction to writing a lexer that is easy to follow even without a parsing background.
51:27Google I/O 2012 - Go Concurrency Patterns
Google for Developers
894K views • 14 years ago
1:07:00Sydney Golang Meetup - Rob Pike - Go 2 Draft Specifications
Macquarie Group
57K views • 7 years ago
23:57GopherCon 2016: The Design of the Go Assembler - Rob Pike
Gopher Academy
116K views • 10 years ago
0:27Rob Pike about the target group of the Go programming language (golang)
f8C4G86p KbqEFe47
7K views • 6 years ago
12:31OSCON 2010: Rob Pike, "Public Static Void"
O'Reilly
119K views • 16 years ago
23:12dotGo 2015 - Rob Pike - Simplicity is Complicated
dotconferences
172K views • 10 years ago
59:26The Go Programming Language
Google TechTalks
406K views • 16 years ago
22:29Gopherfest 2015 | Go Proverbs with Rob Pike
The Go Programming Language
317K views • 10 years ago
1:00:40Dmitry Vyukov — Go scheduler: Implementing language with lightweight concurrency
Hydra
47K views • 7 years ago
56:36GopherCon 2014 Opening Keynote by Rob Pike
Confreaks
38K views • 12 years ago
1:05:56Lang NEXT 2014 Panel Systems Programming in 2014 and Beyond
25msr
3K views • 8 years ago
31:23Concurrency is not Parallelism by Rob Pike
gnbitcom
191K views • 10 years ago
38:19Origins of Go Concurrency style by Rob Pike
jasonofthel33t
28K views • 14 years ago
1:00:29Google I/O 2012 - Meet the Go Team
Google for Developers
108K views • 14 years ago
51:12Google I/O 2011: Writing Web Apps in Go
Google for Developers
135K views • 15 years ago
48:19GopherCon 2014 Inside the Gophers Studio with Blake Mizerany
Confreaks
8K views • 12 years ago
1:03:31Brian Goetz - Stewardship: the Sobering Parts
ClojureTV
39K views • 11 years ago
38:38"Tree-sitter - a new parsing system for programming tools" by Max Brunsfeld
Strange Loop Conference
63K views • 8 years ago
1:13:10Parsing with Derivatives
Stanford
13K views • 15 years ago
56:49Escape from the Heap: Low-Level Programming in Common Lisp
Arthur Gleckler
17K views • 10 years ago
20 comments from Hacker News
If you enjoyed the state machine + parsing part and also I recommend the older "Lexical Scanning in Go" talk that Rob Pike gave: ▶ this video It's in Go, but you can apply most of it easily in other languages. I'm so happy that modern languages like Rust, Zig, and Go support unicode/runes/graphemes natively. So many problem just disappear compared to Java, .net, C++, or scripting languages.
There are many explanations. The most famous one Rob Pike in his lexer talk 2011 ▶ this video at 10.48 Or link Or several articles why you should not parse with regex, like link
Related, I love Rob Pike's talk about lexical Scanning in Go (2011). Educational and elegant approach. ▶ this video
> I think Go spent a lot of time implying that goroutines were some sort of special language magic, but I think everybody knows now that they are basically a really good implementation of green threads that can take advantage of some internal knowledge to do optimal scheduling to avoid context switches. It took me a while to work this out, and I got a lot of pushback from the go team when I pointed this out internally. This comment deeply fascinates me, because I get the same feeling every time I go back and read/watch early Go resources from Rob Pike and others, but I've never actually heard it articulated before. I've always thought that surely they weren't that ignorant about PL theory and history? Or maybe Rob Pike himself was, but surely his team knew better? It really feels like they thought they were making some special hybrid between threads and coroutines, combining the advantages of both. Like this 2011 talk[1] which demonstrated a classic coroutine code pattern implemented with goroutines and channels. But as time went on, goroutines became fully pre-emptive, and their programming model is now identical to threads. Using them as coroutines only leads to misery (read: data races) in my experience. They're faster than OS threads, sure, but that's an implementation detail at this point. When do you think they eventually realized they were re-inventing the same green threads Java had created and scrapped 10 years earlier? [1] ▶ this video
Rob Pike’s lexer was very nicely done and struck a chord with me. It’s not nearly as magical as some of the other things here. It’s just great engineering: ▶ this video
I have to admit that when I first heard the Jackson reference in ▶ this video I thought it was about the other Jackson.
Lexical Scanning in Go by Rob Pike ▶ this 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.
Here's a video of Rob Pike, developer of Go, talking about a lexer he built for the Go text/template package: ▶ this video It supports unicode.
I would like to mention that most, if not all, of the Go compiler and related utilities is written in Go itself, with high quality, open source code that can be found in the "go" package of the standard library: link I would recommend using that as a template for one's own compiler, because it's written in idiomatic Go (originally by the language creators) and is cleanly split across abstraction boundaries (packages "scanner", "parser", "ast", and so on.) There's also a smaller, simpler parser in the "text/template/parse" package, that is used to parse the templating languages in "text/template" and "html/template". As an introduction to it, I recommend the talk "Lexical Scanning in Go" by Rob Pike: ▶ this video
Wow, perfect timing! I'm currently writing my first lexer/parser in D as well ( link ) for a Scheme-like language used in Halo 3. I found Rob Pike's talk on lexical scanning to be pretty useful ( ▶ this video ) and I've modeled mine pretty heavily after the text/template lexer: link .
I thought this would be a good opportunity to use 'state functions' to implement a shell for Bytengine. Rob Pike mentions the use of state functions in his talk "Lexical Scanning in Go" ▶ this video
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] ▶ this video
For those who don't know who Rob Pike is, he's pretty awesome, helped create UTF-8 among other things, and now works on Go. link He has given some really great Go talks which are available on youtube, about an hour each: Origins of Go Concurrency Style - link Lexical Scanning in Go - ▶ this video Go Concurrency Patterns (One of my favorites) - link
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] ▶ this video
> 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: ▶ this video
type state struct { // add any fields you need to persist here } type transition func(*state) transition same as in Lexical Scanning in Go ( ▶ this video )
> 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 ▶ this video .
Check out the std lib: link -- that's canonical Go code. It's my language of choice for personal projects. A neat and compact language that is very trivial to pick up, feels light, and yet sufficiently subtle to intellectually engage your mind. Very productive, good performance, and very portable. ▶ this video caveat: /imho/ the runtime is not yet fully cooked. ETA is Go1.1 (end of year I believe) for beefed up internals.
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: ▶ this video
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. ▶ this video