Commit 2796ac14 authored by Robert Griesemer's avatar Robert Griesemer

go/token: use array instead of map for token->string table

R=rsc
CC=golang-dev
https://golang.org/cl/4284070
parent 0caa0c09
...@@ -126,10 +126,7 @@ const ( ...@@ -126,10 +126,7 @@ const (
) )
// At the moment we have no array literal syntax that lets us describe var tokens = [...]string{
// the index for each element - use a map for now to make sure they are
// in sync.
var tokens = map[Token]string{
ILLEGAL: "ILLEGAL", ILLEGAL: "ILLEGAL",
EOF: "EOF", EOF: "EOF",
...@@ -237,10 +234,14 @@ var tokens = map[Token]string{ ...@@ -237,10 +234,14 @@ var tokens = map[Token]string{
// constant name (e.g. for the token IDENT, the string is "IDENT"). // constant name (e.g. for the token IDENT, the string is "IDENT").
// //
func (tok Token) String() string { func (tok Token) String() string {
if str, exists := tokens[tok]; exists { s := ""
return str 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
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment