factors

package
v0.0.0 Latest Latest
Warning

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

Go to latest
Published: Mar 22, 2021 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var RegexpOpCodeTable = []string{
	"",
	"NoMatch",
	"EmptyMatch",
	"Literal",
	"CC",
	"AnyCharNL",
	"AnyChar",
	"^",
	"$",
	"\\A",
	"$",
	"\\b",
	"\\B",
	"()",
	"*",
	"+",
	"?",
	"RT",
	"・",
	"|",
}

RegexpOpCodeTable is a set of regexp operations.

Functions

This section is empty.

Types

type Analyzer

type Analyzer struct{}

Analyzer is a regexp necessary factor analyzer.

func NewAnalyzer

func NewAnalyzer() *Analyzer

NewAnalyzer creates new analyzer.

func (Analyzer) DebugParse

func (a Analyzer) DebugParse(w io.Writer, re *syntax.Regexp) Factor

DebugParse parses necessary factors for a given regexp, and writes a it's parse tree in dot format.

func (Analyzer) Factor

func (a Analyzer) Factor(re *syntax.Regexp) Factor

Factor returns necessary factors for a given regexp.

func (Analyzer) Parse

func (a Analyzer) Parse(re *syntax.Regexp) *Node

Parse parses necessary factors for a given regexp, and returns a it's parse tree.

type Edge

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

Edge represents a edge.

type Factor

type Factor struct {
	Exact    Set
	Prefix   Set
	Suffix   Set
	Fragment Set
}

Factor represents a tuple of necessary factors for a regexp.

func Alternate

func Alternate(a, b Factor) Factor

Alternate represents `a|b`

func Concatenate

func Concatenate(a, b Factor) Factor

Concatenate represents `a・b`

func NewFactor

func NewFactor() Factor

NewFactor creates a factor tuple.

func NewFactorAnyChar

func NewFactorAnyChar() Factor

NewFactorAnyChar creates a factor tuple initialized with regexp "any char".

func NewFactorInfinite

func NewFactorInfinite() Factor

NewFactorInfinite creates a factor tuple each factor set is infinite.

func NewFactorLiteral

func NewFactorLiteral(literal string) Factor

NewFactorLiteral creates a factor tuple initialized with a given literal.

func (*Factor) Add

func (f *Factor) Add(literal string)

Add adds a literal to each factor set.

func (Factor) Infinite

func (f Factor) Infinite() bool

Infinite returns true if there is a infinite set in the tuple.

func (Factor) String

func (f Factor) String() string

String returns string representation of a tuple.

type Node

type Node struct {
	Factor   Factor
	Regexp   *syntax.Regexp
	Child    []*Node
	Internal bool
}

Node represents a node of a parse tree.

func (*Node) Dot

func (n *Node) Dot(w io.Writer)

Dot writes a node in dot format.

func (Node) String

func (n Node) String() string

String returns string representation of a node.

type Op

type Op syntax.Op

Op is systax.Op.

func (Op) String

func (o Op) String() string

String is a string representation of the regexp operation.

type Set

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

Set represents a set of necessary factors.

func BestSet

func BestSet(arg Set, args ...Set) Set

BestSet chooses the best set from the given sets.

func CrossSet

func CrossSet(x, y Set) Set

CrossSet returns a cross set of x and y. e.g. CrossSet {a, bc} and {xy, z} -> {axy, az, bcxy, bcz}

func NewSet

func NewSet(items ...string) Set

NewSet creates a set initialized given items.

func UnionSet

func UnionSet(x, y Set) Set

UnionSet returns a union set of x and y.

func (*Set) Add

func (s *Set) Add(item string)

Add adds a item to the set.

func (*Set) Clear

func (s *Set) Clear()

Clear clears the set.

func (*Set) DropRedundantFragment

func (s *Set) DropRedundantFragment()

DropRedundantFragment drops items which contains of other item in this set.

func (*Set) DropRedundantPrefix

func (s *Set) DropRedundantPrefix()

DropRedundantPrefix drops items which has prefix of other item in this set.

func (*Set) DropRedundantSuffix

func (s *Set) DropRedundantSuffix()

DropRedundantSuffix drops items which has suffix of other item in this set.

func (Set) Infinite

func (s Set) Infinite() bool

Infinite returns true if this set is infinite.

func (Set) Items

func (s Set) Items() []string

Items returns (sorted) items of the set.

func (Set) Len

func (s Set) Len() int

Len returns a size of this set.

func (Set) LongestCommon

func (s Set) LongestCommon() string

LongestCommon returns the longest common substring of items in the set.

func (*Set) SetInfinite

func (s *Set) SetInfinite()

SetInfinite sets this set infinite.

func (Set) String

func (s Set) String() string

String returns string represents of this set.

Jump to

Keyboard shortcuts

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