-
Notifications
You must be signed in to change notification settings - Fork 2.5k
/
Copy pathpaths.go
33 lines (27 loc) · 1.03 KB
/
paths.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
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0
package ottl // import "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl"
// grammarPathVisitor is used to extract all path from a parsedStatement or booleanExpression
type grammarPathVisitor struct {
paths []path
}
func (v *grammarPathVisitor) visitEditor(_ *editor) {}
func (v *grammarPathVisitor) visitConverter(_ *converter) {}
func (v *grammarPathVisitor) visitValue(_ *value) {}
func (v *grammarPathVisitor) visitMathExprLiteral(_ *mathExprLiteral) {}
func (v *grammarPathVisitor) visitPath(value *path) {
v.paths = append(v.paths, *value)
}
func getParsedStatementPaths(ps *parsedStatement) []path {
visitor := &grammarPathVisitor{}
ps.Editor.accept(visitor)
if ps.WhereClause != nil {
ps.WhereClause.accept(visitor)
}
return visitor.paths
}
func getBooleanExpressionPaths(be *booleanExpression) []path {
visitor := &grammarPathVisitor{}
be.accept(visitor)
return visitor.paths
}