regprog

package
v0.33.0 Latest Latest
Warning

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

Go to latest
Published: Oct 14, 2026 License: Apache-2.0 Imports: 3 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 regprog compiles a regular expression into a program simulated one position at a time, so a single pass over a string finds every prefix that matches. The simulation never backtracks and a step costs O(len(prog)), as the Pike VM of the regexp package.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Class

func Class(b byte) uint8

Class returns the class of the byte b.

Types

type Ends

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

Ends lists the ends of the prefixes of s[start:] that match a program, the positions e of delim after start such that s[start:e] matches. Each call to Next resumes where the previous one stopped, so listing every end costs a single pass, and the memory of a listing depends on the program only.

func (*Ends) Next

func (e *Ends) Next(from int) int

Next returns the first end at or after from, or -1 if there is none. When from is before the end returned last, the listing starts over.

func (*Ends) Reach

func (e *Ends) Reach() int

Reach returns the highest position passed to Next or stepped to.

func (*Ends) Reset

func (e *Ends) Reset()

Reset ends the listing, so the next Start begins a new one.

func (*Ends) Start

func (e *Ends) Start(r *Regexp, s string, start int, delim byte)

Start starts the listing of the ends of r over s from start, unless that listing is in progress.

func (*Ends) Steps

func (e *Ends) Steps() int

Steps returns the number of positions stepped since the listing was created.

type Follow

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

Follow holds the instructions that follow each instruction without consuming a rune. A rune instruction lists the rune instructions of its closure, or the instruction it leads to when the closure has more than maxClosure instructions. An empty instruction then lists the instructions it leads to, and Next follows the entries marked with expand to reach the whole closure.

func (*Follow) Of

func (f *Follow) Of(pc uint32) []uint32

Of returns the entries of the instruction pc.

type Regexp

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

Regexp is a regular expression compiled for simulation. The empty transitions are followed at compile time, for every context of the empty-width assertions, unless a closure is too large.

func Compile

func Compile(re *regexp.Regexp) (*Regexp, error)

Compile compiles re for simulation. The simulation agrees with MatchString only when re is anchored at both ends, as the expressions of route patterns are.

func (*Regexp) ASCII

func (r *Regexp) ASCII() Sets

ASCII returns the sets of the ASCII bytes the rune instructions match.

func (*Regexp) Accepts

func (r *Regexp) Accepts(prev uint8, pcs []uint32) bool

Accepts reports whether a match follows one of the rune instructions pcs at the end of the string, after a byte of class prev.

func (*Regexp) Consumes

func (r *Regexp) Consumes(b byte) bool

Consumes reports whether a rune instruction of r matches b, which must be ASCII. When none does, no string with b matches r.

func (*Regexp) Expands

func (r *Regexp) Expands() bool

Expands reports whether some entries of the closures of r are marked with expand. Only Next follows them.

func (*Regexp) First

func (r *Regexp) First(next uint8) []uint32

First returns the rune instructions of the start of the string, before a byte of class next.

func (*Regexp) Follow

func (r *Regexp) Follow(prev, next uint8) *Follow

Follow returns the instructions that follow each instruction between bytes of classes prev and next.

func (*Regexp) Len

func (r *Regexp) Len() int

Len returns the number of instructions of the program of r.

func (*Regexp) MatchRune

func (r *Regexp) MatchRune(pc uint32, c rune) bool

MatchRune reports whether the rune instruction pc matches c.

func (*Regexp) Next

func (r *Regexp) Next(dst, pcs []uint32, prev, next uint8, seen []uint64, stamp uint64, stack *[]uint32) []uint32

Next appends to dst the rune instructions that follow the rune instructions pcs between bytes of classes prev and next, except those marked in seen with stamp. It marks the instructions it reaches, so each one is reached once at a position, and uses stack as scratch.

type Sets

type Sets [][2]uint64

Sets holds, for each rune instruction, the set of the ASCII bytes it matches.

func (Sets) Has

func (s Sets) Has(pc uint32, b byte) bool

Has reports whether the rune instruction pc matches the ASCII byte b.

Jump to

Keyboard shortcuts

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