Reviewers:
golang-dev_googlegroups.com,
Message:
Hello
golan...@googlegroups.com,
I'd like you to review this change to
https://go.googlecode.com/hg/
Description:
text/template/parse: move itemType.String from test code into real code.
itemType is used in a few places to report errors to users of
text/template.
Without String you get errors such as
template: :96: expected %!s(parse.itemType=14) in else; got "/"
With String you get
template: :96: expected right delim in else; got "/"
Please review this at
https://codereview.appspot.com/7191045/
Affected files:
M src/pkg/text/template/parse/lex.go
M src/pkg/text/template/parse/lex_test.go
Index: src/pkg/text/template/parse/lex.go
===================================================================
--- a/src/pkg/text/template/parse/lex.go
+++ b/src/pkg/text/template/parse/lex.go
@@ -81,6 +81,48 @@
"with": itemWith,
}
+// Make the types prettyprint.
+var itemName = map[itemType]string{
+ itemError: "error",
+ itemBool: "bool",
+ itemChar: "char",
+ itemCharConstant: "charconst",
+ itemComplex: "complex",
+ itemColonEquals: ":=",
+ itemEOF: "EOF",
+ itemField: "field",
+ itemIdentifier: "identifier",
+ itemLeftDelim: "left delim",
+ itemLeftParen: "(",
+ itemNumber: "number",
+ itemPipe: "pipe",
+ itemRawString: "raw string",
+ itemRightDelim: "right delim",
+ itemRightParen: ")",
+ itemSpace: "space",
+ itemString: "string",
+ itemVariable: "variable",
+
+ // keywords
+ itemDot: ".",
+ itemDefine: "define",
+ itemElse: "else",
+ itemIf: "if",
+ itemEnd: "end",
+ itemNil: "nil",
+ itemRange: "range",
+ itemTemplate: "template",
+ itemWith: "with",
+}
+
+func (i itemType) String() string {
+ s := itemName[i]
+ if s == "" {
+ return fmt.Sprintf("item%d", int(i))
+ }
+ return s
+}
+
const eof = -1
// stateFn represents the state of the scanner as a function that returns
the next state.
Index: src/pkg/text/template/parse/lex_test.go
===================================================================
--- a/src/pkg/text/template/parse/lex_test.go
+++ b/src/pkg/text/template/parse/lex_test.go
@@ -5,52 +5,9 @@
package parse
import (
- "fmt"
"testing"
)
-// Make the types prettyprint.
-var itemName = map[itemType]string{
- itemError: "error",
- itemBool: "bool",
- itemChar: "char",
- itemCharConstant: "charconst",
- itemComplex: "complex",
- itemColonEquals: ":=",
- itemEOF: "EOF",
- itemField: "field",
- itemIdentifier: "identifier",
- itemLeftDelim: "left delim",
- itemLeftParen: "(",
- itemNumber: "number",
- itemPipe: "pipe",
- itemRawString: "raw string",
- itemRightDelim: "right delim",
- itemRightParen: ")",
- itemSpace: "space",
- itemString: "string",
- itemVariable: "variable",
-
- // keywords
- itemDot: ".",
- itemDefine: "define",
- itemElse: "else",
- itemIf: "if",
- itemEnd: "end",
- itemNil: "nil",
- itemRange: "range",
- itemTemplate: "template",
- itemWith: "with",
-}
-
-func (i itemType) String() string {
- s := itemName[i]
- if s == "" {
- return fmt.Sprintf("item%d", int(i))
- }
- return s
-}
-
type lexTest struct {
name string
input string