diff options
| author | Brad Fitzpatrick <bradfitz@golang.org> | 2016-11-14 22:23:10 +0000 |
|---|---|---|
| committer | Brad Fitzpatrick <bradfitz@golang.org> | 2016-11-14 22:23:24 +0000 |
| commit | b83350a2e05d63eaae8da9ff4f957ab44e4cb9d9 (patch) | |
| tree | 393b98cd52778fc2a190ebdea52fbdcfd856f0f8 /src/text/template/parse/parse.go | |
| parent | 2442b49c47aa818bbc55e4c064e9ea0ca058735f (diff) | |
| download | go-b83350a2e05d63eaae8da9ff4f957ab44e4cb9d9.tar.xz | |
Revert "text/template: efficient reporting of line numbers"
This reverts commit 794fb71d9c1018c4beae1657baca5229e6a02ad0.
Reason for revert: submitted without TryBots and it broke all three race builders.
Change-Id: I80a1e566616f0ee8fa3529d4eeee04268f8a713b
Reviewed-on: https://go-review.googlesource.com/33232
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Diffstat (limited to 'src/text/template/parse/parse.go')
| -rw-r--r-- | src/text/template/parse/parse.go | 22 |
1 files changed, 10 insertions, 12 deletions
diff --git a/src/text/template/parse/parse.go b/src/text/template/parse/parse.go index 5d5c017ba9..893564b983 100644 --- a/src/text/template/parse/parse.go +++ b/src/text/template/parse/parse.go @@ -157,7 +157,7 @@ func (t *Tree) ErrorContext(n Node) (location, context string) { // errorf formats the error and terminates processing. func (t *Tree) errorf(format string, args ...interface{}) { t.Root = nil - format = fmt.Sprintf("template: %s:%d: %s", t.ParseName, t.lex.line, format) + format = fmt.Sprintf("template: %s:%d: %s", t.ParseName, t.lex.lineNumber(), format) panic(fmt.Errorf(format, args...)) } @@ -376,17 +376,15 @@ func (t *Tree) action() (n Node) { return t.withControl() } t.backup() - token := t.peek() // Do not pop variables; they persist until "end". - return t.newAction(token.pos, token.line, t.pipeline("command")) + return t.newAction(t.peek().pos, t.lex.lineNumber(), t.pipeline("command")) } // Pipeline: // declarations? command ('|' command)* func (t *Tree) pipeline(context string) (pipe *PipeNode) { var decl []*VariableNode - token := t.peekNonSpace() - pos := token.pos + pos := t.peekNonSpace().pos // Are there declarations? for { if v := t.peekNonSpace(); v.typ == itemVariable { @@ -415,7 +413,7 @@ func (t *Tree) pipeline(context string) (pipe *PipeNode) { } break } - pipe = t.newPipeline(pos, token.line, decl) + pipe = t.newPipeline(pos, t.lex.lineNumber(), decl) for { switch token := t.nextNonSpace(); token.typ { case itemRightDelim, itemRightParen: @@ -452,6 +450,7 @@ func (t *Tree) checkPipeline(pipe *PipeNode, context string) { func (t *Tree) parseControl(allowElseIf bool, context string) (pos Pos, line int, pipe *PipeNode, list, elseList *ListNode) { defer t.popVars(len(t.vars)) + line = t.lex.lineNumber() pipe = t.pipeline(context) var next Node list, next = t.itemList() @@ -480,7 +479,7 @@ func (t *Tree) parseControl(allowElseIf bool, context string) (pos Pos, line int t.errorf("expected end; found %s", next) } } - return pipe.Position(), pipe.Line, pipe, list, elseList + return pipe.Position(), line, pipe, list, elseList } // If: @@ -522,10 +521,9 @@ func (t *Tree) elseControl() Node { peek := t.peekNonSpace() if peek.typ == itemIf { // We see "{{else if ... " but in effect rewrite it to {{else}}{{if ... ". - return t.newElse(peek.pos, peek.line) + return t.newElse(peek.pos, t.lex.lineNumber()) } - token := t.expect(itemRightDelim, "else") - return t.newElse(token.pos, token.line) + return t.newElse(t.expect(itemRightDelim, "else").pos, t.lex.lineNumber()) } // Block: @@ -552,7 +550,7 @@ func (t *Tree) blockControl() Node { block.add() block.stopParse() - return t.newTemplate(token.pos, token.line, name, pipe) + return t.newTemplate(token.pos, t.lex.lineNumber(), name, pipe) } // Template: @@ -569,7 +567,7 @@ func (t *Tree) templateControl() Node { // Do not pop variables; they persist until "end". pipe = t.pipeline(context) } - return t.newTemplate(token.pos, token.line, name, pipe) + return t.newTemplate(token.pos, t.lex.lineNumber(), name, pipe) } func (t *Tree) parseTemplateName(token item, context string) (name string) { |
