diff options
author | Ondřej Surý <ondrej@sury.org> | 2011-04-26 09:55:32 +0200 |
---|---|---|
committer | Ondřej Surý <ondrej@sury.org> | 2011-04-26 09:55:32 +0200 |
commit | 7b15ed9ef455b6b66c6b376898a88aef5d6a9970 (patch) | |
tree | 3ef530baa80cdf29436ba981f5783be6b4d2202b /src/pkg/go/token/token.go | |
parent | 50104cc32a498f7517a51c8dc93106c51c7a54b4 (diff) | |
download | golang-7b15ed9ef455b6b66c6b376898a88aef5d6a9970.tar.gz |
Imported Upstream version 2011.04.13upstream/2011.04.13
Diffstat (limited to 'src/pkg/go/token/token.go')
-rw-r--r-- | src/pkg/go/token/token.go | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/src/pkg/go/token/token.go b/src/pkg/go/token/token.go index 2a2d3ecc4..a5f21df16 100644 --- a/src/pkg/go/token/token.go +++ b/src/pkg/go/token/token.go @@ -126,10 +126,7 @@ const ( ) -// At the moment we have no array literal syntax that lets us describe -// the index for each element - use a map for now to make sure they are -// in sync. -var tokens = map[Token]string{ +var tokens = [...]string{ ILLEGAL: "ILLEGAL", EOF: "EOF", @@ -237,10 +234,14 @@ var tokens = map[Token]string{ // constant name (e.g. for the token IDENT, the string is "IDENT"). // func (tok Token) String() string { - if str, exists := tokens[tok]; exists { - return str + s := "" + if 0 <= tok && tok < Token(len(tokens)) { + s = tokens[tok] } - return "token(" + strconv.Itoa(int(tok)) + ")" + if s == "" { + s = "token(" + strconv.Itoa(int(tok)) + ")" + } + return s } |