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 :
Advertisement
Something interesting
Tutorials
+17.1k Golang : Capture stdout of a child process and act according to the result
+14.8k Golang : Normalize unicode strings for comparison purpose
+16.4k Golang : Test floating point numbers not-a-number and infinite example
+7.4k Golang : Convert source code to assembly language
+22.7k Golang : Round float to precision example
+12.5k Golang : Arithmetic operation with numerical slices or arrays example
+11.3k Golang : Byte format example
+10.5k Generate Random number with math/rand in Go
+19.1k Golang : When to use public and private identifier(variable) and how to make the identifier public or private?
+8.2k Golang : Add build version and other information in executables
+5k Golang : Calculate a pip value and distance to target profit example