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 ¶
- func Class(b byte) uint8
- type Ends
- type Follow
- type Regexp
- func (r *Regexp) ASCII() Sets
- func (r *Regexp) Accepts(prev uint8, pcs []uint32) bool
- func (r *Regexp) Consumes(b byte) bool
- func (r *Regexp) Expands() bool
- func (r *Regexp) First(next uint8) []uint32
- func (r *Regexp) Follow(prev, next uint8) *Follow
- func (r *Regexp) Len() int
- func (r *Regexp) MatchRune(pc uint32, c rune) bool
- func (r *Regexp) Next(dst, pcs []uint32, prev, next uint8, seen []uint64, stamp uint64, ...) []uint32
- type Sets
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
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 ¶
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) Reset ¶
func (e *Ends) Reset()
Reset ends the listing, so the next Start begins a new one.
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.
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 ¶
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) Accepts ¶
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 ¶
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 ¶
Expands reports whether some entries of the closures of r are marked with expand. Only Next follows them.
func (*Regexp) First ¶
First returns the rune instructions of the start of the string, before a byte of class next.
func (*Regexp) Follow ¶
Follow returns the instructions that follow each instruction between bytes of classes prev and next.
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.