This repository has been archived by the owner on Nov 22, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
parser.go
492 lines (441 loc) · 8.78 KB
/
parser.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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
// Copyright (c) 2011 CZ.NIC z.s.p.o. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// blame: jnml, labs.nic.cz
// WARNING: If this file is parser.go then DO NOT EDIT.
// parser.go is generated by goyacc from parser.y (see the Makefile).
package resolv
import __yyfmt__ "fmt"
import (
"fmt"
"net"
)
type yySymType struct {
yys int
ip net.IP
num uint
str string
list []string
mask SortlistItem
}
const tDOMAIN = 57346
const tNAMESERVER = 57347
const tOPTIONS = 57348
const tSEARCH = 57349
const tSORTLIST = 57350
const tATTEMPTS = 57351
const tDEBUG = 57352
const tEDNS0 = 57353
const tINET6 = 57354
const tIP6_BYTESTRING = 57355
const tIP6_DOTINT = 57356
const tNDOTS = 57357
const tNO_CHECK_NAMES = 57358
const tNO_IP6_DOTINT = 57359
const tROTATE = 57360
const tTIMEOUT = 57361
const tIP_ADDRESS = 57362
const tDECADIC = 57363
const tDOMAIN_NAME = 57364
var yyToknames = []string{
"tDOMAIN",
"tNAMESERVER",
"tOPTIONS",
"tSEARCH",
"tSORTLIST",
"tATTEMPTS",
"tDEBUG",
"tEDNS0",
"tINET6",
"tIP6_BYTESTRING",
"tIP6_DOTINT",
"tNDOTS",
"tNO_CHECK_NAMES",
"tNO_IP6_DOTINT",
"tROTATE",
"tTIMEOUT",
"tIP_ADDRESS",
"tDECADIC",
"tDOMAIN_NAME",
}
var yyStatenames = []string{}
const yyEofCode = 1
const yyErrCode = 2
const yyMaxDepth = 200
var yyExca = []int{
-1, 1,
1, -1,
-2, 0,
}
const yyNprod = 33
const yyPrivate = 57344
var yyTokenNames []string
var yyStates []string
const yyLast = 52
var yyAct = []int{
30, 41, 31, 38, 34, 35, 36, 39, 33, 37,
32, 40, 6, 4, 8, 5, 7, 27, 42, 48,
47, 46, 29, 26, 23, 21, 19, 17, 16, 14,
45, 25, 3, 44, 24, 52, 51, 50, 49, 28,
22, 20, 13, 18, 43, 12, 11, 15, 10, 9,
2, 1,
}
var yyPact = []int{
-1000, 8, -1000, -1000, -1000, -1000, -1000, -1000, -1000, 4,
3, 2, 1, 0, 20, -1, 12, 9, -2, 19,
-3, -8, -1000, -4, -1000, -1000, 19, -1000, 10, -8,
-1000, -1000, -1000, -1000, -1000, -1000, -1000, -1000, -1000, -5,
-6, -7, -1000, -1000, 18, -1000, 16, 15, 14, -1000,
-1000, -1000, -1000,
}
var yyPgo = []int{
0, 17, 51, 50, 49, 48, 47, 46, 45, 43,
42, 41, 0,
}
var yyR1 = []int{
0, 2, 2, 1, 1, 3, 4, 3, 5, 3,
7, 3, 8, 3, 10, 3, 12, 12, 12, 12,
12, 12, 12, 12, 12, 12, 12, 11, 11, 6,
6, 9, 9,
}
var yyR2 = []int{
0, 0, 2, 1, 3, 1, 0, 4, 0, 3,
0, 4, 0, 3, 0, 3, 1, 1, 1, 1,
1, 1, 1, 1, 3, 3, 3, 2, 3, 2,
3, 2, 3,
}
var yyChk = []int{
-1000, -2, -3, 24, 5, 7, 4, 8, 6, -4,
-5, -7, -8, -10, 25, -6, 25, 25, -9, 25,
-11, 25, 20, 25, 22, 22, 25, -1, 20, 25,
-12, 10, 18, 16, 12, 13, 14, 17, 11, 15,
19, 9, 22, -1, 23, -12, 26, 26, 26, 20,
21, 21, 21,
}
var yyDef = []int{
1, -2, 2, 5, 6, 8, 10, 12, 14, 0,
0, 0, 0, 0, 0, 9, 0, 0, 13, 0,
15, 0, 7, 0, 29, 11, 0, 31, 3, 0,
27, 16, 17, 18, 19, 20, 21, 22, 23, 0,
0, 0, 30, 32, 0, 28, 0, 0, 0, 4,
24, 25, 26,
}
var yyTok1 = []int{
1, 3, 3, 3, 3, 3, 3, 3, 3, 3,
24, 3, 3, 3, 3, 3, 3, 3, 3, 3,
3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
3, 3, 25, 3, 3, 3, 3, 3, 3, 3,
3, 3, 3, 3, 3, 3, 3, 23, 3, 3,
3, 3, 3, 3, 3, 3, 3, 3, 26,
}
var yyTok2 = []int{
2, 3, 4, 5, 6, 7, 8, 9, 10, 11,
12, 13, 14, 15, 16, 17, 18, 19, 20, 21,
22,
}
var yyTok3 = []int{
0,
}
/* parser for yacc output */
var yyDebug = 0
type yyLexer interface {
Lex(lval *yySymType) int
Error(s string)
}
const yyFlag = -1000
func yyTokname(c int) string {
if c > 0 && c <= len(yyToknames) {
if yyToknames[c-1] != "" {
return yyToknames[c-1]
}
}
return __yyfmt__.Sprintf("tok-%v", c)
}
func yyStatname(s int) string {
if s >= 0 && s < len(yyStatenames) {
if yyStatenames[s] != "" {
return yyStatenames[s]
}
}
return __yyfmt__.Sprintf("state-%v", s)
}
func yylex1(lex yyLexer, lval *yySymType) int {
c := 0
char := lex.Lex(lval)
if char <= 0 {
c = yyTok1[0]
goto out
}
if char < len(yyTok1) {
c = yyTok1[char]
goto out
}
if char >= yyPrivate {
if char < yyPrivate+len(yyTok2) {
c = yyTok2[char-yyPrivate]
goto out
}
}
for i := 0; i < len(yyTok3); i += 2 {
c = yyTok3[i+0]
if c == char {
c = yyTok3[i+1]
goto out
}
}
out:
if c == 0 {
c = yyTok2[1] /* unknown char */
}
if yyDebug >= 3 {
__yyfmt__.Printf("lex %U %s\n", uint(char), yyTokname(c))
}
return c
}
func yyParse(yylex *lex) int {
var yyn int
var yylval yySymType
var yyVAL yySymType
yyS := make([]yySymType, yyMaxDepth)
Nerrs := 0 /* number of errors */
Errflag := 0 /* error recovery flag */
yystate := 0
yychar := -1
yyp := -1
goto yystack
ret0:
return 0
ret1:
return 1
yystack:
/* put a state and value onto the stack */
if yyDebug >= 4 {
__yyfmt__.Printf("char %v in %v\n", yyTokname(yychar), yyStatname(yystate))
}
yyp++
if yyp >= len(yyS) {
nyys := make([]yySymType, len(yyS)*2)
copy(nyys, yyS)
yyS = nyys
}
yyS[yyp] = yyVAL
yyS[yyp].yys = yystate
yynewstate:
yyn = yyPact[yystate]
if yyn <= yyFlag {
goto yydefault /* simple state */
}
if yychar < 0 {
yychar = yylex1(yylex, &yylval)
}
yyn += yychar
if yyn < 0 || yyn >= yyLast {
goto yydefault
}
yyn = yyAct[yyn]
if yyChk[yyn] == yychar { /* valid shift */
yychar = -1
yyVAL = yylval
yystate = yyn
if Errflag > 0 {
Errflag--
}
goto yystack
}
yydefault:
/* default state action */
yyn = yyDef[yystate]
if yyn == -2 {
if yychar < 0 {
yychar = yylex1(yylex, &yylval)
}
/* look through exception table */
xi := 0
for {
if yyExca[xi+0] == -1 && yyExca[xi+1] == yystate {
break
}
xi += 2
}
for xi += 2; ; xi += 2 {
yyn = yyExca[xi+0]
if yyn < 0 || yyn == yychar {
break
}
}
yyn = yyExca[xi+1]
if yyn < 0 {
goto ret0
}
}
if yyn == 0 {
/* error ... attempt to resume parsing */
switch Errflag {
case 0: /* brand new error */
yylex.Error("syntax error")
Nerrs++
if yyDebug >= 1 {
__yyfmt__.Printf("%s", yyStatname(yystate))
__yyfmt__.Printf("saw %s\n", yyTokname(yychar))
}
fallthrough
case 1, 2: /* incompletely recovered error ... try again */
Errflag = 3
/* find a state where "error" is a legal shift action */
for yyp >= 0 {
yyn = yyPact[yyS[yyp].yys] + yyErrCode
if yyn >= 0 && yyn < yyLast {
yystate = yyAct[yyn] /* simulate a shift of "error" */
if yyChk[yystate] == yyErrCode {
goto yystack
}
}
/* the current p has no shift on "error", pop stack */
if yyDebug >= 2 {
__yyfmt__.Printf("error recovery pops state %d\n", yyS[yyp].yys)
}
yyp--
}
/* there is no state on the stack with an error shift ... abort */
goto ret1
case 3: /* no shift yet; clobber input char */
if yyDebug >= 2 {
__yyfmt__.Printf("error recovery discards %s\n", yyTokname(yychar))
}
if yychar == yyEofCode {
goto ret1
}
yychar = -1
goto yynewstate /* try again in the same state */
}
}
/* reduction by production yyn */
if yyDebug >= 2 {
__yyfmt__.Printf("reduce %v in:\n\t%v\n", yyn, yyStatname(yystate))
}
yynt := yyn
yypt := yyp
_ = yypt // guard against "declared and not used"
yyp -= yyR2[yyn]
yyVAL = yyS[yyp+1]
/* consult goto table to find next state */
yyn = yyR1[yyn]
yyg := yyPgo[yyn]
yyj := yyg + yyS[yyp].yys + 1
if yyj >= yyLast {
yystate = yyAct[yyg]
} else {
yystate = yyAct[yyj]
if yyChk[yystate] != -yyn {
yystate = yyAct[yyg]
}
}
// dummy call; replaced with literal code
switch yynt {
case 3:
{
yyVAL.mask.Addr = yyS[yypt-0].ip
}
case 4:
{
yyVAL.mask.Addr, yyVAL.mask.NetMask = yyS[yypt-2].ip, yyS[yypt-0].ip
}
case 5:
{
yylex.begin(sc_LINE_START)
}
case 6:
{
yylex.begin(sc_IP)
}
case 7:
{
yylex.resolv.AppendNameserver(yyS[yypt-0].ip)
}
case 8:
{
yylex.begin(sc_DOMAIN)
}
case 10:
{
yylex.begin(sc_DOMAIN)
}
case 11:
{
r := yylex.resolv
if r.Domain != "" {
panic(fmt.Errorf("domain %q already defined", r.Domain))
}
r.Domain = yyS[yypt-0].str
}
case 12:
{
yylex.begin(sc_IP)
}
case 14:
{
yylex.begin(sc_OPTS)
}
case 16:
{
yylex.resolv.Opt.Debug = true
}
case 17:
{
yylex.resolv.Opt.Rotate = true
}
case 18:
{
yylex.resolv.Opt.NoCheckNames = true
}
case 19:
{
yylex.resolv.Opt.Inet6 = true
}
case 20:
{
yylex.resolv.Opt.Ip6ByteString = true
}
case 21:
{
yylex.resolv.Opt.Ip6Dotint = true
}
case 22:
{
yylex.resolv.Opt.Ip6Dotint = false
}
case 23:
{
yylex.resolv.Opt.Edns0 = true
}
case 24:
{
yylex.resolv.Opt.Ndots = yyS[yypt-0].num
}
case 25:
{
yylex.resolv.Opt.TimeoutSecs = yyS[yypt-0].num
}
case 26:
{
yylex.resolv.Opt.Attempts = yyS[yypt-0].num
}
case 29:
{
yylex.resolv.appendSearch(yyS[yypt-0].str)
}
case 30:
{
yylex.resolv.appendSearch(yyS[yypt-0].str)
}
case 31:
{
yylex.resolv.appendSortlist(yyS[yypt-0].mask.Addr, yyS[yypt-0].mask.NetMask)
}
case 32:
{
yylex.resolv.appendSortlist(yyS[yypt-0].mask.Addr, yyS[yypt-0].mask.NetMask)
}
}
goto yystack /* stack new state and value */
}