syntax

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Mar 28, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Equal

func Equal(a, b []*Node) bool

func Graphviz

func Graphviz(pattern string, m Matcher) string

func IsSpecial

func IsSpecial(c byte) bool

func OneWithLeastChildren

func OneWithLeastChildren(nodes []*Node) int

func SameKind

func SameKind(nodes []*Node, kind Type) bool

Types

type AnyMatcher

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

func NewAny

func NewAny(s []rune) AnyMatcher

func (AnyMatcher) Index

func (m AnyMatcher) Index(s string) (int, []int)

func (AnyMatcher) Len

func (AnyMatcher) Len() int

func (AnyMatcher) Match

func (m AnyMatcher) Match(s string) bool

func (AnyMatcher) String

func (m AnyMatcher) String() string

type AnyOfMatcher

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

func (AnyOfMatcher) Content

func (m AnyOfMatcher) Content(f func(Matcher))

func (AnyOfMatcher) Len

func (m AnyOfMatcher) Len() (n int)

func (AnyOfMatcher) Match

func (m AnyOfMatcher) Match(s string) (ok bool)

func (AnyOfMatcher) String

func (m AnyOfMatcher) String() string

String satisfies the fmt.Stringer interface.

type Container

type Container interface {
	Content(func(Matcher))
}

type ContainsMatcher

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

func NewContains

func NewContains(needle string) ContainsMatcher

func NewNotContains

func NewNotContains(needle string) ContainsMatcher

func (ContainsMatcher) Index

func (m ContainsMatcher) Index(s string) (int, []int)

func (ContainsMatcher) Len

func (m ContainsMatcher) Len() int

func (ContainsMatcher) Match

func (m ContainsMatcher) Match(s string) bool

func (ContainsMatcher) String

func (m ContainsMatcher) String() string

String satisfies the fmt.Stringer interface.

type EveryOfMatcher

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

func (EveryOfMatcher) Content

func (m EveryOfMatcher) Content(f func(Matcher))

func (EveryOfMatcher) Len

func (m EveryOfMatcher) Len() (n int)

func (EveryOfMatcher) Match

func (m EveryOfMatcher) Match(s string) bool

func (EveryOfMatcher) String

func (m EveryOfMatcher) String() string

String satisfies the fmt.Stringer interface.

type IndexedAnyOfMatcher

type IndexedAnyOfMatcher struct {
	AnyOfMatcher
	// contains filtered or unexported fields
}

func (IndexedAnyOfMatcher) Index

func (m IndexedAnyOfMatcher) Index(s string) (index int, segments []int)

func (IndexedAnyOfMatcher) String

func (m IndexedAnyOfMatcher) String() string

String satisfies the fmt.Stringer interface.

type IndexedEveryOf

type IndexedEveryOf struct {
	EveryOfMatcher
	// contains filtered or unexported fields
}

func (IndexedEveryOf) Index

func (m IndexedEveryOf) Index(s string) (int, []int)

func (IndexedEveryOf) String

func (m IndexedEveryOf) String() string

String satisfies the fmt.Stringer interface.

type IndexedSizedAnyOfMatcher

type IndexedSizedAnyOfMatcher struct {
	IndexedAnyOfMatcher
	// contains filtered or unexported fields
}

func (IndexedSizedAnyOfMatcher) Size

func (m IndexedSizedAnyOfMatcher) Size() int

type IndexedTreeMatcher

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

type Indexer

type Indexer interface {
	Index(string) (int, []int)
}

type Lexer

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

func NewLexer

func NewLexer(src string) *Lexer

func (*Lexer) Next

func (l *Lexer) Next() Token

type ListData

type ListData struct {
	Not   bool
	Chars string
}

type ListMatcher

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

func NewList

func NewList(rs []rune, not bool) ListMatcher

func (ListMatcher) Index

func (m ListMatcher) Index(s string) (int, []int)

func (ListMatcher) Len

func (ListMatcher) Len() int

func (ListMatcher) Match

func (m ListMatcher) Match(s string) bool

func (ListMatcher) Size

func (ListMatcher) Size() int

func (ListMatcher) String

func (m ListMatcher) String() string

String satisfies the fmt.Stringer interface.

type MatchIndexSizer

type MatchIndexSizer interface {
	Matcher
	Indexer
	Sizer
}

func MatchIndexSizers

func MatchIndexSizers(v []Matcher) ([]MatchIndexSizer, bool)

func MustIndexedSizedAnyOf

func MustIndexedSizedAnyOf(v ...Matcher) MatchIndexSizer

type MatchIndexer

type MatchIndexer interface {
	Matcher
	Indexer
}

func MatchIndexers

func MatchIndexers(v []Matcher) ([]MatchIndexer, bool)

func MustIndexedAnyOf

func MustIndexedAnyOf(v ...Matcher) MatchIndexer

type MatchSizer

type MatchSizer interface {
	Matcher
	Sizer
}

type Matcher

type Matcher interface {
	Match(string) bool
	Len() int
}

func BuildMatcher

func BuildMatcher(matchers []Matcher) (m Matcher, err error)

func MinimizeMatcher

func MinimizeMatcher(ms []Matcher) (m []Matcher)

func NewAnyOf

func NewAnyOf(v ...Matcher) Matcher

func NewEveryOf

func NewEveryOf(ms []Matcher) Matcher

func NewTree

func NewTree(v MatchIndexer, l, r Matcher) Matcher

func Optimize

func Optimize(m Matcher) (opt Matcher)

type Matchers

type Matchers []Matcher

func (Matchers) String

func (matchers Matchers) String() string

String satisfies the fmt.Stringer interface.

type MaxMatcher

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

func NewMax

func NewMax(n int) MaxMatcher

func (MaxMatcher) Index

func (m MaxMatcher) Index(s string) (int, []int)

func (MaxMatcher) Len

func (m MaxMatcher) Len() int

func (MaxMatcher) Match

func (m MaxMatcher) Match(s string) bool

func (MaxMatcher) String

func (m MaxMatcher) String() string

String satisfies the fmt.Stringer interface.

type MinMatcher

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

func NewMin

func NewMin(n int) MinMatcher

func (MinMatcher) Index

func (m MinMatcher) Index(s string) (int, []int)

func (MinMatcher) Len

func (m MinMatcher) Len() int

func (MinMatcher) Match

func (m MinMatcher) Match(s string) bool

func (MinMatcher) String

func (m MinMatcher) String() string

String satisfies the fmt.Stringer interface.

type Node

type Node struct {
	Parent   *Node
	Type     Type
	Value    any
	Children []*Node
}

func AppendUnique

func AppendUnique(target []*Node, val *Node) []*Node

func CommonChildren

func CommonChildren(nodes []*Node) (commonLeft, commonRight []*Node)

func Minimize

func Minimize(t *Node) *Node

Minimize applies heuristics to minimize the number of nodes in t.

func New

func New(typ Type, v any, ch ...*Node) *Node

New creates a new node of type.

func Parse

func Parse(l *Lexer) (*Node, error)

Parse builds a tree from the tokens read from the lexer.

func (*Node) Equal

func (node *Node) Equal(n *Node) bool

func (*Node) Insert

func (node *Node) Insert(children ...*Node)

Insert inserts a child node.

func (*Node) Match

func (node *Node) Match(sep []rune) (Matcher, error)

Match builds the matcher for the node.

func (*Node) String

func (node *Node) String() string

type NothingMatcher

type NothingMatcher struct{}

func NewNothing

func NewNothing() NothingMatcher

func (NothingMatcher) Index

func (NothingMatcher) Index(s string) (int, []int)

func (NothingMatcher) Len

func (NothingMatcher) Len() int

func (NothingMatcher) Match

func (NothingMatcher) Match(s string) bool

func (NothingMatcher) Size

func (NothingMatcher) Size() int

func (NothingMatcher) String

func (NothingMatcher) String() string

String satisfies the fmt.Stringer interface.

type PrefixAnyMatcher

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

func NewPrefixAny

func NewPrefixAny(s string, sep []rune) PrefixAnyMatcher

func (PrefixAnyMatcher) Index

func (m PrefixAnyMatcher) Index(s string) (int, []int)

func (PrefixAnyMatcher) Len

func (m PrefixAnyMatcher) Len() int

func (PrefixAnyMatcher) Match

func (m PrefixAnyMatcher) Match(s string) bool

func (PrefixAnyMatcher) String

func (m PrefixAnyMatcher) String() string

String satisfies the fmt.Stringer interface.

type PrefixMatcher

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

func NewPrefix

func NewPrefix(p string) PrefixMatcher

func (PrefixMatcher) Index

func (m PrefixMatcher) Index(s string) (int, []int)

func (PrefixMatcher) Len

func (m PrefixMatcher) Len() int

func (PrefixMatcher) Match

func (m PrefixMatcher) Match(s string) bool

func (PrefixMatcher) String

func (m PrefixMatcher) String() string

String satisfies the fmt.Stringer interface.

type PrefixSuffixMatcher

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

func NewPrefixSuffix

func NewPrefixSuffix(prefix, suffix string) PrefixSuffixMatcher

func (PrefixSuffixMatcher) Index

func (m PrefixSuffixMatcher) Index(s string) (int, []int)

func (PrefixSuffixMatcher) Len

func (m PrefixSuffixMatcher) Len() int

func (PrefixSuffixMatcher) Match

func (m PrefixSuffixMatcher) Match(s string) bool

func (PrefixSuffixMatcher) String

func (m PrefixSuffixMatcher) String() string

String satisfies the fmt.Stringer interface.

type RangeData

type RangeData struct {
	Not    bool
	Lo, Hi rune
}

type RangeMatcher

type RangeMatcher struct {
	Lo, Hi rune
	Not    bool
}

func NewRange

func NewRange(lo, hi rune, not bool) RangeMatcher

func (RangeMatcher) Index

func (m RangeMatcher) Index(s string) (index int, segments []int)

func (RangeMatcher) Len

func (RangeMatcher) Len() int

func (RangeMatcher) Match

func (m RangeMatcher) Match(s string) (ok bool)

func (RangeMatcher) Size

func (RangeMatcher) Size() int

func (RangeMatcher) String

func (m RangeMatcher) String() string

String satisfies the fmt.Stringer interface.

type RowMatcher

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

func NewRow

func NewRow(ms []MatchIndexSizer) RowMatcher

func (RowMatcher) Content

func (m RowMatcher) Content(f func(Matcher))

func (RowMatcher) Index

func (m RowMatcher) Index(s string) (index int, segments []int)

func (RowMatcher) Len

func (m RowMatcher) Len() int

func (RowMatcher) Match

func (m RowMatcher) Match(s string) (ok bool)

func (RowMatcher) Size

func (m RowMatcher) Size() int

func (RowMatcher) String

func (m RowMatcher) String() string

String satisfies the fmt.Stringer interface.

type SingleMatcher

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

single represents ?

func NewSingle

func NewSingle(s []rune) SingleMatcher

func (SingleMatcher) Index

func (m SingleMatcher) Index(v string) (int, []int)

func (SingleMatcher) Len

func (SingleMatcher) Len() int

func (SingleMatcher) Match

func (m SingleMatcher) Match(v string) bool

func (SingleMatcher) Size

func (SingleMatcher) Size() int

func (SingleMatcher) String

func (m SingleMatcher) String() string

String satisfies the fmt.Stringer interface.

type SizedTreeMatcher

type SizedTreeMatcher struct {
	TreeMatcher
}

func (SizedTreeMatcher) Size

func (m SizedTreeMatcher) Size() int

type Sizer

type Sizer interface {
	Size() int
}

type SomePool

type SomePool interface {
	Get() []int
	Put([]int)
}

type SuffixAnyMatcher

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

func NewSuffixAny

func NewSuffixAny(s string, sep []rune) SuffixAnyMatcher

func (SuffixAnyMatcher) Index

func (m SuffixAnyMatcher) Index(v string) (int, []int)

func (SuffixAnyMatcher) Len

func (m SuffixAnyMatcher) Len() int

func (SuffixAnyMatcher) Match

func (m SuffixAnyMatcher) Match(v string) bool

func (SuffixAnyMatcher) String

func (m SuffixAnyMatcher) String() string

String satisfies the fmt.Stringer interface.

type SuffixMatcher

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

func NewSuffix

func NewSuffix(s string) SuffixMatcher

func (SuffixMatcher) Index

func (m SuffixMatcher) Index(v string) (int, []int)

func (SuffixMatcher) Len

func (m SuffixMatcher) Len() int

func (SuffixMatcher) Match

func (m SuffixMatcher) Match(v string) bool

func (SuffixMatcher) String

func (m SuffixMatcher) String() string

String satisfies the fmt.Stringer interface.

type SuperMatcher

type SuperMatcher struct{}

func NewSuper

func NewSuper() SuperMatcher

func (SuperMatcher) Index

func (m SuperMatcher) Index(v string) (int, []int)

func (SuperMatcher) Len

func (m SuperMatcher) Len() int

func (SuperMatcher) Match

func (m SuperMatcher) Match(_ string) bool

func (SuperMatcher) String

func (m SuperMatcher) String() string

String satisfies the fmt.Stringer interface.

type TextData

type TextData struct {
	Text string
}

type TextMatcher

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

TextMatcher represents raw string to match

func NewText

func NewText(s string) TextMatcher

func (TextMatcher) BytesCount

func (m TextMatcher) BytesCount() int

func (TextMatcher) Index

func (m TextMatcher) Index(s string) (int, []int)

func (TextMatcher) Len

func (m TextMatcher) Len() int

func (TextMatcher) Match

func (m TextMatcher) Match(s string) bool

func (TextMatcher) Size

func (m TextMatcher) Size() int

func (TextMatcher) String

func (m TextMatcher) String() string

String satisfies the fmt.Stringer interface.

type Token

type Token struct {
	Token TokenType
	Raw   string
}

func (Token) String

func (token Token) String() string

type TokenType

type TokenType int
const (
	TokenEOF TokenType = iota
	TokenError
	TokenText
	TokenChar
	TokenAny
	TokenSuper
	TokenSingle
	TokenNot
	TokenSeparator
	TokenRangeOpen
	TokenRangeClose
	TokenRangeLo
	TokenRangeHi
	TokenRangeBetween
	TokenTermsOpen
	TokenTermsClose
)

func (TokenType) String

func (typ TokenType) String() string

type TreeMatcher

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

func (TreeMatcher) Content

func (m TreeMatcher) Content(f func(Matcher))

func (TreeMatcher) Len

func (m TreeMatcher) Len() int

func (TreeMatcher) Match

func (m TreeMatcher) Match(s string) (ok bool)

func (TreeMatcher) String

func (m TreeMatcher) String() string

String satisfies the fmt.Stringer interface.

type Type

type Type int
const (
	Nothing Type = iota
	Pattern
	List
	Range
	Text
	Any
	Super
	Single
	AnyOf
)

func (Type) String

func (typ Type) String() string

Jump to

Keyboard shortcuts

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