mirror of
https://github.com/golang/go
synced 2024-11-22 01:34:41 -07:00
go/token: use array instead of map for token->string table
R=rsc CC=golang-dev https://golang.org/cl/4284070
This commit is contained in:
parent
0caa0c0923
commit
2796ac1466
@ -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
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user