Golang go/token.Token.IsKeyword function example

package go/token

IsKeyword returns true for tokens corresponding to keywords; it returns false otherwise.

Golang go/token.Token.IsKeyword function usage example

 // getClass returns the CSS class name associated with tok.
 func (h *Highlighter) getClass(tok token.Token) string {
  switch {
  case tok.IsKeyword(): // <--- here
 return h.KeywordClass
  case tok.IsLiteral():
 if tok == token.IDENT {
 return h.IdentClass
 } else {
 return h.LiteralClass
 }
  case tok.IsOperator():
 return h.OperatorClass
  case tok == token.COMMENT:
 return h.CommentClass
  case tok == token.ILLEGAL:
 break
  default:
 panic(fmt.Sprintf("unknown token type: %v", tok))
  }
  return ""
 }

References :

http://dhconnelly.com/litebrite/litebrite.html

http://golang.org/pkg/go/token/#Token.IsKeyword

Advertisement