compiler

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Optimize

func Optimize(p *Program)

Types

type Compiler

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

type Inst

type Inst struct {
	Op              OpCode
	Out             int         // primary successor
	Out1            int         // secondary successor (for InstSplit)
	Rune            rune        // for InstRune
	Ranges          []Range     // for InstRuneClass
	UnicodeTable    interface{} // *unicode.RangeTable for Unicode property classes
	Cap             int         // for InstCapStart/End
	Ref             int         // for InstBackref
	Greedy          bool        // for InstSplit: prefer Out (greedy) vs Out1 (lazy)
	Negated         bool        // for InstRuneClass: negated class
	CaseInsensitive bool        // for InstRune/InstRuneClass: (?i) mode
}

type OpCode

type OpCode int
const (
	InstRune            OpCode = iota // match single rune
	InstRuneClass                     // match rune against ranges
	InstAnyNotNL                      // match any char except \n
	InstAnyChar                       // match any char (dotall)
	InstSplit                         // NFA split: try Out and Out1
	InstJump                          // unconditional jump to Out
	InstMatch                         // successful match
	InstFail                          // forced failure
	InstCapStart                      // begin capture group
	InstCapEnd                        // end capture group
	InstBeginLine                     // ^
	InstEndLine                       // $
	InstBeginText                     // \A
	InstEndText                       // \z
	InstWordBoundary                  // \b
	InstNoWordBoundary                // \B
	InstLookaheadStart                // begin lookahead
	InstLookaheadEnd                  // end lookahead
	InstLookbehindStart               // begin lookbehind
	InstLookbehindEnd                 // end lookbehind
	InstBackref                       // match captured group content
	InstAtomicStart                   // begin atomic group
	InstAtomicEnd                     // end atomic group
)

type Program

type Program struct {
	Insts           []Inst
	Start           int
	NumCap          int
	CapNames        map[string]int
	NeedsBacktrack  bool
	NeedsLookaround bool
	HasAnchors      bool
	AnchoredStart   bool // pattern starts with ^ or \A
	OnlyStartAnchor bool // only anchor is ^ at start (safe for DFA)
	IsLiteral       bool
	LiteralPrefix   string
	PrefixComplete  bool
}

func Compile

func Compile(tree *syntax.Tree) (*Program, error)

func (*Program) AddInst

func (p *Program) AddInst(inst Inst) int

func (*Program) HasWordBoundary

func (p *Program) HasWordBoundary() bool

type Range

type Range struct {
	Lo, Hi rune
}

Jump to

Keyboard shortcuts

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