aboutsummaryrefslogtreecommitdiff
path: root/src/pkg/text/template/parse/parse.go
AgeCommit message (Collapse)Author
2014-09-08build: move package sources from src/pkg to srcRuss Cox
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.
2014-08-29text/template: add back pointer to Nodes for better error generationRob Pike
ErrorContext now has all the information it needs from the Node, rather than depending on the template that contains it. This makes it easier for html/template to generate correct locations in its error messages. Updated html/template to use this ability where it is easy, which is not everywhere, but more work can probably push it through. Fixes #8577. LGTM=adg R=golang-codereviews, adg CC=golang-codereviews https://golang.org/cl/130620043
2013-09-17text/template/parse, html/template: copy Tree.text during html template cloneJosh Bleecher Snyder
The root cause of the panic reported in https://code.google.com/p/go/issues/detail?id=5980 is that parse's Tree.Text wasn't being copied during the clone. Fix this by adding and using a Copy method for parse.Tree. Fixes #5980. R=golang-dev, r CC=golang-dev https://golang.org/cl/12420044
2013-08-28text/template: allow {{else if ... }} to simplify if chainsRob Pike
The method is simple: the parser just parses {{if A}}a{{else if B}}b{{end}} to the same tree that would be produced by {{if A}}a{{else}}{{if B}}b{{end}}{{end}} Thus no changes are required in text/template itself or in html/template, only in text/template/parse. Fixes #6085 R=golang-dev, adg CC=golang-dev https://golang.org/cl/13327043
2013-08-03various: deleted unused itemsRob Pike
R=golang-dev, dsymonds CC=golang-dev https://golang.org/cl/12396043
2013-03-22build: remove dead codeRuss Cox
R=golang-dev, r CC=golang-dev https://golang.org/cl/7877045
2013-03-05text/template/parse: remove self-assignment.David Symonds
R=golang-dev, adg CC=golang-dev https://golang.org/cl/7431054
2013-01-22text/template/parse: don't show itemType in error messagesShenghou Ma
so that the user don't need to decipher something like this: template: main:1: expected %!s(parse.itemType=14) in end; got "|" now they get this: template: main:1: unexpected "|" in end R=golang-dev, r CC=golang-dev https://golang.org/cl/7128054
2012-10-03text/template: better error messages during execution,Rob Pike
They now show the correct name, the byte offset on the line, and context for the failed evaluation. Before: template: three:7: error calling index: index out of range: 5 After: template: top:7:20: executing "three" at <index "hi" $>: error calling index: index out of range: 5 Here top is the template that was parsed to create the set, and the error appears with the action starting at byte 20 of line 7 of "top", inside the template called "three", evaluating the expression <index "hi" $>. Also fix a bug in index: it didn't work on strings. Ouch. Also fix bug in error for index: was showing type of index not slice. The real previous error was: template: three:7: error calling index: can't index item of type int The html/template package's errors can be improved by building on this; I'll do that in a separate pass. Extends the API for text/template/parse but only by addition of a field and method. The old API still works. Fixes #3188. R=golang-dev, dsymonds CC=golang-dev https://golang.org/cl/6576058
2012-09-24text/template: allow .Field access to parenthesized expressionsRob Pike
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
2012-09-14text/template: towards better errorsRob Pike
Give the right name for errors, and add a test to check we're getting the errors we expect. Also fix an ordering bug (calling add after stopParse) that caused a nil indirection rather than a helpful error. Fixes #3280. R=golang-dev, adg CC=golang-dev https://golang.org/cl/6520043
2012-08-29text/template: make spaces significantRob Pike
Other than catching an error case that was missed before, this CL introduces no changes to the template language or API. For simplicity, templates use spaces as argument separators. This means that spaces are significant: .x .y is not the same as .x.y. In the existing code, these cases are discriminated by the lexer, but that means for instance that (a b).x cannot be distinguished from (a b) .x, which is lousy. Although that syntax is not supported yet, we want to support it and this CL is a necessary step. This CL emits a "space" token (actually a run of spaces) from the lexer so the parser can discriminate these cases. It therefore fixes a couple of undisclosed bugs ("hi".x is now an error) but doesn't otherwise change the language. Later CLs will amend the grammar to make .X a proper operator. There is one unpleasantness: With space a token, three-token lookahead is now required when parsing variable declarations to discriminate them from plain variable references. Otherwise the change isn't bad. The CL also moves the debugging print code out of the lexer into the test, which is the only place it's needed or useful. Step towards resolving issue 3999. It still remains to move field chaining out of the lexer and into the parser and make field access an operator. R=golang-dev, dsymonds CC=golang-dev https://golang.org/cl/6492054
2012-08-24text/template: allow grouping of pipelines using parenthesesRob Pike
Based on work by Russ Cox. From his CL: This is generally useful but especially helpful when trying to use the built-in boolean operators. It lets you write: {{if not (f 1)}} foo {{end}} {{if and (f 1) (g 2)}} bar {{end}} {{if or (f 1) (g 2)}} quux {{end}} instead of {{if f 1 | not}} foo {{end}} {{if f 1}}{{if g 2}} bar {{end}}{{end}} {{$do := 0}}{{if f 1}}{{$do := 1}}{{else if g 2}}{{$do := 1}}{{end}}{{if $do}} quux {{end}} The result can be a bit LISPy but the benefit in expressiveness and readability for such a small change justifies it. I believe no changes are required to html/template. Fixes #3276. R=golang-dev, adg, rogpeppe, minux.ma CC=golang-dev https://golang.org/cl/6482056
2012-08-08text/template: add 'nil' as a keyword in the languageRob Pike
The keyword reprents an untyped nil and is useful for passing nil values to methods and functions. The nil will be promoted to the appropriate type when used; if a type cannot be assigned, an error results. R=rsc, dsymonds CC=golang-dev https://golang.org/cl/6459056
2012-04-23text/template: detect unexported fields betterRob Pike
Moves the error detection back into execution, where it used to be, and improves the error message. Rolls back most of 6009048, which broke lower-case keys in maps. If it weren't for maps we could detect this at compile time rather than execution time. Fixes #3542. R=golang-dev, dsymonds CC=golang-dev https://golang.org/cl/6098051
2012-04-15text/template/parse: fix doc commentShenghou Ma
Fixes #3529. R=golang-dev, r CC=golang-dev https://golang.org/cl/6037046
2012-04-12text/template: catch unexported fields during parseRob Pike
It's a common error to reference unexported field names in templates, especially for newcomers. This catches the error at parse time rather than execute time so the rare few who check errors will notice right away. These were always an error, so the net behavior is unchanged. Should break no existing code, just identify the error earlier. R=golang-dev, dsymonds CC=golang-dev https://golang.org/cl/6009048
2012-03-14text/template: fix a couple of parse bugs around identifiers.Rob Pike
1) Poor error checking in variable declarations admitted $x=2 or even $x%2. 2) Need white space or suitable termination character after identifiers, so $x+2 doesn't parse, in case we want it to mean something one day. Number 2 in particular prevents mistakes that we will have to honor later and so is necessary for Go 1. Fixes #3270. Fixes #3271. R=golang-dev, rsc CC=golang-dev https://golang.org/cl/5795073
2012-02-28text/template: fix redefinition bugsRob Pike
R=golang-dev, adg CC=golang-dev https://golang.org/cl/5696087
2012-02-19templates: minor edits to the documentationRob Pike
R=golang-dev, rsc CC=golang-dev https://golang.org/cl/5677084
2011-12-01template: move the empty check into parse, which needs it when constructingRob Pike
tree sets. R=golang-dev, gri CC=golang-dev https://golang.org/cl/5449062
2011-11-28text/template: address a couple of issues for html/templateRob Pike
- allow Lookup to work on uninitialized templates - fix bug in add: can't error after parser is stopped - add Add method for html/template R=adg, rogpeppe, r, rsc CC=golang-dev https://golang.org/cl/5436080
2011-11-23text/template: new, simpler APIRob Pike
The Set type is gone. Instead, templates are automatically associated by being parsed together; nested definitions implicitly create associations. Only associated templates can invoke one another. This approach dramatically reduces the breadth of the construction API. For now, html/template is deleted from src/pkg/Makefile, so this can be checked in. Nothing in the tree depends on it. It will be updated next. R=dsymonds, adg, rsc, r, gri, mikesamuel, nigeltao CC=golang-dev https://golang.org/cl/5415060
2011-11-18template/parse: rename Set to ParseRob Pike
Preamble to the simplification of the template API. Although the signature of Parse (nee Set) changes, it's really an internal function, used only by text/template. R=golang-dev, rsc, gri, r CC=golang-dev https://golang.org/cl/5415052
2011-11-17text/template: refactor set parsingRob Pike
Parse {{define}} blocks during template parsing rather than separately as a set-specific thing. This cleans up set parse significantly, and enables the next step, if we want, to unify the API for templates and sets. Other than an argument change to parse.Parse, which is in effect an internal function and unused by client code, there is no API change and no spec change yet. R=golang-dev, rsc, r CC=golang-dev https://golang.org/cl/5393049
2011-11-03os,text,unicode: renamingsRob Pike
This is Go 1 package renaming CL #4. This one merely moves the source; the import strings will be changed after the next weekly release. This one moves pieces into os, text, and unicode. exec -> os/exec scanner -> text/scanner tabwriter -> text/tabwriter template -> text/template template/parse -> text/template/parse utf16 -> unicode/utf16 utf8 -> unicode/utf8 This should be the last of the source-rearranging CLs. R=golang-dev, rsc CC=golang-dev https://golang.org/cl/5331066