-
Notifications
You must be signed in to change notification settings - Fork 4
/
parse.go
152 lines (146 loc) · 2.72 KB
/
parse.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
// Code generated by re2c 3.1, DO NOT EDIT.
// -*-go-*-
//
//go:generate re2go parser.re -o parser.go -i
package goami2
import "fmt"
// Parse AMI message as string into *Message structure
func Parse(data string) (*Message, error) {
msg := NewMessage()
var cur, mar int
var ns, ne, vs, ve int
var yyt1 int
var yyt2 int
var yyt3 int
for {
{
var yych byte
if (len(data) <= cur) {
return nil, fmt.Errorf("%w: unexpected end of input", ErrAMI)
}
yych = data[cur]
switch (yych) {
case '\r':
goto yy3
case '0','1','2','3','4','5','6','7','8','9':
fallthrough
case 'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z':
fallthrough
case 'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z':
yyt1 = cur
goto yy4
default:
goto yy1
}
yy1:
cur += 1
yy2:
{ break }
yy3:
cur += 1
yych = data[cur]
switch (yych) {
case '\n':
goto yy5
default:
goto yy2
}
yy4:
cur += 1
mar = cur
yych = data[cur]
switch (yych) {
case '-':
fallthrough
case '0','1','2','3','4','5','6','7','8','9':
fallthrough
case 'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z':
fallthrough
case 'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z':
goto yy6
default:
goto yy2
}
yy5:
cur += 1
{ return msg, nil }
yy6:
cur += 1
if (len(data) <= cur) {
return nil, fmt.Errorf("%w: unexpected end of input", ErrAMI)
}
yych = data[cur]
switch (yych) {
case '-':
fallthrough
case '0','1','2','3','4','5','6','7','8','9':
fallthrough
case 'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z':
fallthrough
case 'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z':
goto yy6
case ':':
yyt2 = cur
goto yy8
default:
goto yy7
}
yy7:
cur = mar
goto yy2
yy8:
cur += 1
if (len(data) <= cur) {
return nil, fmt.Errorf("%w: unexpected end of input", ErrAMI)
}
yych = data[cur]
switch (yych) {
case '\n':
goto yy7
case '\r':
yyt3 = cur
goto yy10
case ' ':
goto yy8
default:
yyt3 = cur
goto yy9
}
yy9:
cur += 1
if (len(data) <= cur) {
return nil, fmt.Errorf("%w: unexpected end of input", ErrAMI)
}
yych = data[cur]
switch (yych) {
case '\n':
goto yy7
case '\r':
goto yy10
default:
goto yy9
}
yy10:
cur += 1
yych = data[cur]
switch (yych) {
case '\n':
goto yy11
default:
goto yy7
}
yy11:
cur += 1
ns = yyt1
ne = yyt2
vs = yyt3
ve = cur
ve += -2
{
msg.AddField(data[ns:ne], data[vs:ve])
}
}
}
return nil, fmt.Errorf("%w: invalid input: %q", ErrAMI, data[cur:])
}
// vi: ft=go