engine

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: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrBacktrackLimit = errors.New("rexa: backtrack limit exceeded")

Functions

This section is empty.

Types

type BacktrackEngine

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

func NewBacktrackEngine

func NewBacktrackEngine(limit int64) *BacktrackEngine

func (*BacktrackEngine) Match

func (e *BacktrackEngine) Match(prog *compiler.Program, input *Input, pos int) *MatchResult

func (*BacktrackEngine) Search

func (e *BacktrackEngine) Search(prog *compiler.Program, input *Input, startPos int) *MatchResult

type CaptureSlot

type CaptureSlot struct {
	Start int
	End   int
}

func CopySlots

func CopySlots(src []CaptureSlot) []CaptureSlot

func EmptySlots

func EmptySlots(n int) []CaptureSlot

type Engine

type Engine interface {
	Match(prog *compiler.Program, input *Input, pos int) *MatchResult
	Search(prog *compiler.Program, input *Input, pos int) *MatchResult
}

type EngineKind

type EngineKind int
const (
	EngineLiteral EngineKind = iota
	EngineLazyDFA
	EnginePikeVM
	EngineBacktrack
)

func (EngineKind) String

func (k EngineKind) String() string

type Input

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

func MakeInput

func MakeInput(s string) Input

func NewInputBytes

func NewInputBytes(b []byte) *Input

func NewInputString

func NewInputString(s string) *Input

func (*Input) Length

func (inp *Input) Length() int

func (*Input) RuneAt

func (inp *Input) RuneAt(pos int) (rune, bool)

func (*Input) Runes

func (inp *Input) Runes() []rune

func (*Input) Slice

func (inp *Input) Slice(start, end int) []rune

func (*Input) SliceString

func (inp *Input) SliceString(start, end int) string

func (*Input) String

func (inp *Input) String() string

type LazyDFA

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

LazyDFA builds DFA states on the fly from the NFA program. Each DFA state is a set of NFA instruction PCs (the epsilon closure). States are cached; if the cache overflows it's flushed and rebuilt.

func NewLazyDFA

func NewLazyDFA(prog *compiler.Program, capacity int) *LazyDFA

func (*LazyDFA) Abandoned

func (d *LazyDFA) Abandoned() bool

func (*LazyDFA) Match

func (d *LazyDFA) Match(prog *compiler.Program, input *Input, pos int) *MatchResult

func (*LazyDFA) Search

func (d *LazyDFA) Search(prog *compiler.Program, input *Input, pos int) *MatchResult

func (*LazyDFA) SearchBool

func (d *LazyDFA) SearchBool(prog *compiler.Program, input Input, pos int) (matched bool, abandoned bool)

func (*LazyDFA) SearchInto

func (d *LazyDFA) SearchInto(prog *compiler.Program, input *Input, pos int, dst *MatchResult, caps []CaptureSlot) (bool, bool)

SearchInto finds first match, writing result into dst. Returns (matched, abandoned).

type LiteralEngine

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

func NewLiteralEngine

func NewLiteralEngine(literal string) *LiteralEngine

func (*LiteralEngine) Match

func (e *LiteralEngine) Match(prog *compiler.Program, input *Input, pos int) *MatchResult

func (*LiteralEngine) MatchString

func (e *LiteralEngine) MatchString(s string, pos int) (end int, ok bool)

MatchString checks if the pattern matches at exactly position pos. Zero allocs for ASCII.

func (*LiteralEngine) Search

func (e *LiteralEngine) Search(prog *compiler.Program, input *Input, pos int) *MatchResult

func (*LiteralEngine) SearchString

func (e *LiteralEngine) SearchString(s string, pos int) (start, end int, ok bool)

SearchString searches directly on a string without creating Input. Zero allocs.

type MatchResult

type MatchResult struct {
	Matched  bool
	Captures []CaptureSlot
	Err      error
}

type MetaEngine

type MetaEngine struct {
	Used EngineKind
	// contains filtered or unexported fields
}

func NewMetaEngine

func NewMetaEngine(prog *compiler.Program) *MetaEngine

func NewMetaEngineWithOptions

func NewMetaEngineWithOptions(prog *compiler.Program, backtrackLimit int64, cacheCapacity int) *MetaEngine

func (*MetaEngine) Literal

func (me *MetaEngine) Literal() *LiteralEngine

func (*MetaEngine) Match

func (me *MetaEngine) Match(prog *compiler.Program, input *Input, pos int) *MatchResult

func (*MetaEngine) PikeVM

func (me *MetaEngine) PikeVM() *PikeVM

func (*MetaEngine) Search

func (me *MetaEngine) Search(prog *compiler.Program, input *Input, pos int) *MatchResult

func (*MetaEngine) SearchBool

func (me *MetaEngine) SearchBool(prog *compiler.Program, input Input, pos int) bool

func (*MetaEngine) SearchRange

func (me *MetaEngine) SearchRange(prog *compiler.Program, input Input, pos int) (start, end int, ok bool)

SearchRange returns match boundaries without allocating MatchResult.

type PikeVM

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

func NewPikeVM

func NewPikeVM() *PikeVM

func (*PikeVM) Match

func (vm *PikeVM) Match(prog *compiler.Program, input *Input, pos int) *MatchResult

func (*PikeVM) Search

func (vm *PikeVM) Search(prog *compiler.Program, input *Input, startPos int) *MatchResult

func (*PikeVM) SearchBool

func (vm *PikeVM) SearchBool(prog *compiler.Program, input Input, startPos int) bool

Jump to

Keyboard shortcuts

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