pattern

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 19, 2026 License: MIT Imports: 5 Imported by: ? 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 pattern executes refinement regular expressions with deterministic work accounting. Native schema regex dialects remain a separate concern.

Index

Constants

View Source
const InstructionProfile = "refine.regex.instructions.v1"

InstructionProfile versions the execution semantics, not the source syntax parser or its optimization choices. This development snapshot is not a native schema format or an unversioned cross-toolchain serialization guarantee.

Variables

This section is empty.

Functions

func Fold

func Fold[R any](mode Mode, cases ModeCases[R]) R

Adding a second enum makes GoPlus qualify its generated fold helpers. Retain the original Mode helper API for existing plain-Go consumers.

func ModeEqual

func ModeEqual(a, b Mode) bool

ModeEqual reports structural equality of a and b.

func ModeEqualWith

func ModeEqualWith(a, b Mode, ov ModeEqOverrides) bool

ModeEqualWith reports structural equality of a and b under ov.

func ModeFold

func ModeFold[R any](m Mode, cs ModeCases[R]) R

ModeFold reduces Mode by one-level case analysis.

func OpcodeEqual

func OpcodeEqual(a, b Opcode) bool

OpcodeEqual reports structural equality of a and b.

func OpcodeEqualWith

func OpcodeEqualWith(a, b Opcode, ov OpcodeEqOverrides) bool

OpcodeEqualWith reports structural equality of a and b under ov.

func OpcodeFold

func OpcodeFold[R any](o Opcode, cs OpcodeCases[R]) R

OpcodeFold reduces Opcode by one-level case analysis.

func OpcodeName

func OpcodeName(op Opcode) string

Types

type Accept

type Accept struct{}

type Alt

type Alt struct{}

type AltMatch

type AltMatch struct{}

type Capture

type Capture struct{}

type EmptyWidth

type EmptyWidth struct{}

type Error

type Error struct {
	Code    string
	Message string
}

func (*Error) Error

func (e *Error) Error() string

type Fail

type Fail struct{}

type Full

type Full struct{}

type Instruction

type Instruction struct {
	Opcode Opcode
	Out    uint32
	Arg    uint32
	Runes  []rune
}

type Mode

type Mode interface {
	// contains filtered or unexported methods
}

type ModeCases

type ModeCases[R any] struct {
	Full   func() R
	Search func() R
}

ModeCases selects one handler per Mode variant for ModeFold.

type ModeEqOverrides

type ModeEqOverrides struct {
	Full   func(x, y Full) (eq, handled bool)
	Search func(x, y Search) (eq, handled bool)
}

ModeEqOverrides carries optional per-variant hooks for ModeEqualWith. A hook returning handled=false falls through to the derived comparison.

type Nop

type Nop struct{}

type Opcode

type Opcode interface {
	// contains filtered or unexported methods
}

type OpcodeCases

type OpcodeCases[R any] struct {
	Alt          func() R
	AltMatch     func() R
	Capture      func() R
	EmptyWidth   func() R
	Accept       func() R
	Fail         func() R
	Nop          func() R
	Rune         func() R
	Rune1        func() R
	RuneAny      func() R
	RuneAnyNotNL func() R
}

OpcodeCases selects one handler per Opcode variant for OpcodeFold.

type OpcodeEqOverrides

type OpcodeEqOverrides struct {
	Alt          func(x, y Alt) (eq, handled bool)
	AltMatch     func(x, y AltMatch) (eq, handled bool)
	Capture      func(x, y Capture) (eq, handled bool)
	EmptyWidth   func(x, y EmptyWidth) (eq, handled bool)
	Accept       func(x, y Accept) (eq, handled bool)
	Fail         func(x, y Fail) (eq, handled bool)
	Nop          func(x, y Nop) (eq, handled bool)
	Rune         func(x, y Rune) (eq, handled bool)
	Rune1        func(x, y Rune1) (eq, handled bool)
	RuneAny      func(x, y RuneAny) (eq, handled bool)
	RuneAnyNotNL func(x, y RuneAnyNotNL) (eq, handled bool)
}

OpcodeEqOverrides carries optional per-variant hooks for OpcodeEqualWith. A hook returning handled=false falls through to the derived comparison.

type Program

type Program struct {
	Profile        string
	UnicodeVersion string
	Start          int
	Instructions   []Instruction
}

type Regex

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

func Compile

func Compile(source value.Text, meter *validation.Meter) (Regex, error)

Compile reuses the Go/RE2 syntax parser and program compiler, not its matcher. Invalid/unsupported dialect constructs fail explicitly. Parser diagnostics are sanitized because the pattern itself can originate in a private payload.

func (Regex) Match

func (r Regex) Match(subject value.Text, mode Mode, meter *validation.Meter) (bool, error)

Match uses an iterative Thompson-style state set, not backtracking. Valid UTF-16 surrogate pairs form one code point; lone units retain their identity rather than being silently replaced. length in the DSL still counts units.

func (Regex) Program

func (r Regex) Program() (Program, error)

Program returns a detached instruction snapshot for other runtime backends. Mutating the snapshot, including any rune range, cannot affect this Regex or any subsequent snapshot. Character folding uses the declared Unicode version.

type Rune

type Rune struct{}

type Rune1

type Rune1 struct{}

type RuneAny

type RuneAny struct{}

type RuneAnyNotNL

type RuneAnyNotNL struct{}
type Search struct{}

Jump to

Keyboard shortcuts

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