This parses - now make it quick

This commit is contained in:
Miek Gieben 2011-07-20 21:19:40 +02:00
parent 367dfb8eb8
commit 802b8cd9c9
3 changed files with 13247 additions and 89636 deletions

View File

@ -23,6 +23,7 @@ GOFILES=\
xfr.go\ xfr.go\
zone.go\ zone.go\
zparse.go\ zparse.go\
# test.go\
include $(GOROOT)/src/Make.pkg include $(GOROOT)/src/Make.pkg

102838
zparse.go

File diff suppressed because it is too large Load Diff

View File

@ -76,8 +76,8 @@ func Zparse(q io.Reader) (z *Zone, err os.Error) {
z = new(Zone) z = new(Zone)
data := string(buf) data := string(buf)
// cs, p, pe, eof := 0, 0, len(data), len(data)
cs, p, pe := 0, 0, len(data) cs, p, pe := 0, 0, len(data)
eof := len(data)
brace := false brace := false
lines := 0 lines := 0
mark := 0 mark := 0
@ -93,8 +93,7 @@ func Zparse(q io.Reader) (z *Zone, err os.Error) {
action setTtl { ttl, _ := strconv.Atoi(data[mark:p]); hdr.Ttl = uint32(ttl) } action setTtl { ttl, _ := strconv.Atoi(data[mark:p]); hdr.Ttl = uint32(ttl) }
action number { tok.pushInt(data[mark:p]) } action number { tok.pushInt(data[mark:p]) }
action text { tok.pushString(data[mark:p]) } action text { tok.pushString(data[mark:p]) }
action textblank { tok.pushString(data[mark:p]) } action set { z.Push(rr); tok.reset() }
action set { z.Push(rr); tok.reset(); println("setting") }
action openBrace { if brace { println("Brace already open")} ; brace = true } action openBrace { if brace { println("Brace already open")} ; brace = true }
action closeBrace { if !brace { println("Brace already closed")}; brace = false } action closeBrace { if !brace { println("Brace already closed")}; brace = false }
action brace { brace } action brace { brace }
@ -124,15 +123,15 @@ func Zparse(q io.Reader) (z *Zone, err os.Error) {
| (comment? nl)+ when brace | (comment? nl)+ when brace
)+ %mark; )+ %mark;
qclass = ('IN'i|'CS'i|'CH'i|'HS'i|'ANY'i|'NONE'i) %qclass; qclass = ('IN'i|'CS'i|'CH'i|'HS'i|'ANY'i|'NONE'i) %qclass;
chars = [^; \t"\n\\)(];
ttl = digit+ >mark; ttl = digit+ >mark;
qname = [\-a-zA-Z0-9.\\_]+ %qname; qname = chars+ %qname;
# If I use this in the definitions at the end, things break. # If I use this in the definitions at the end, things break.
# 6l seems to hang when compiling the resulting .go file... # 6l seems to hang when compiling the resulting .go file...
# tb is WITH the space # tb is WITH the space
tb = [\-a-zA-Z0-9.\\/+=: ]+ $1 %0 %textblank; tb = (chars | ' ')+ $1 %0 %text;
t = [\-a-zA-Z0-9.\\/+=:]+ $1 %0 %text; t = chars+ $1 %0 %text;
n = [0-9]+ $1 %0 %number; n = [0-9]+ $1 %0 %number;
lhs = qname? bl %defTtl ( lhs = qname? bl %defTtl (
@ -149,11 +148,11 @@ func Zparse(q io.Reader) (z *Zone, err os.Error) {
| ('AAAA'i %qtype bl t) %rdata_aaaa | ('AAAA'i %qtype bl t) %rdata_aaaa
| ('NS'i %qtype bl t) %rdata_ns | ('NS'i %qtype bl t) %rdata_ns
| ('CNAME'i %qtype bl t) %rdata_cname | ('CNAME'i %qtype bl t) %rdata_cname
| ('SOA'i %qtype bl t bl t bl n bl n bl n bl n bl n) %rdata_soa # | ('SOA'i %qtype bl t bl t bl n bl n bl n bl n bl n) %rdata_soa
| ('MX'i %qtype bl n bl t) %rdata_mx | ('MX'i %qtype bl n bl t) %rdata_mx
| ('DS'i %qtype bl n bl n bl n bl t) %rdata_ds # | ('DS'i %qtype bl n bl n bl n bl tb) %rdata_ds
| ('DNSKEY'i %qtype bl n bl n bl n bl t) %rdata_dnskey # | ('DNSKEY'i %qtype bl n bl n bl n bl tb) %rdata_dnskey
| ('RRSIG'i %qtype bl n bl n bl n bl n bl n bl n bl n bl t bl t) %rdata_rrsig # | ('RRSIG'i %qtype bl n bl n bl n bl n bl n bl n bl n bl t bl tb) %rdata_rrsig
); );
rr = lhs rhs %set; rr = lhs rhs %set;
@ -162,19 +161,18 @@ func Zparse(q io.Reader) (z *Zone, err os.Error) {
write init; write init;
write exec; write exec;
}%% }%%
/* if eof > -1 {
This part needs work if cs < z_first_final {
if cs < z_first_final { // No clue what I'm doing what so ever
// No clue what I'm doing what so ever if p == pe {
if p == pe { println("unexpected eof")
println("unexpected eof") return z, nil
return z, nil } else {
} else { println("error at position ", p)
println("error at position ", p) return z, nil
return z, nil }
} }
} }
*/
return z, nil return z, nil
} }