Documentation ¶
Index ¶
- Variables
- func GetOperatorValues(ops []Operator) []string
- type Modifier
- type Operator
- type Operators
- func (o *Operators) AddOperator(key string, op Operator)
- func (o *Operators) AddRemainder(str ...string)
- func (o *Operators) Equals(b *Operators) bool
- func (o *Operators) Get(keys ...string) []Operator
- func (o *Operators) GetOperator(key string) []Operator
- func (o *Operators) GetOperatorValues(key string) []string
- type ParseMapKeyError
- type ParseMatchError
- type ParseRegexpError
- type Parser
- type ParserConfig
- func (c *ParserConfig) ParseMapKey(inputKey string) (mods []Modifier, key string, err error)
- func (c *ParserConfig) ParseMatch(match []string) (mods []Modifier, key string, value []string, err error)
- func (c *ParserConfig) Regexp() (r *regexp.Regexp, err error)
- func (c *ParserConfig) SetDefaultModifiers(m ...Modifier)
- type ParserDelegateSatDefaultModifiers
- type ParserRegexpDelegate
Constants ¶
This section is empty.
Variables ¶
var (
ErrInvalidDelegate = errors.New("invalid delegate")
)
var (
ErrParserInvalidMatch = errors.New("could not parser regexp matches")
)
Functions ¶
func GetOperatorValues ¶
Types ¶
type Modifier ¶
type Modifier rune
var ( ModifierOr Modifier = '|' ModifierNot Modifier = '!' ModifierAnd Modifier = '&' Modifiers = []Modifier{ ModifierOr, ModifierNot, ModifierAnd, } )
Default Modifiers
type Operator ¶
type Operator struct { // Values representative of this operator. Values []string // Modifiers associated with the operator. Modifiers []Modifier }
Operator defines a set of values and modifiers that go along with those values. Most operators contain only a single value, but prepare to handle multiple values.
2022-09-28 - Note that this is a breaking change from previous versions.
type Operators ¶
type Operators struct { // Map of key to operator Values map[string][]Operator // Remainders Remainders []Operator // Any Errors related to parsing of the operator. Errors []error }
func (*Operators) AddOperator ¶
func (*Operators) AddRemainder ¶
func (*Operators) Equals ¶
Equals returns true of the provided operators is the same as the current one.
func (*Operators) GetOperator ¶
func (*Operators) GetOperatorValues ¶
type ParseMapKeyError ¶
type ParseMapKeyError struct { // The error in question Base error // InputKey which caused the error. InputKey string }
ParseMapKeyError is an error related to parsing of a map key. It wraps the error returned from ParserRegexpDelegate.ParseMapKey
type ParseMatchError ¶
type ParseMatchError struct { // Matches that were returned, if any. Matches []string // The error in question Base error }
ParseMatchError is an error related to the parsing of a match. It wraps the error returned from ParserRegexpDelegate.ParseMatch
type ParseRegexpError ¶
type ParseRegexpError struct { // The error in question Base error }
ParseRegexpError occurs when regexp could not be parsed properly for Parser.Parse.
type Parser ¶
type Parser struct { // Delegate modifies the operation of the parser. // // TODO: Currently, only a Regexp parser is supported, but in the future, this should be extracted to extended to // allow for other types of parsers. Delegate ParserRegexpDelegate }
Parser parses maps/strings into operators using the provided delegate to modify its behaviour. Currently, the only delegate possible is the Regexp delegate. This delegate will ParseMatch based on a Regexp returned by the delegate and a corresponding ParseMatch function.
func NewParser ¶
NewParser generates a new parser based on the provided delegate. If defined, it will also set default modifiers.
Unfortunately, the delegate does not work because we used to take in ParserConfig (note: missing the pointer). However, it currently wants &ParserConfig. Thus, we use interface{}.
func (*Parser) Parse ¶
Parse parses a string into operators based on the regexp generated from the parser config.
type ParserConfig ¶
type ParserConfig struct { // String start and end characters. StringStart string StringEnd string // Key delimiting character KeyDelimiter string // List of modifier runes. Modifiers []Modifier // contains filtered or unexported fields }
ParserConfig implements ParserRegexpDelegate. It looks for operators of the form
[modifier-character][key][key-delimiter][str-start][stuff][str-end]
For example, if StringStart and StringEnd were " and the keyDelimiter was =, an example operator would be
key="value" !key="value"
The key and the string delimiters are optional.
Naming of ParserConfig is to ensure backwards compatibility for users that still use this. In the future, it will be changed to DefaultParserDelegate.
@DEPRECATED
func (*ParserConfig) ParseMapKey ¶
func (c *ParserConfig) ParseMapKey(inputKey string) (mods []Modifier, key string, err error)
ParseMapKey decodes the input key by splitting out its modifiers.This is used for the Parser.ParseMap functionality.
func (*ParserConfig) ParseMatch ¶
func (c *ParserConfig) ParseMatch(match []string) (mods []Modifier, key string, value []string, err error)
ParseMatch parses the provided match to return: - modifiers - key - value
Match has the same values as regexp.FindSubmatchString
func (*ParserConfig) Regexp ¶
func (c *ParserConfig) Regexp() (r *regexp.Regexp, err error)
Regexp function should return a single regular expression which parses for 1 operator, keeping in mind remainders and modifiers.
func (*ParserConfig) SetDefaultModifiers ¶
func (c *ParserConfig) SetDefaultModifiers(m ...Modifier)
type ParserDelegateSatDefaultModifiers ¶
type ParserDelegateSatDefaultModifiers interface { // SetDefaultModifiers should store the provided modifiers as the modifiers used in the REGEXP and the ParseMapKey // function IF another set of modifiers hasn't already been set. SetDefaultModifiers(m ...Modifier) }
ParserDelegateSatDefaultModifiers is an optional interface allowing setting of "default" modifiers (e.g., in the case none are provided). This is for backwards compatibility and will be removed in the future.
@DEPRECATED
type ParserRegexpDelegate ¶
type ParserRegexpDelegate interface { // Regexp function should return a single regular expression which parses for 1 operator, keeping in mind // remainders and modifiers. Regexp() (*regexp.Regexp, error) // ParseMatch parses the provided match to return: // - modifiers // - key // - value // // Depending on the return values, the Parser will either: // - exclude it // - include it as an operator // - include it as a remainder. ParseMatch(match []string) (mods []Modifier, key string, value []string, err error) // ParseMapKey decodes the input key by splitting out its modifiers.This is used for the Parser.ParseMap // functionality. ParseMapKey(inputKey string) (mods []Modifier, key string, err error) }
ParserRegexpDelegate is an interface that the Parser uses to help perform its work in producing operators. The Parser will delegate responsibility to the provided implementation.