-
Notifications
You must be signed in to change notification settings - Fork 2
/
sequenceof9.go
76 lines (73 loc) · 1.44 KB
/
sequenceof9.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package parse
type sequenceOf9Parser[A, B, C, D, E, F, G, H, I any] struct {
A Parser[A]
B Parser[B]
C Parser[C]
D Parser[D]
E Parser[E]
F Parser[F]
G Parser[G]
H Parser[H]
I Parser[I]
}
func (p sequenceOf9Parser[A, B, C, D, E, F, G, H, I]) Parse(in *Input) (match Tuple9[A, B, C, D, E, F, G, H, I], ok bool, err error) {
start := in.Index()
match.A, ok, err = p.A.Parse(in)
if err != nil || !ok {
return
}
match.B, ok, err = p.B.Parse(in)
if err != nil || !ok {
in.Seek(start)
return
}
match.C, ok, err = p.C.Parse(in)
if err != nil || !ok {
in.Seek(start)
return
}
match.D, ok, err = p.D.Parse(in)
if err != nil || !ok {
in.Seek(start)
return
}
match.E, ok, err = p.E.Parse(in)
if err != nil || !ok {
in.Seek(start)
return
}
match.F, ok, err = p.F.Parse(in)
if err != nil || !ok {
in.Seek(start)
return
}
match.G, ok, err = p.G.Parse(in)
if err != nil || !ok {
in.Seek(start)
return
}
match.H, ok, err = p.H.Parse(in)
if err != nil || !ok {
in.Seek(start)
return
}
match.I, ok, err = p.I.Parse(in)
if err != nil || !ok {
in.Seek(start)
return
}
return
}
func SequenceOf9[A, B, C, D, E, F, G, H, I any](a Parser[A], b Parser[B], c Parser[C], d Parser[D], e Parser[E], f Parser[F], g Parser[G], h Parser[H], i Parser[I]) Parser[Tuple9[A, B, C, D, E, F, G, H, I]] {
return sequenceOf9Parser[A, B, C, D, E, F, G, H, I]{
A: a,
B: b,
C: c,
D: d,
E: e,
F: f,
G: g,
H: h,
I: i,
}
}