token

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2026 License: MIT Imports: 1 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package token defines the tokens the lexer produces and the parser consumes.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsIdentByte

func IsIdentByte(c byte) bool

IsIdentByte reports whether c can be part of an identifier: a letter, a digit, or an underscore (section 2).

func IsKeyword

func IsKeyword(word string) bool

IsKeyword reports whether word is a keyword.

func IsReserved

func IsReserved(word string) bool

IsReserved reports whether word is a reserved word.

Types

type Comment

type Comment struct {
	Text     string // the comment's source, from // or /* to the end of the line or */
	Pos      Pos
	EndPos   Pos // just after the comment
	Off, End int
}

Comment is a comment as written, kept only by lexer.LexLayout.

type Kind

type Kind int

Kind classifies a token.

const (
	EOF      Kind = iota
	Newline       // a line break that ends a statement (section 2)
	Ident         // an identifier, or any word after "." or "?."
	Keyword       // one of the keywords
	Reserved      // one of the reserved words
	Int           // an integer literal; Value holds the int64
	Float         // a float literal; Float holds the float64
	String        // a string literal; Text holds the unescaped value
	Template      // a string with interpolations; Parts holds its pieces
	Op            // an operator or punctuation; Text holds it
	Regex         // a regular expression literal; Text holds the source as written, Flags the sorted flags
	Html          // an HTML expression; Markup holds its tree
	Duration      // a duration literal; Text holds it as written
	// Bad is source the recovering lexer could not read as a token (lexer.LexRecover), kept so
	// that the parser can step over it; Text holds it as written.
	Bad
)

func (Kind) String

func (k Kind) String() string

type Markup

type Markup struct {
	Nodes []MarkupNode
	// Close is the position of the end tag that closed the content, </name> or </>, and zero for
	// the children of a self-closing element.
	Close Pos
}

Markup is the content of an HTML expression as the lexer read it (section 5): its text decoded and its white space collapsed, its interpolations as token streams for the parser.

type MarkupAttr

type MarkupAttr struct {
	Kind   MarkupAttrKind
	Name   string
	Text   string
	Tokens []Token
	Pos    Pos
	EndPos Pos // just after the attribute
	// Off and End are the byte span of the expression, from its { to its }.
	Off, End int
}

MarkupAttr is an attribute as written; an expression's tokens end with EOF.

type MarkupAttrKind

type MarkupAttrKind uint8

MarkupAttrKind is the form of a MarkupAttr.

const (
	AttrText   MarkupAttrKind = iota // name="text"; Text holds the decoded text
	AttrBare                         // name alone
	AttrExpr                         // name={expr}
	AttrSpread                       // {...expr}
)

type MarkupKind

type MarkupKind uint8

MarkupKind is the kind of a MarkupNode.

const (
	MarkupText    MarkupKind = iota // Text holds the decoded text
	MarkupElement                   // Name, Attrs, and Children
	MarkupExpr                      // an interpolation; Tokens ends with EOF
)

type MarkupNode

type MarkupNode struct {
	Kind     MarkupKind
	Name     string
	Attrs    []MarkupAttr
	Children *Markup
	Text     string
	Tokens   []Token
	// TextOnly marks a <title> or <textarea> outside <svg> and <math>, whose content may not be Html.
	TextOnly bool
	Pos      Pos
	EndPos   Pos // just after the node
	// Off and End are the node's byte span in the source.
	Off, End int
}

MarkupNode is one item of content.

type Part

type Part struct {
	Text   string
	Tokens []Token
	Pos    Pos
	EndPos Pos // just after the part
	// Off and End are the part's byte span in the source: the text as written, or an
	// interpolation from its $ to its closing brace.
	Off, End int
}

Part is one piece of a string with interpolations: literal text, or the tokens of an interpolation (ending with EOF).

type Pos

type Pos struct {
	Line, Col int
}

Pos is a position in a source file: 1-based line and 1-based byte column.

type Token

type Token struct {
	Kind  Kind
	Text  string  // the word, operator, or unescaped string value
	Value int64   // for Int
	Float float64 // for Float
	Parts []Part  // for Template
	Flags string  // for Regex
	// Markup is the fragment an Html token holds: an element is a fragment of one node.
	Markup *Markup
	Pos    Pos
	// EndPos is the position just after the token, so Pos and EndPos span it; a Newline is empty.
	EndPos Pos
	// Off and End are the token's byte span in the source: the source between them is the token
	// as written. A Newline is empty, at its line break.
	Off, End int
}

Token is one lexical token.

func (Token) Is

func (t Token) Is(text string) bool

Is reports whether the token is the keyword or operator with the given text.

func (Token) String

func (t Token) String() string

String describes the token for error messages.

Jump to

Keyboard shortcuts

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