3 ms·
> 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 (http
by jbarham 14y ago
> 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 (http://golang.org/pkg/text/template/ http://golang.org/pkg/text/template/).
See the source lexer source code at http://golang.org/src/pkg/text/template/parse/lex.go http://golang.org/src/pkg/text/template/parse/lex.go and note that stateFn is defined recursively.
There's a video by Pike describing how he built the parser at http://www.youtube.com/watch?v=HxaD_trXwRE http://www.youtube.com/watch?v=HxaD_trXwRE.