diff options
| author | Rob Pike <r@golang.org> | 2012-09-24 13:23:15 +1000 |
|---|---|---|
| committer | Rob Pike <r@golang.org> | 2012-09-24 13:23:15 +1000 |
| commit | 9050550c12e2d09cf8f0c22a270cfa90120cdf6d (patch) | |
| tree | 014cb848c742805de43d7d3f5293e830af2baef6 /src/pkg/text/template/parse/parse_test.go | |
| parent | edce6349639e321c3b1a34036a8fbc08ad363cd3 (diff) | |
| download | go-9050550c12e2d09cf8f0c22a270cfa90120cdf6d.tar.xz | |
text/template: allow .Field access to parenthesized expressions
Change the grammar so that field access is a proper operator.
This introduces a new node, ChainNode, into the public (but
actually internal) API of text/template/parse. For
compatibility, we only use the new node type for the specific
construct, which was not parseable before. Therefore this
should be backward-compatible.
Before, .X.Y was a token in the lexer; this CL breaks it out
into .Y applied to .X. But for compatibility we mush them
back together before delivering. One day we might remove
that hack; it's the simple TODO in parse.go/operand.
This change also provides grammatical distinction between
f
and
(f)
which might permit function values later, but not now.
Fixes #3999.
R=golang-dev, dsymonds, gri, rsc, mikesamuel
CC=golang-dev
https://golang.org/cl/6494119
Diffstat (limited to 'src/pkg/text/template/parse/parse_test.go')
| -rw-r--r-- | src/pkg/text/template/parse/parse_test.go | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/src/pkg/text/template/parse/parse_test.go b/src/pkg/text/template/parse/parse_test.go index 4be4ca077d..0f75c33e77 100644 --- a/src/pkg/text/template/parse/parse_test.go +++ b/src/pkg/text/template/parse/parse_test.go @@ -188,6 +188,8 @@ var parseTests = []parseTest{ `{{$x := .X | .Y}}`}, {"nested pipeline", "{{.X (.Y .Z) (.A | .B .C) (.E)}}", noError, `{{.X (.Y .Z) (.A | .B .C) (.E)}}`}, + {"field applied to parentheses", "{{(.Y .Z).Field}}", noError, + `{{(.Y .Z).Field}}`}, {"simple if", "{{if .X}}hello{{end}}", noError, `{{if .X}}"hello"{{end}}`}, {"if with else", "{{if .X}}true{{else}}false{{end}}", noError, @@ -370,8 +372,9 @@ var errorTests = []parseTest{ "{{range .X}}", hasError, `unexpected EOF`}, {"variable", - "{{$a.b := 23}}", - hasError, `illegal variable in declaration`}, + // Declare $x so it's defined, to avoid that error, and then check we don't parse a declaration. + "{{$x := 23}}{{with $x.y := 3}}{{$x 23}}{{end}}", + hasError, `unexpected ":="`}, {"multidecl", "{{$a,$b,$c := 23}}", hasError, `too many declarations`}, |
