Documentation
¶
Overview ¶
Package token defines CSS tokens produced by a tokenizer.
Index ¶
- Constants
- func Equals(a Token, b Token) bool
- type HashType
- type NumberType
- type Position
- type Token
- func AtKeyword(s string) Token
- func BadString() Token
- func BadUrl() Token
- func CDC() Token
- func CDO() Token
- func Colon() Token
- func Comma() Token
- func Delim(x rune) Token
- func Dimension(nt NumberType, repr string, value float64, unit string) Token
- func EOF() Token
- func Function(s string) Token
- func Hash(t HashType, s string) Token
- func Ident(s string) Token
- func LeftCurlyBracket() Token
- func LeftParen() Token
- func LeftSquareBracket() Token
- func Number(nt NumberType, repr string, value float64) Token
- func Percentage(nt NumberType, repr string, value float64) Token
- func RightCurlyBracket() Token
- func RightParen() Token
- func RightSquareBracket() Token
- func Semicolon() Token
- func String(s string) Token
- func Url(s string) Token
- func Whitespace() Token
- func (t Token) Delim() rune
- func (t Token) HashType() HashType
- func (t Token) Is(x Type) bool
- func (t Token) IsNumeric() bool
- func (t Token) NumericValue() (NumberType, float64)
- func (t Token) Position() Position
- func (t Token) Repr() string
- func (t Token) String() string
- func (t Token) StringValue() string
- func (t Token) Type() Type
- func (t Token) Unit() string
- func (t Token) WithPosition(p Position) Token
- type Type
Constants ¶
const ( TypeWhitespace = Type("whitespace-token") TypeEOF = Type("EOF-token") TypeString = Type("string-token") TypeBadString = Type("bad-string-token") TypeDelim = Type("delim-token") TypeComma = Type("comma-token") TypeHash = Type("hash-token") TypeLeftParen = Type("(-token") TypeRightParen = Type(")-token") TypeNumber = Type("number-token") TypeDimension = Type("dimension-token") TypePercentage = Type("percentage-token") TypeCDC = Type("CDC-token") TypeIdent = Type("ident-token") TypeFunction = Type("function-token") TypeUrl = Type("url-token") TypeBadUrl = Type("bad-url-token") TypeColon = Type("colon-token") TypeSemicolon = Type("semicolon-token") TypeCDO = Type("CDO-token") TypeAtKeyword = Type("at-keyword-token") TypeLeftSquareBracket = Type("[-token") TypeRightSquareBracket = Type("]-token") TypeLeftCurlyBracket = Type("{-token") TypeRightCurlyBracket = Type("}-token") )
const ( HashTypeID = HashType("id") HashTypeUnrestricted = HashType("unrestricted") )
const ( NumberTypeInteger = NumberType("integer") NumberTypeNumber = NumberType("number") )
Variables ¶
This section is empty.
Functions ¶
func Equals ¶
Equals returns true iff the given two tokens are of the same type and of the same value (and other applicable details, such as hash type, number type, dimension unit, etc).
In the case of <number-token>, <percentage-token>, and <dimension-token>, the tokens are also only considered equal if their underlying representation (i.e. the result of the Token.Repr method) is exactly equal.
Types ¶
type NumberType ¶
type NumberType string
type Token ¶
type Token struct {
// contains filtered or unexported fields
}
func LeftCurlyBracket ¶
func LeftCurlyBracket() Token
func LeftSquareBracket ¶
func LeftSquareBracket() Token
func Percentage ¶
func Percentage(nt NumberType, repr string, value float64) Token
func RightCurlyBracket ¶
func RightCurlyBracket() Token
func RightParen ¶
func RightParen() Token
func RightSquareBracket ¶
func RightSquareBracket() Token
func Whitespace ¶
func Whitespace() Token
func (Token) Delim ¶
Delim returns the delimeter of a <delim-token>. If the token is not a delim token, returns utf.RuneError.
func (Token) HashType ¶
HashType returns the hash type of a <hash-token>. If the token is not a hash token, returns HashType("")
func (Token) IsNumeric ¶
IsNumeric returns true if a token is a <number-token>, <percentage-token>, or <dimension-token>.
func (Token) NumericValue ¶
func (t Token) NumericValue() (NumberType, float64)
NumericValue returns a (number type, numeric value) of a <number-token>, <percentage-token>, or <dimension-token>. If the token is not one of these types, returns (NumberType(""), 0). In the case of a percentage, the raw value as typed is returned e.g. "50%" returns 50.0.
func (Token) Repr ¶
Repr returns the original representation of a token (or part of a token). This preserves details such as whether .009 was written as .009 or 9e-3 in a number. This is only valid for certain types. If called on an unsupported type, this function returns an empty string.
func (Token) StringValue ¶
StringValue returns the string value of a <ident-token>, <function-token>, <at-keyword-token>, <hash-token>, <string-token>, or <url-token>, or the empty string if the token is not one of these types.
func (Token) Unit ¶
Unit returns the unit of a <dimension-token>. If the token is not a dimension token, returns "".