summaryrefslogtreecommitdiff
path: root/src/text/template/parse/node.go
Commit message (Collapse)AuthorAgeFilesLines
* text/template: add CommentNode to template parse treeAriel Mashraki2020-08-281-0/+33
| | | | | | | | | | Fixes #34652 Change-Id: Icf6e3eda593fed826736f34f95a9d66f5450cc98 Reviewed-on: https://go-review.googlesource.com/c/go/+/229398 Reviewed-by: Daniel Martí <mvdan@mvdan.cc> Run-TryBot: Daniel Martí <mvdan@mvdan.cc> TryBot-Result: Gobot Gobot <gobot@golang.org>
* text/template: fix lint typo in VariableNode docMacks2020-06-231-1/+1
| | | | | | | | Change-Id: I68b8c782478aa3e7adbd36a2de1c20b04e8c395b GitHub-Last-Rev: 50f27197837e57e1d68b8905eaa66ea142bd45fc GitHub-Pull-Request: golang/go#39622 Reviewed-on: https://go-review.googlesource.com/c/go/+/239383 Reviewed-by: Rob Pike <r@golang.org>
* text/template/parse: speed up nodes printingAriel Mashraki2019-10-031-19/+110
| | | | | | | | | | | | | | | | | | | | | | | | | | This CL is a follow up for 198080. Added a private writeTo method to the Node interface, in order to use the same builder for printing all nodes in the tree. Benchmark output against master: benchmark old ns/op new ns/op delta BenchmarkParseLarge-8 24594994 25292054 +2.83% BenchmarkVariableString-8 117 118 +0.85% BenchmarkListString-8 10475 3353 -67.99% benchmark old allocs new allocs delta BenchmarkVariableString-8 3 3 +0.00% BenchmarkListString-8 149 31 -79.19% benchmark old bytes new bytes delta BenchmarkVariableString-8 72 72 +0.00% BenchmarkListString-8 5698 1608 -71.78% Change-Id: I2b1cf07cda65c1b80083fb99671289423700feba Reviewed-on: https://go-review.googlesource.com/c/go/+/198278 Reviewed-by: Rob Pike <r@golang.org> Run-TryBot: Rob Pike <r@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
* text/template/parse: use strings.Builder in Chain and List nodesAriel Mashraki2019-10-011-8/+12
| | | | | | | | | | | | | | | | | | | | | | | This CL is a continuation of 198078. Benchmark output: benchmark old ns/op new ns/op delta BenchmarkParseLarge-8 24759165 24516563 -0.98% BenchmarkVariableString-8 115 115 +0.00% BenchmarkListString-8 924 680 -26.41% benchmark old allocs new allocs delta BenchmarkVariableString-8 3 3 +0.00% BenchmarkListString-8 14 13 -7.14% benchmark old bytes new bytes delta BenchmarkVariableString-8 72 72 +0.00% BenchmarkListString-8 512 424 -17.19% Change-Id: I9ec48fe4832437c556a5fa94d4cbf6e29e28d944 Reviewed-on: https://go-review.googlesource.com/c/go/+/198080 Reviewed-by: Emmanuel Odeke <emm.odeke@gmail.com> Run-TryBot: Emmanuel Odeke <emm.odeke@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org>
* text/template/parse: use strings.Builder in String methodsAriel Mashraki2019-10-011-19/+22
| | | | | | | | | | | | | | | | | | | | | | As mentioned in godoc, strings.Builder is more efficient for concatenating and building strings. Running a simple bench test on VariableNode.String() gives: benchmark old ns/op new ns/op delta BenchmarkParseLarge-8 25676831 24453285 -4.77% BenchmarkVariableString-8 296 115 -61.15% benchmark old allocs new allocs delta BenchmarkVariableString-8 8 3 -62.50% benchmark old bytes new bytes delta BenchmarkVariableString-8 112 72 -35.71% Change-Id: I13c9340080738fcad1edeed859d33ba608e4b05a Reviewed-on: https://go-review.googlesource.com/c/go/+/198078 Reviewed-by: Emmanuel Odeke <emm.odeke@gmail.com> Run-TryBot: Emmanuel Odeke <emm.odeke@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org>
* text/template: further simplify building the vars listRob Pike2019-10-011-3/+3
| | | | | | | | | | | | Followup to https://golang.org/cl/197997 If you know the number of elements, you don't need append at all. Either use append to grow, or allocate and index. Here we choose number 2. Change-Id: Ic58637231789640ff7b293ece04a95a8de7ccf8f Reviewed-on: https://go-review.googlesource.com/c/go/+/198097 Reviewed-by: Ian Lance Taylor <iant@golang.org>
* text/template/parse: specify slice capacity in Pipenode.CopyPipe()Pantelis Sampaziotis2019-09-301-1/+1
| | | | | | | | | | The required vars slice capacity is known so it can be specified before appending. Change-Id: Ifa2fe97602e84198c4d01e5a1b0529f3f65f2df1 GitHub-Last-Rev: a0580df208a1d498968138d63508ae4e30df2ec5 GitHub-Pull-Request: golang/go#34613 Reviewed-on: https://go-review.googlesource.com/c/go/+/197997 Reviewed-by: Andrew Bonventre <andybons@golang.org>
* text/template: accept new number syntaxRuss Cox2019-02-261-1/+1
| | | | | | | | | | | | | | | | | | | | | This CL updates text/template's scanner to accept the new number syntaxes: - Hexadecimal floating-point values. - Digit-separating underscores. - Leading 0b and 0o prefixes. See golang.org/design/19308-number-literals for background. For #12711. For #19308. For #28493. For #29008. Change-Id: I68c16ea35c3f506701063781388de72bafee6b8d Reviewed-on: https://go-review.googlesource.com/c/160248 Reviewed-by: Rob Pike <r@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
* text/template/parse: undo breaking API changesDaniel Theophanes2018-06-221-20/+20
| | | | | | | | | | | | | | | | | golang.org/cl/84480 altered the API for the parse package for clarity and consistency. However, the changes also broke the API for consumers of the package. This CL reverts the API to the previous spelling, adding only a single new exported symbol. Fixes #25968 Change-Id: Ieb81054b61eeac7df3bc3864ef446df43c26b80f Reviewed-on: https://go-review.googlesource.com/120355 Reviewed-by: Daniel Martí <mvdan@mvdan.cc> Reviewed-by: Rob Pike <r@golang.org> Run-TryBot: Daniel Martí <mvdan@mvdan.cc> TryBot-Result: Gobot Gobot <gobot@golang.org>
* text/template: copy Decl field when copying PipeNodeIan Lance Taylor2018-04-101-0/+1
| | | | | | | | | | Fixes #24791 Change-Id: I62ac17313e6e09796586911d88191a36d67f9aa1 Reviewed-on: https://go-review.googlesource.com/106115 Run-TryBot: Ian Lance Taylor <iant@golang.org> Reviewed-by: Daniel Martí <mvdan@mvdan.cc> TryBot-Result: Gobot Gobot <gobot@golang.org>
* text/template: add variable assignmentsDaniel Martí2018-04-041-19/+20
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Variables can be declared and shadowing is supported, but modifying existing variables via assignments was not available. This meant that modifying a variable from a nested block was not possible: {{ $v := "init" }} {{ if true }} {{ $v := "changed" }} {{ end }} v: {{ $v }} {{/* "init" */}} Introduce the "=" assignment token, such that one can now do: {{ $v := "init" }} {{ if true }} {{ $v = "changed" }} {{ end }} v: {{ $v }} {{/* "changed" */}} To avoid confusion, rename PipeNode.Decl to PipeNode.Vars, as the variables may not always be declared after this change. Also change a few other names to better reflect the added ambiguity of variables in pipelines. Modifying the text/template/parse package in a backwards incompatible manner is acceptable, given that the package godoc clearly states that it isn't intended for general use. It's the equivalent of an internal package, back when internal packages didn't exist yet. To make the changes to the parse package sit well with the cmd/api test, update except.txt with the changes that we aren't worried about. Fixes #10608. Change-Id: I1f83a4297ee093fd45f9993cebb78fc9a9e81295 Reviewed-on: https://go-review.googlesource.com/84480 Run-TryBot: Daniel Martí <mvdan@mvdan.cc> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Rob Pike <r@golang.org>
* text/template: revert CL 66410 "add break, continue actions in ranges"Ian Lance Taylor2018-02-061-64/+0
| | | | | | | | | | | | | | | | | | | | | | | | | The new break and continue actions do not work in html/template, and fixing them requires thinking about security issues that seem too tricky at this stage of the release. We will try again for 1.11. Original CL description: text/template: add break, continue actions in ranges Adds the two range control actions "break" and "continue". They act the same as the Go keywords break and continue, but are simplified in that only the innermost range statement can be broken out of or continued. Fixes #20531 Updates #20531 Updates #23683 Change-Id: Ia7fd3c409163e3bcb5dc42947ae90b15bdf89853 Reviewed-on: https://go-review.googlesource.com/92155 Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Russ Cox <rsc@golang.org>
* text/template: add break, continue actions in rangesTim Cooper2017-10-171-0/+64
| | | | | | | | | | | | Adds the two range control actions "break" and "continue". They act the same as the Go keywords break and continue, but are simplified in that only the innermost range statement can be broken out of or continued. Fixes #20531 Change-Id: I4412b3bbfd4dadb0ab74ae718e308c1ac7a0a1e9 Reviewed-on: https://go-review.googlesource.com/66410 Reviewed-by: Rob Pike <r@golang.org>
* all: switch to the new deprecation conventionShenghou Ma2015-06-181-5/+5
| | | | | | | | | While we're at it, move some misplaced comment blocks around. Change-Id: I1847d7f1ca1dbb8e5de737203c4ed6c66e112508 Reviewed-on: https://go-review.googlesource.com/10188 Reviewed-by: Rob Pike <r@golang.org> Reviewed-by: Russ Cox <rsc@golang.org>
* text/template/parse: huge integers are not floatsRob Pike2015-05-031-0/+5
| | | | | | | | | | | | | | | Ideal constants in the template package are a little different from Go. This is a case that slipped through the cracks: A huge integer number was accepted as a floating-point number, but this loses precision and is confusing. Also, the code in the template package (as opposed to the parse package) wasn't expecting it. Root this out at the source: If an integer doesn't fit an int64 or uint64, complain right away. Change-Id: I375621e6f5333c4d53f053a3c84a9af051711b7a Reviewed-on: https://go-review.googlesource.com/9651 Reviewed-by: Russ Cox <rsc@golang.org>
* build: move package sources from src/pkg to srcRuss Cox2014-09-081-0/+834
Preparation was in CL 134570043. This CL contains only the effect of 'hg mv src/pkg/* src'. For more about the move, see golang.org/s/go14nopkg.