-
Notifications
You must be signed in to change notification settings - Fork 0
/
compile_filters.go
71 lines (60 loc) · 1.52 KB
/
compile_filters.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
// Copyright (c) 2019, AT&T Intellectual Property. All rights reserved.
//
// Copyright (c) 2017 by Brocade Communications Systems, Inc.
// All rights reserved.
//
// SPDX-License-Identifier: MPL-2.0
package compile
import (
"github.com/sdcio/yang-parser/schema"
)
type SchemaFilter func(sn schema.Node) bool
// Filter configuration nodes
func IsConfig(sn schema.Node) bool {
return sn.Config()
}
// Filter opd: extension nodes
func IsOpd(sn schema.Node) bool {
switch sn.(type) {
case schema.OpdCommand, schema.OpdArgument, schema.OpdOption:
return true
}
return false
}
// Filter operational state nodes, which are config false
func IsState(sn schema.Node) bool {
return !IsConfig(sn) && !IsOpd(sn)
}
// Filter configuration and operational state nodes
func IsConfigOrState() SchemaFilter {
return Include(IsConfig, IsState)
}
// Returns a filter which will include nodes that match a set of filters
func Include(filters ...SchemaFilter) SchemaFilter {
return func(sn schema.Node) bool {
for _, fltr := range filters {
if fltr != nil && fltr(sn) {
return true
}
}
return false
}
}
// Returns a filter which will exclude nodes that match a set of filters
func Exclude(filters ...SchemaFilter) SchemaFilter {
return func(sn schema.Node) bool {
for _, fltr := range filters {
if fltr != nil && fltr(sn) {
return false
}
}
return true
}
}
// Returns an operational state node filter if state is true
func IncludeState(state bool) SchemaFilter {
if state {
return IsState
}
return Exclude(IsState)
}