mirror of https://github.com/golang/go.git
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
This commit is contained in:
parent
a04d4f02a4
commit
0e45890c8b
|
|
@ -195,15 +195,7 @@ func (l *lexer) errorf(format string, args ...interface{}) stateFn {
|
||||||
|
|
||||||
// nextItem returns the next item from the input.
|
// nextItem returns the next item from the input.
|
||||||
func (l *lexer) nextItem() item {
|
func (l *lexer) nextItem() item {
|
||||||
for {
|
return <-l.items
|
||||||
select {
|
|
||||||
case item := <-l.items:
|
|
||||||
return item
|
|
||||||
default:
|
|
||||||
l.state = l.state(l)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
panic("not reached")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// lex creates a new scanner for the input string.
|
// lex creates a new scanner for the input string.
|
||||||
|
|
@ -219,12 +211,19 @@ func lex(name, input, left, right string) *lexer {
|
||||||
input: input,
|
input: input,
|
||||||
leftDelim: left,
|
leftDelim: left,
|
||||||
rightDelim: right,
|
rightDelim: right,
|
||||||
state: lexText,
|
items: make(chan item),
|
||||||
items: make(chan item, 2), // Two items of buffering is sufficient for all state functions
|
|
||||||
}
|
}
|
||||||
|
go l.run()
|
||||||
return l
|
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
|
// state functions
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
|
@ -391,7 +390,7 @@ func (l *lexer) atTerminator() bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
// lexChar scans a character constant. The initial quote is already
|
// 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 {
|
func lexChar(l *lexer) stateFn {
|
||||||
Loop:
|
Loop:
|
||||||
for {
|
for {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue