aboutsummaryrefslogtreecommitdiff
path: root/src/pkg/text
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
2014-08-13text/scanner: improve documentationRobert Griesemer
LGTM=r R=r CC=golang-codereviews https://golang.org/cl/123390043
2014-06-17text/scanner: fix commentRobert Griesemer
LGTM=bradfitz R=golang-codereviews, bradfitz CC=golang-codereviews https://golang.org/cl/105300044
2014-06-16text/scanner: provide facility for custom identifiersRobert Griesemer
LGTM=r R=golang-codereviews, r CC=golang-codereviews https://golang.org/cl/108030044
2014-05-19text/template,html/template: document that partial results may be written on ↵Rob Pike
error Fixes #7445. LGTM=bradfitz R=golang-codereviews, bradfitz CC=golang-codereviews https://golang.org/cl/94640043
2014-04-15text/template: say more often that templates are safe for parallel executionRob Pike
It was said already but apparently not enough times. Fixes #6985. LGTM=crawshaw R=golang-codereviews, crawshaw CC=golang-codereviews https://golang.org/cl/86300043
2014-03-21text/scanner: handle non-io.EOF errorsRui Ueyama
Currently Scan ignores an error returned from source if the number of bytes source has read is 0. Fixes #7594. LGTM=gri R=golang-codereviews, bradfitz, gri CC=golang-codereviews https://golang.org/cl/78120043
2014-02-14text/template: don't panic when function call evaluates a nil pointerRob Pike
Catch the error instead and return it to the user. Before this fix, the template package panicked. Now you get: template: bug11:1:14: executing "bug11" at <.PS>: dereference of nil pointer of type *string Extended example at http://play.golang.org/p/uP6pCW3qKT Fixes #7333. LGTM=rsc R=rsc CC=golang-codereviews https://golang.org/cl/64150043
2014-02-04text/tabwriter: improve panic backtracesJosh Bleecher Snyder
Fixes #7117. LGTM=gri R=golang-codereviews, gobot, gri CC=golang-codereviews https://golang.org/cl/53310044
2014-01-27all: use {bytes,strings}.NewReader instead of bytes.BuffersBrad Fitzpatrick
Use the smaller read-only bytes.NewReader/strings.NewReader instead of a bytes.Buffer when possible. LGTM=r R=golang-codereviews, r CC=golang-codereviews https://golang.org/cl/54660045
2013-12-30text/template: don't panic when using AddParseTree with an unparsed templateJosh Bleecher Snyder
Fixes #7032. R=golang-codereviews, r CC=golang-codereviews https://golang.org/cl/43960045
2013-12-12net, text/tabwriter: use cap arg to makeJosh Bleecher Snyder
Changes generated by: gofmt -w -r 'make(a, b)[0:0] -> make(a, 0, b)' src/pkg R=golang-dev, bradfitz CC=golang-dev https://golang.org/cl/24820045
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-09-04text/template: allow eq to take more than two argumentsRob Pike
Based on an old suggestion by rsc, it compares the second and following arguments to the first. Unfortunately the code cannot be as pretty as rsc's original because it doesn't require identical types. R=golang-dev, dsymonds, adg CC=golang-dev https://golang.org/cl/13509046
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-27text/template: make the escapers for HTML etc. handle pointers correctlyRob Pike
Apply the same rules for argument evaluation and indirection that are used by the regular evaluator. Fixes #5802 R=golang-dev, dsymonds CC=golang-dev https://golang.org/cl/13257043
2013-08-21text/template: implement comparison of basic typesRob Pike
Add eq, lt, etc. to allow one to do simple comparisons. It's basic types only (booleans, integers, unsigned integers, floats, complex, string) because that's easy, easy to define, and covers the great majority of useful cases, while leaving open the possibility of a more sweeping definition later. {{if eq .X .Y}}X and Y are equal{{else}}X and Y are unequal{{end}} R=golang-dev, adg CC=golang-dev https://golang.org/cl/13091045
2013-08-13text/template: Make function call builtin handle nil errors correctlyElias Naur
The call builtin unconditionally tries to convert a second return value from a function to the error type. This fails in case nil is returned, effectively making call useless for functions returning two values. This CL adds a nil check for the second return value, and adds a test. Note that for regular function and method calls the nil error case is handled correctly and is verified by a test. R=r CC=golang-dev https://golang.org/cl/12804043
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-07-31text/template: fix type of ComplexZero in testRob Pike
Was stupidly float64; should be complex128. The tests still pass. Fixes #5649. R=golang-dev, rsc CC=golang-dev https://golang.org/cl/12107044
2013-07-23all: be more idiomatic when documenting boolean return values.Rob Pike
Phrases like "returns whether or not the image is opaque" could be describing what the function does (it always returns, regardless of the opacity) or what it returns (a boolean indicating the opacity). Even when the "or not" is missing, the phrasing is bizarre. Go with "reports whether", which is still clunky but at least makes it clear we're talking about the return value. These were edited by hand. A few were cleaned up in other ways. R=golang-dev, dsymonds CC=golang-dev https://golang.org/cl/11699043
2013-05-03text/template: comment fixKeith Randall
R=golang-dev, minux.ma, r CC=golang-dev https://golang.org/cl/9086043
2013-03-27text/template: fix bug in evaluating a chain starting with a function.Rob Pike
R=golang-dev, alberto.garcia.hierro CC=golang-dev https://golang.org/cl/7861046
2013-03-22build: remove dead codeRuss Cox
R=golang-dev, r CC=golang-dev https://golang.org/cl/7877045
2013-03-08text/template: revert minor change to Name methodRob Pike
For better printing, I recently changed Name to return "<unnamed>" for templates with empty names, but this causes trouble for the many packages that used "" as the template name, so restore the old behavior. It's usually printed as a quoted string anyway, so it should be fine. R=golang-dev, dsymonds CC=golang-dev https://golang.org/cl/7577044
2013-03-06text/template: improve error reporting for executing an empty templateRob Pike
Fixes #4522. R=golang-dev, rsc CC=golang-dev https://golang.org/cl/7502044
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
2013-01-12text/template: Document that range can be used on chan types.Kamil Kisiel
Fixes #4640. R=golang-dev, adg CC=golang-dev https://golang.org/cl/7082044
2012-10-30gofmt: apply gofmt -w src miscRobert Griesemer
Remove trailing whitespace in comments. No other changes. R=r CC=golang-dev https://golang.org/cl/6815053
2012-10-07text/template: fix nil crash on TemplatesRob Pike
Fixes #3872. R=golang-dev, rsc CC=golang-dev https://golang.org/cl/6612060
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-09-07text/scanner: skip first character if it's a BOMRobert Griesemer
R=r CC=golang-dev https://golang.org/cl/6493097
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-15text/scanner: report illegal hexadecimal numbers (bug fix)Robert Griesemer
R=r CC=golang-dev https://golang.org/cl/6450136
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