forked from redpanda-data/connect
-
Notifications
You must be signed in to change notification settings - Fork 0
/
query_parser.go
37 lines (34 loc) · 856 Bytes
/
query_parser.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 parser
import (
"github.com/dafanshu/benthos/v4/internal/bloblang/query"
)
func queryParser(pCtx Context) Func {
rootParser := parseWithTails(Expect(
OneOf(
matchExpressionParser(pCtx),
ifExpressionParser(pCtx),
lambdaExpressionParser(pCtx),
bracketsExpressionParser(pCtx),
literalValueParser(pCtx),
functionParser(pCtx),
metadataLiteralParser(),
variableLiteralParser(),
fieldLiteralRootParser(pCtx),
),
"query",
), pCtx)
return func(input []rune) Result {
res := SpacesAndTabs()(input)
return arithmeticParser(rootParser)(res.Remaining)
}
}
func tryParseQuery(expr string) (query.Function, *Error) {
res := queryParser(Context{
Functions: query.AllFunctions,
Methods: query.AllMethods,
})([]rune(expr))
if res.Err != nil {
return nil, res.Err
}
return res.Payload.(query.Function), nil
}