syntax

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 1, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func LookupUnicodeClass

func LookupUnicodeClass(name string) (*unicode.RangeTable, bool)

Types

type CharRange

type CharRange struct {
	Lo, Hi rune
}

type Flags

type Flags uint32
const (
	FlagCaseInsensitive Flags = 1 << iota
	FlagMultiline
	FlagDotAll
	FlagUngreedy
	FlagUnicode
)

type GroupKind

type GroupKind int
const (
	GroupCapture       GroupKind = iota // (
	GroupNonCapture                     // (?:
	GroupNamed                          // (?<name> or (?P<name>
	GroupLookahead                      // (?=
	GroupNegLookahead                   // (?!
	GroupLookbehind                     // (?<=
	GroupNegLookbehind                  // (?<!
	GroupAtomic                         // (?>
	GroupFlags                          // (?i), (?mi-s)
)

type Lexer

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

func NewLexer

func NewLexer(pattern string) *Lexer

func (*Lexer) Tokenize

func (l *Lexer) Tokenize() ([]Token, error)

type Node

type Node struct {
	Op           Op
	Children     []*Node
	Rune         rune        // for OpLiteral
	Ranges       []CharRange // for OpCharClass (explicit ranges)
	UnicodeTable interface{} // *unicode.RangeTable for Unicode property classes
	Min, Max     int         // for OpRepeat: {min,max}, Max == -1 means unbounded
	Cap          int         // capture group index (0 = whole match)
	Name         string      // for OpNamedCapture, OpBackref by name
	Ref          int         // for OpBackref by number
	Flags        Flags
	Negated      bool // for OpCharClass (negated class)
}

type Op

type Op int
const (
	OpLiteral        Op = iota // single rune
	OpDot                      // . (any char except \n, or any char if DotAll)
	OpCharClass                // character class [abc], [a-z]
	OpConcat                   // AB
	OpAlternate                // A|B
	OpCapture                  // (...) capturing group
	OpGroup                    // (?:...) non-capturing group
	OpNamedCapture             // (?<name>...) named capturing group
	OpStar                     // A*
	OpPlus                     // A+
	OpQuest                    // A?
	OpRepeat                   // A{n,m}
	OpLazy                     // wraps quantifier for lazy mode
	OpPossessive               // wraps quantifier for possessive mode
	OpLookahead                // (?=A)
	OpNegLookahead             // (?!A)
	OpLookbehind               // (?<=A)
	OpNegLookbehind            // (?<!A)
	OpAtomic                   // (?>A)
	OpBackref                  // \1, \k<name>
	OpBeginLine                // ^
	OpEndLine                  // $
	OpBeginText                // \A
	OpEndText                  // \z
	OpWordBoundary             // \b
	OpNoWordBoundary           // \B
	OpEmpty                    // empty match
)

type Parser

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

type SyntaxError

type SyntaxError struct {
	Pattern string
	Pos     int
	Msg     string
}

func (*SyntaxError) Error

func (e *SyntaxError) Error() string

type Token

type Token struct {
	Kind      TokenKind
	Rune      rune      // for TokLiteral
	Value     string    // raw text of the token
	Min, Max  int       // for TokQuantifier: {Min,Max}, Max == -1 means unbounded
	GroupKind GroupKind // for TokGroupOpen
	Name      string    // for named groups, named backrefs
	Ref       int       // for TokBackref by number
	Negated   bool      // for TokCharClass/TokUnicodeClass (uppercase variants)
	Pos       int       // byte offset in original pattern
}

type TokenKind

type TokenKind int
const (
	TokLiteral      TokenKind = iota // single rune: 'a', '\n', '\x41'
	TokDot                           // '.'
	TokCaret                         // '^'
	TokDollar                        // '$'
	TokStar                          // '*'
	TokPlus                          // '+'
	TokQuestion                      // '?'
	TokPipe                          // '|'
	TokLParen                        // '('
	TokRParen                        // ')'
	TokLBracket                      // '['
	TokRBracket                      // ']'
	TokLBrace                        // '{'
	TokRBrace                        // '}'
	TokBackref                       // \1..\99, \k<name>
	TokGroupOpen                     // (?:, (?=, (?!, (?<=, (?<!, (?<name>, (?P<name>
	TokQuantifier                    // {n}, {n,}, {n,m}
	TokCharClass                     // \d, \w, \s, \D, \W, \S
	TokUnicodeClass                  // \p{L}, \P{Lu}
	TokEOF
)

type Tree

type Tree struct {
	Root     *Node
	NumCap   int
	CapNames map[string]int
}

func Parse

func Parse(pattern string) (*Tree, error)

Jump to

Keyboard shortcuts

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