Documentation
¶
Overview ¶
package meg implements Regular Expressions for multiaddr Components. It's short for "Megular Expressions"
Index ¶
- Variables
- func Match[T any, PT interface{ ... }](matcher Matcher, components []T) (bool, error)
- type CaptureFunc
- type MatchState
- type Matchable
- type Matcher
- type Pattern
- func CaptureBytes(code int, val *[]byte) Pattern
- func CaptureOneOrMoreBytes(code int, vals *[][]byte) Pattern
- func CaptureOneOrMoreStrings(code int, vals *[]string) Pattern
- func CaptureString(code int, val *string) Pattern
- func CaptureWithF(code int, f CaptureFunc) Pattern
- func CaptureZeroOrMoreBytes(code int, vals *[][]byte) Pattern
- func CaptureZeroOrMoreStrings(code int, vals *[]string) Pattern
- func CaptureZeroOrMoreWithF(code int, f CaptureFunc) Pattern
- func Cat(patterns ...Pattern) Pattern
- func OneOrMore(code int) Pattern
- func Optional(s Pattern) Pattern
- func Or(p ...Pattern) Pattern
- func Val(code int) Pattern
- func ZeroOrMore(code int) Pattern
Constants ¶
This section is empty.
Variables ¶
var Any int = matchAny
Any is a special code that matches any value.
Functions ¶
func Match ¶
Match returns whether the given Components match the Matcher
Errors are used to communicate capture errors. If the error is non-nil the returned bool will be false.
The PT pattern is from: https://go.dev/blog/generic-interfaces
Types ¶
type CaptureFunc ¶
type MatchState ¶
type MatchState struct {
// contains filtered or unexported fields
}
MatchState is the Thompson NFA for a regular expression.
func (MatchState) String ¶
func (s MatchState) String() string
type Matchable ¶
type Matchable interface {
Code() int
// Value() returns the string representation of the matchable.
Value() string
// RawValue() returns the byte representation of the Value
RawValue() []byte
// Bytes() returns the underlying bytes of the matchable. For multiaddr
// Components, this includes the protocol code and possibly the varint
// encoded size.
Bytes() []byte
}
Matchable is an interface for any thing that can be matched against by this package. In the future, we may use multiaddr.Component types directly.
type Matcher ¶
type Matcher struct {
// contains filtered or unexported fields
}
Matcher holds a graph of match state nodes. Use PatternToMatcher to create.
func PatternToMatcher ¶
type Pattern ¶
type Pattern = func(states []MatchState, nextIdx int) ([]MatchState, int)
Pattern is a curried MatchState. Given the slice of current MatchStates and a handle (int index) to the next MatchState, it returns a (possibly modified) slice of next MatchStates and handle to the inserted MatchState.
func CaptureBytes ¶
func CaptureOneOrMoreBytes ¶
func CaptureOneOrMoreStrings ¶
func CaptureString ¶
func CaptureWithF ¶
func CaptureWithF(code int, f CaptureFunc) Pattern
func CaptureZeroOrMoreBytes ¶
func CaptureZeroOrMoreWithF ¶
func CaptureZeroOrMoreWithF(code int, f CaptureFunc) Pattern