blob: c84b8afc64e35f7a6d0db114cdc22d78df18db5f (
plain)
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
72
73
74
|
package main
type StringSegmentPathFilterAST struct {
index string
}
func (ast StringSegmentPathFilterAST) compileWith(next PathFilterState) PathFilterState {
return StringSegmentPathFilter {
index: ast.index,
next: next,
}
}
type IntegerSegmentPathFilterAST struct {
index int
}
func (ast IntegerSegmentPathFilterAST) compileWith(next PathFilterState) PathFilterState {
return IntegerSegmentPathFilter {
index: ast.index,
next: next,
}
}
type RepeatPathFilterAST struct {
content PathFilterAST
}
func (ast RepeatPathFilterAST) compileWith(next PathFilterState) PathFilterState {
nextGroup := &OrPathFilter{}
repeatStart := ast.content.compileWith(nextGroup)
nextGroup.filters = [2]PathFilterState{next, repeatStart}
return nextGroup
}
type SequencePathFilterAST struct {
first PathFilterAST
second PathFilterAST
}
func (ast SequencePathFilterAST) compileWith(next PathFilterState) PathFilterState {
next = ast.second.compileWith(next)
next = ast.first.compileWith(next)
return next
}
type AnySegmentPathFilterAST struct {}
func (ast AnySegmentPathFilterAST) compileWith(next PathFilterState) PathFilterState {
return AnySegmentPathFilter{next: next}
}
type OrPathFilterAST struct {
first PathFilterAST
second PathFilterAST
}
func (ast OrPathFilterAST) compileWith(next PathFilterState) PathFilterState {
return OrPathFilter {
filters: [2]PathFilterState{
ast.first.compileWith(next),
ast.second.compileWith(next),
},
}
}
type NonePathFilterAST struct {}
func (ast NonePathFilterAST) compileWith(next PathFilterState) PathFilterState {
return next
}
type PathFilterAST interface {
compileWith(PathFilterState) PathFilterState
}
func compilePathFilterAST(ast PathFilterAST) PathFilter {
return PathFilter{
initial: ast.compileWith(NonePathFilter{}),
}
}
|