本文整理汇总了Golang中go/token.Token.IsOperator方法的典型用法代码示例。如果您正苦于以下问题:Golang Token.IsOperator方法的具体用法?Golang Token.IsOperator怎么用?Golang Token.IsOperator使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类go/token.Token
的用法示例。
在下文中一共展示了Token.IsOperator方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: tokenclass
func tokenclass(tok token.Token) int {
switch {
case tok.IsLiteral():
return literal
case tok.IsOperator():
return operator
case tok.IsKeyword():
return keyword
}
return special
}
示例2: TokenKind
// TokenKind returns a syntaxhighlight token kind value for the given tok and lit.
func TokenKind(tok token.Token, lit string) syntaxhighlight.Kind {
switch {
case tok.IsKeyword() || (tok.IsOperator() && tok <= token.ELLIPSIS):
return syntaxhighlight.Keyword
// Literals.
case tok == token.INT || tok == token.FLOAT || tok == token.IMAG || tok == token.CHAR:
return syntaxhighlight.Decimal
case tok == token.STRING:
return syntaxhighlight.String
case lit == "true" || lit == "false" || lit == "iota" || lit == "nil":
return syntaxhighlight.Literal
case tok == token.COMMENT:
return syntaxhighlight.Comment
default:
return syntaxhighlight.Plaintext
}
}
示例3: getClass
// 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():
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 ""
}
示例4: getColor
func getColor(tok token.Token) string {
switch {
case tok.IsKeyword():
return Colors[Keyword]
case tok.IsLiteral():
if tok == token.IDENT {
return Colors[Identifier]
} else {
return Colors[Literal]
}
case tok.IsOperator():
return Colors[Operator]
case tok == token.COMMENT:
return Colors[Comment]
case tok == token.ILLEGAL:
return Colors[Illegal]
default:
panic(fmt.Sprintf("unknown token type: %v", tok))
}
return ""
}
示例5: Token
func (self *HTMLStyler) Token(tok token.Token) ([]byte, printer.HTMLTag) {
extra := ""
if tok.IsKeyword() {
extra += " go-keyword"
}
if tok.IsLiteral() {
extra += " go-literal"
}
if tok.IsOperator() {
extra += " go-operator"
}
self.prev = tok
return []byte(tok.String()), printer.HTMLTag{
Start: "<span class=\"go-token" + extra + "\">",
End: "</span>",
}
}