aboutsummaryrefslogtreecommitdiff
path: root/src/pkg/text/template/parse
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-09-03text/template: 0xef is an integer, not a floating-point value.Rob Pike
The discriminator in the execution engine was stupid. Add a test to the parse package too. The problem wasn't there but the particular case ('e' in a hex integer) was not covered. Fixes #8622. LGTM=ruiu R=golang-codereviews, ruiu CC=golang-codereviews https://golang.org/cl/133530043
2014-08-29text/template/parse: restore pointer-only receivers for Type on Dot and NilRob Pike
Needless except that the api tool complains. We could fix that issue instead. TBR=bradfitz R=golang-codereviews CC=golang-codereviews https://golang.org/cl/133290043
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-09-13text/template/parse: mostly roll back the error detection for unmatched ↵Rob Pike
right delimiters It's too late to change this behavior: it breaks templates with minimized JavaScript. Makes me sad because this common error can never be caught: "{foo}}". Three cheers for compatibility. (Leave in a fix to a broken test.) R=golang-dev, dsymonds, rsc CC=golang-dev https://golang.org/cl/13689043
2013-09-12text/template: catch unmatched right delimiterRob Pike
It was simply a missing error case: when scanning plain text outside of an action, a right delimiter should be an error. R=golang-dev, dsymonds CC=golang-dev https://golang.org/cl/13468045
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-09text/template/parse: nicer error when comment ends before final delimiterRob Pike
By separating finding the end of the comment from the end of the action, we can diagnose malformed comments better. Also tweak the documentation to make the comment syntax clearer. Fixes #6022. R=golang-dev, dsymonds CC=golang-dev https://golang.org/cl/12570044
2013-08-03various: deleted unused itemsRob Pike
R=golang-dev, dsymonds CC=golang-dev https://golang.org/cl/12396043
2013-07-31text/template/parse: print TextNodes using %s not %qRob Pike
This means that printing a Node will produce output that can be used as valid input. It won't be exactly the same - some spacing may be different - but it will mean the same. Fixes #4593. R=golang-dev, dsymonds CC=golang-dev https://golang.org/cl/12006047
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-07text/template: add an unexported method to NodeRob Pike
Protects the package a little against undesirable clients. R=golang-dev, bradfitz, rsc CC=golang-dev https://golang.org/cl/6624054
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-27text/template: fix typo of errorf as error in comment.Josh Holland
R=r, minux.ma CC=gobot, golang-dev https://golang.org/cl/6506120
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: catch (A).X as a parse errorRob Pike
This shouldn't be an error (see issue 3999), but until it's handled correctly, treat it as one to avoid confusion. Without this CL, (A).X parses as two arguments. R=golang-dev, rsc CC=golang-dev https://golang.org/cl/6473059
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-09text/template/parse: fix bug handling /*/Rob Pike
Incorrect syntax for comment was erroneously accepted. Fixes #3919. R=golang-dev, rsc CC=golang-dev https://golang.org/cl/6453105
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-07-30text/template/parse/lex.go: fix typoRob Pike
R=golang-dev, bradfitz CC=golang-dev https://golang.org/cl/6448081
2012-07-30text/template/parse: fix data raceRob Pike
The situation only affects diagnostics but is easy to fix. When computing lineNumber, use the position of the last item returned by nextItem rather than the current state of the lexer. This is internal only and does not affect the API. Fixes #3886. R=golang-dev, iant CC=golang-dev https://golang.org/cl/6445061
2012-06-01text/template/parse: restore the goroutineRob Pike
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
2012-04-25all: fix errors found by go vetRob Pike
R=golang-dev, rsc CC=golang-dev https://golang.org/cl/6125044
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
2012-02-11text/template/parse: deep Copy method for nodesRob Pike
This will help html/template copy templates. R=golang-dev, gri, nigeltao, r CC=golang-dev https://golang.org/cl/5653062
2012-02-09text/template/parse: fix commentMikio Hara
R=r, rsc CC=golang-dev https://golang.org/cl/5644055
2012-01-30build: remove Make.pkg, Make.toolRuss Cox
Consequently, remove many package Makefiles, and shorten the few that remain. gomake becomes 'go tool make'. Turn off test phases of run.bash that do not work, flagged with $BROKEN. Future CLs will restore these, but this seemed like a big enough CL already. R=golang-dev, r CC=golang-dev https://golang.org/cl/5601057
2012-01-19text/template/parse: use human error printsRob Pike
The previous version of all the node.String methods printed the parse tree and was useful for developing the parse tree code. Now that that's done, we might as well print the nodes using the standard template syntax. It's much easier to read and makes error reporting look more natural. Helps issue 2644. R=rsc, n13m3y3r CC=golang-dev https://golang.org/cl/5553066
2011-12-05use new strconv APIRuss Cox
All but 3 cases (in gcimporter.go and hixie.go) are automatic conversions using gofix. No attempt is made to use the new Append functions even though there are definitely opportunities. R=golang-dev, gri CC=golang-dev https://golang.org/cl/5447069
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-08renaming_3: gofix -r go1pkgrename src/pkg/[m-z]*Rob Pike
R=rsc CC=golang-dev https://golang.org/cl/5345045
2011-11-08renaming_1: hand-edited files for go 1 renamingRob Pike
This contains the files that required handiwork, mostly Makefiles with updated TARGs, plus the two packages with modified package names. html/template/doc.go needs a separate edit pass. test/fixedbugs/bug358.go is not legal go so gofix fails on it. R=rsc CC=golang-dev https://golang.org/cl/5340050
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