syntax

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Aug 28, 2026 License: MIT Imports: 4 Imported by: 44

Documentation

Overview

Package syntax implements the lexer of the glob pattern syntax. The parser lives in package glob; the syntax itself is described at [glob.Compile].

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsSpecial added in v1.0.0

func IsSpecial(c byte) bool

IsSpecial reports whether c is a glob meta character, that is, one that [glob.QuoteMeta] escapes. Note that `,`, `!` and `-` are not among them: they are special only inside `{...}` and `[...]` respectively, which are.

Types

type Lexer added in v1.0.0

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

Lexer splits a pattern into tokens; see Lexer.Next.

func NewLexer added in v1.0.0

func NewLexer(source string) *Lexer

NewLexer returns a lexer over the source pattern.

func (*Lexer) Next added in v1.0.0

func (l *Lexer) Next() Token

Next returns the next token. Once the input is over it returns EOF, and once an error happened it returns that Error, repeatedly.

func (*Lexer) Offset added in v1.0.0

func (l *Lexer) Offset() int

Offset returns the byte offset in the source the lexer stopped at, that is, the position right after the most recently returned token.

type Token added in v1.0.0

type Token struct {
	Type TokenType
	Data string
}

Token is a lexeme of the pattern: its kind and the source text it was read from (or the error message for Error, the literal characters with the escapes resolved for Text).

func (Token) String added in v1.0.0

func (t Token) String() string

type TokenType added in v1.0.0

type TokenType int

TokenType tells the kind of a Token.

const (
	// EOF marks the end of the input; the lexer returns it repeatedly.
	EOF TokenType = iota
	// Error carries an error message in Token.Data; the lexer keeps
	// returning it once it happened. Note that the lexer catches only the
	// errors local to a token (an invalid UTF-8 sequence, a malformed
	// character class): the structural ones, like an unclosed `{`, are for
	// the parser to detect.
	Error
	// Text is a run of literal characters, with the escapes resolved.
	Text
	// Any is the `*` wildcard.
	Any
	// Super is the `**` wildcard.
	Super
	// Single is the `?` wildcard.
	Single
	// Not is the `!` right after the `[` of a character class.
	Not
	// TermSeparator is the `,` between the alternatives of a `{...}` group.
	// Outside of a group a comma is a plain Text character.
	TermSeparator
	// RangeOpen and RangeClose are the `[` and `]` of a character class.
	// Between them the lexer produces either a Text token (a set of
	// characters, `[abc]`) or a RangeLo, RangeBetween, RangeHi triple (a
	// range, `[a-c]`), possibly preceded by Not.
	RangeOpen
	RangeClose
	RangeLo
	RangeHi
	RangeBetween
	// TermsOpen and TermsClose are the `{` and `}` of an alternatives group.
	TermsOpen
	TermsClose
)

func (TokenType) String added in v1.0.0

func (tt TokenType) String() string

Jump to

Keyboard shortcuts

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