Example #1
0
func tokenclass(tok token.Token) int {
	switch {
	case tok.IsLiteral():
		return literal
	case tok.IsOperator():
		return operator
	case tok.IsKeyword():
		return keyword
	}
	return special
}
Example #2
0
// 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 ""
}
Example #3
0
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 ""
}
Example #4
0
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>",
	}
}