lexer

package
v0.3.3 Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2026 License: MIT Imports: 7 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 lexer turns Ant source into tokens, applying the line-ending rule of section 2.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsMarkupSpace

func IsMarkupSpace(c byte) bool

IsMarkupSpace reports whether c is white space in markup (section 5, White space).

func KeepsWhiteSpace

func KeepsWhiteSpace(name string) bool

KeepsWhiteSpace reports whether the content of the element name, matched ignoring ASCII case, is outside the white space rule (section 5, White space): <pre> and <textarea>, and <script> and <style>, whose content is raw text.

func Lex

func Lex(src string) ([]token.Token, error)

Lex tokenizes src. The token stream ends with a Newline (unless empty) and an EOF.

func LexLayout

func LexLayout(src string, shebang bool) ([]token.Token, []token.Comment, error)

LexLayout tokenizes src as Lex does, and also returns its comments in source order, for the formatter, which must print them where they were. With shebang true, src is a file, and a first line that starts with #! is skipped (section 2); it is returned as the first comment.

func LexWith

func LexWith(src string, regex bool) (toks []token.Token, err error)

LexWith tokenizes src as Lex does. With regex false, a / never begins a regular expression literal, which gives the lexer as it was before the literal existed; the fuzz test compares the two on every input in which the literal does not occur.

func NormalizeBreaks

func NormalizeBreaks(s string) string

NormalizeBreaks returns s with each \r that is a line break on its own replaced by \n, so that every line break holds a \n and its lines can be found and counted by \n. The offsets do not change.

func Operand

func Operand(t token.Token) bool

Operand reports whether t is an operand in the sense of section 2: an identifier, a literal of any kind, true, false, null, void, or a closing bracket. After an operand a / is division.

Types

type Error

type Error struct {
	Pos token.Pos
	Msg string
	// AtEnd marks an error the end of the source caused, such as an element still open there,
	// so that more input may complete it.
	AtEnd bool
}

Error is a lexical error.

func LexRecover

func LexRecover(src string, shebang bool) ([]token.Token, []token.Comment, []*Error)

LexRecover tokenizes src as LexLayout does but goes on past every error, for an editor, and returns the errors found in source order. A string or raw string that no later quote or backtick closes ends at the end of its first line, and a comment left open at the end of the source; a construct that cannot be read at all becomes a Bad token; and markup that is malformed is read as far as it goes. Tokens come out as they would once the errors were fixed, as far as the lexer can tell.

func (*Error) Error

func (e *Error) Error() string

Jump to

Keyboard shortcuts

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