Documentation
¶
Overview ¶
Example (ExtractStrings) ¶
es := func(cond string) { root, err := parseCondition(cond) if err != nil { panic(err) } str, positive := extractStrings(root) fmt.Printf("----- %s -----\n", cond) fmt.Printf("strings: %+v\n", str) fmt.Printf("positive: %t\n", positive) } es(`"foo"`) es(`"foo" AND "bar"`) es(`"foo" OR "bar"`) es(`NOT "foo"`) es(`"foo" AND NOT "bar"`) es(`"foo" OR NOT "bar"`) es(`NOT ("foo" OR "bar")`) es(`NOT ("foo" AND "bar")`) es(`NOT ("foo" OR NOT "bar")`) es(`NOT ("foo" AND NOT "bar")`)
Output: ----- "foo" ----- strings: [foo] positive: true ----- "foo" AND "bar" ----- strings: [foo bar] positive: true ----- "foo" OR "bar" ----- strings: [foo bar] positive: true ----- NOT "foo" ----- strings: [foo] positive: false ----- "foo" AND NOT "bar" ----- strings: [foo bar] positive: true ----- "foo" OR NOT "bar" ----- strings: [foo bar] positive: false ----- NOT ("foo" OR "bar") ----- strings: [foo bar] positive: false ----- NOT ("foo" AND "bar") ----- strings: [foo bar] positive: false ----- NOT ("foo" OR NOT "bar") ----- strings: [foo bar] positive: true ----- NOT ("foo" AND NOT "bar") ----- strings: [foo bar] positive: false
Example (Parse) ¶
p := func(cond string) { t, err := tokenize(cond) if err != nil { panic(err) } root, err := parse(t) if err != nil { panic(err) } fmt.Printf("----- %s -----\n", cond) fmt.Println(root.String()) } p(`"foo"`) p(`"foo" AND "bar"`) p(`"foo" AND NOT "bar"`) p(`"foo" AND NOT ("bar" OR "baz")`)
Output: ----- "foo" ----- nodeVAL{"foo"} ----- "foo" AND "bar" ----- nodeAND{nodeVAL{"foo"},nodeVAL{"bar"}} ----- "foo" AND NOT "bar" ----- nodeAND{nodeVAL{"foo"},nodeNOT{nodeVAL{"bar"}}} ----- "foo" AND NOT ("bar" OR "baz") ----- nodeAND{nodeVAL{"foo"},nodeNOT{nodeOR{nodeVAL{"bar"},nodeVAL{"baz"}}}}
Example (Tokenize) ¶
tk := func(cond string) { tokens, err := tokenize(cond) if err != nil { panic(err) } fmt.Printf("----- %s -----\n", cond) for _, token := range tokens { fmt.Println(token.String()) } } tk(`"foo"`) tk(`"foo" AND "bar"`) tk(`"foo" AND ("bar" OR "baz")`) tk(`"foo" AND ("bar" OR NOT "baz")`) tk(`"escaped quote: \""`)
Output: ----- "foo" ----- nodeVAL ( foo ) at pos 1 ----- "foo" AND "bar" ----- nodeVAL ( foo ) at pos 1 nodeAND ( AND ) at pos 7 nodeVAL ( bar ) at pos 11 ----- "foo" AND ("bar" OR "baz") ----- nodeVAL ( foo ) at pos 1 nodeAND ( AND ) at pos 7 LPAR ( ( ) at pos 11 nodeVAL ( bar ) at pos 12 nodeOR ( OR ) at pos 18 nodeVAL ( baz ) at pos 21 RPAR ( ) ) at pos 26 ----- "foo" AND ("bar" OR NOT "baz") ----- nodeVAL ( foo ) at pos 1 nodeAND ( AND ) at pos 7 LPAR ( ( ) at pos 11 nodeVAL ( bar ) at pos 12 nodeOR ( OR ) at pos 18 nodeNOT ( NOT ) at pos 21 nodeVAL ( baz ) at pos 25 RPAR ( ) ) at pos 30 ----- "escaped quote: \"" ----- nodeVAL ( escaped quote: " ) at pos 1
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Evalostic ¶
type Evalostic struct {
// contains filtered or unexported fields
}
Evalostic is a matcher that can apply multiple conditions on a string with some performance optimizations. The biggest optimization is that only conditions that contain at least one keyword of the string will be checked, these strings will be filtered with the Aho-Corasick algorithm. The only exception are negative conditions (see comment of: Negatives() function).
Click to show internal directories.
Click to hide internal directories.