-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathoption.go
More file actions
38 lines (31 loc) · 1.1 KB
/
Copy pathoption.go
File metadata and controls
38 lines (31 loc) · 1.1 KB
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
package sqlparser
import "github.com/viant/parsly"
type Options struct {
structuralValidation bool
onError func(err error, cur *parsly.Cursor, destNode interface{}) error
}
// WithStructuralValidation rejects unbalanced parentheses/subscripts and unclosed
// quotes/comments before parsing. It does not promise full dialect validation.
func WithStructuralValidation() Option {
return func(o *Options) { o.structuralValidation = true }
}
type Option func(o *Options)
func (o *Options) apply(opts []Option) {
for _, opt := range opts {
opt(o)
}
}
func newOptions(options []Option) *Options {
ret := &Options{}
ret.apply(options)
return ret
}
// WithErrorHandler extends syntax at parser-owned recovery points. For an
// unknown operand, destNode is *node.Node: a successful handler must assign a
// node and advance the cursor through exactly that operand. Nested argument
// and subquery cursors inherit the handler; unhandled errors must be returned.
func WithErrorHandler(fn func(err error, cur *parsly.Cursor, destNode interface{}) error) Option {
return func(o *Options) {
o.onError = fn
}
}