Golang go/token.Token.IsOperator function example

package go/token

IsOperator returns true for tokens corresponding to operators and delimiters; it returns false otherwise.

Golang go/token.Token.IsOperator function usage example

 // getClass returns the CSS class name associated with tok.
  func (h *Highlighter) getClass(tok token.Token) string {
 switch {
 case tok.IsKeyword():
 return h.KeywordClass
 case tok.IsLiteral():  // <---- here
 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.IsOperator

Advertisement