aboutsummaryrefslogtreecommitdiff
path: root/src/pkg/text/template/parse
diff options
context:
space:
mode:
authorRob Pike <r@golang.org>2012-06-01 18:34:14 -0700
committerRob Pike <r@golang.org>2012-06-01 18:34:14 -0700
commit0e45890c8bafbaeed18c22f462d5435e43705264 (patch)
treea98121ba26861e74805dab14a7d41d1e2c9f966d /src/pkg/text/template/parse
parenta04d4f02a4ff68e0ef7a222d6e301225877ded90 (diff)
downloadgo-0e45890c8bafbaeed18c22f462d5435e43705264.tar.xz
text/template/parse: restore the goroutine
To avoid goroutines during init, the nextItem function was a clever workaround. Now that init goroutines are permitted, restore the original, simpler design. R=golang-dev, bradfitz CC=golang-dev https://golang.org/cl/6282043
Diffstat (limited to 'src/pkg/text/template/parse')
-rw-r--r--src/pkg/text/template/parse/lex.go23
1 files changed, 11 insertions, 12 deletions
diff --git a/src/pkg/text/template/parse/lex.go b/src/pkg/text/template/parse/lex.go
index 1cf4d739c4..62bf6d2009 100644
--- a/src/pkg/text/template/parse/lex.go
+++ b/src/pkg/text/template/parse/lex.go
@@ -195,15 +195,7 @@ func (l *lexer) errorf(format string, args ...interface{}) stateFn {
// nextItem returns the next item from the input.
func (l *lexer) nextItem() item {
- for {
- select {
- case item := <-l.items:
- return item
- default:
- l.state = l.state(l)
- }
- }
- panic("not reached")
+ return <-l.items
}
// lex creates a new scanner for the input string.
@@ -219,12 +211,19 @@ func lex(name, input, left, right string) *lexer {
input: input,
leftDelim: left,
rightDelim: right,
- state: lexText,
- items: make(chan item, 2), // Two items of buffering is sufficient for all state functions
+ items: make(chan item),
}
+ go l.run()
return l
}
+// run runs the state machine for the lexer.
+func (l *lexer) run() {
+ for l.state = lexText; l.state != nil; {
+ l.state = l.state(l)
+ }
+}
+
// state functions
const (
@@ -391,7 +390,7 @@ func (l *lexer) atTerminator() bool {
}
// lexChar scans a character constant. The initial quote is already
-// scanned. Syntax checking is done by the parse.
+// scanned. Syntax checking is done by the parser.
func lexChar(l *lexer) stateFn {
Loop:
for {