-
Notifications
You must be signed in to change notification settings - Fork 3
/
sieve.go
60 lines (50 loc) · 1.15 KB
/
sieve.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
package sieve
import (
"io"
"github.com/foxcpp/go-sieve/interp"
"github.com/foxcpp/go-sieve/lexer"
"github.com/foxcpp/go-sieve/parser"
)
type (
Script = interp.Script
RuntimeData = interp.RuntimeData
PolicyReader = interp.PolicyReader
Message = interp.Message
Envelope = interp.Envelope
Options struct {
Lexer lexer.Options
Parser parser.Options
Interp interp.Options
}
)
func DefaultOptions() Options {
return Options{
Lexer: lexer.Options{
MaxTokens: 5000,
},
Parser: parser.Options{
MaxBlockNesting: 15,
MaxTestNesting: 15,
},
Interp: interp.Options{
MaxRedirects: 5,
MaxVariableCount: 128,
MaxVariableNameLen: 32,
MaxVariableLen: 4000,
},
}
}
func Load(r io.Reader, opts Options) (*Script, error) {
toks, err := lexer.Lex(r, &opts.Lexer)
if err != nil {
return nil, err
}
cmds, err := parser.Parse(lexer.NewStream(toks), &opts.Parser)
if err != nil {
return nil, err
}
return interp.LoadScript(cmds, &opts.Interp)
}
func NewRuntimeData(s *Script, p interp.PolicyReader, e interp.Envelope, msg interp.Message) *interp.RuntimeData {
return interp.NewRuntimeData(s, p, e, msg)
}