-
Notifications
You must be signed in to change notification settings - Fork 0
/
field_matcher.go
37 lines (33 loc) · 1.35 KB
/
field_matcher.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package hypermatch
type fieldMatcher struct {
Transitions map[string]*valueMatcher `json:"t,omitempty"`
MatchingRuleIdentifiers []RuleIdentifier `json:"m,omitempty"`
MatchingAnythingButRuleIdentifiers []RuleIdentifier `json:"n,omitempty"`
AnythingButTransitions map[string]map[RuleIdentifier]*fieldMatcher `json:"o,omitempty"`
Exclusive bool `json:"e,omitempty"`
}
func newFieldMatcher() *fieldMatcher {
return &fieldMatcher{
Transitions: make(map[string]*valueMatcher),
MatchingRuleIdentifiers: nil,
MatchingAnythingButRuleIdentifiers: nil,
AnythingButTransitions: nil,
}
}
func (f *fieldMatcher) AddAnythingButTransition(id RuleIdentifier, path string, fm *fieldMatcher) {
if f.AnythingButTransitions == nil {
f.AnythingButTransitions = make(map[string]map[RuleIdentifier]*fieldMatcher)
}
if _, ok := f.AnythingButTransitions[path]; !ok {
f.AnythingButTransitions[path] = make(map[RuleIdentifier]*fieldMatcher)
}
f.AnythingButTransitions[path][id] = fm
}
func (f *fieldMatcher) GetTransition(key string) *valueMatcher {
vm, ok := f.Transitions[key]
if !ok {
vm = newValueMatcher()
f.Transitions[key] = vm
}
return vm
}