token

package
v2.16.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 24, 2024 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package token defines CSS tokens produced by a tokenizer.

Index

Constants

View Source
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")
)
View Source
const (
	HashTypeID           = HashType("id")
	HashTypeUnrestricted = HashType("unrestricted")
)
View Source
const (
	NumberTypeInteger = NumberType("integer")
	NumberTypeNumber  = NumberType("number")
)

Variables

This section is empty.

Functions

func Equals

func Equals(a Token, b Token) bool

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 HashType

type HashType string

type NumberType

type NumberType string

type Position added in v2.7.0

type Position struct {
	Byte int64 // steam offset in bytes (0-indexed)
	Rune int64 // line offset in runes (0-indexed)
	Line int64 // current line (0-indexed)
	End  int64 // stream offset in bytes (0-indexed)
}

type Token

type Token struct {
	// contains filtered or unexported fields
}

func AtKeyword

func AtKeyword(s string) Token

func BadString

func BadString() Token

func BadUrl

func BadUrl() Token

func CDC

func CDC() Token

func CDO

func CDO() Token

func Colon

func Colon() Token

func Comma

func Comma() Token

func Delim

func Delim(x rune) Token

func Dimension

func Dimension(nt NumberType, repr string, value float64, unit string) Token

func EOF

func EOF() Token

func Function

func Function(s string) Token

func Hash

func Hash(t HashType, s string) Token

func Ident

func Ident(s string) Token

func LeftCurlyBracket

func LeftCurlyBracket() Token

func LeftParen

func LeftParen() Token

func LeftSquareBracket

func LeftSquareBracket() Token

func Number

func Number(nt NumberType, repr string, value float64) 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 Semicolon

func Semicolon() Token

func String

func String(s string) Token

func Url

func Url(s string) Token

func Whitespace

func Whitespace() Token

func (Token) Delim

func (t Token) Delim() rune

Delim returns the delimeter of a <delim-token>. If the token is not a delim token, returns utf.RuneError.

func (Token) HashType

func (t Token) HashType() HashType

HashType returns the hash type of a <hash-token>. If the token is not a hash token, returns HashType("")

func (Token) Is

func (t Token) Is(x Type) bool

func (Token) IsNumeric

func (t Token) IsNumeric() bool

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) Position added in v2.7.0

func (t Token) Position() Position

func (Token) Repr

func (t Token) Repr() string

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) String

func (t Token) String() string

func (Token) StringValue

func (t Token) StringValue() string

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) Type

func (t Token) Type() Type

func (Token) Unit

func (t Token) Unit() string

Unit returns the unit of a <dimension-token>. If the token is not a dimension token, returns "".

func (Token) WithPosition added in v2.7.0

func (t Token) WithPosition(p Position) Token

type Type

type Type string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL