Documentation
¶
Overview ¶
package meg implements Regular Expressions for multiaddr Components. It's short for "Megular Expressions"
Index ¶
- Variables
- func Match[L ListOfMatchable](matcher Matcher, components L) (bool, error)
- type CaptureFunc
- type ListOfMatchable
- 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 ¶
func Match[L ListOfMatchable](matcher Matcher, components L) (bool, error)
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.
Components must be a ListOfMatchable to allow us to use a slice of []T as a []Matchable when *T implements Matchable.
Types ¶
type CaptureFunc ¶
type ListOfMatchable ¶
ListOfMatchable is anything list-like that contains Matchable items. This allows us to convert a slice of []T as a []Matchable when *T implements Matchable. In the future, this may not be required if Go generics allows us to say S ~[]T, and *T implements Matchable. This may also not be required if we move this out of its own package and depend on Multiaddr and Components directly.
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