This works, but is too slow
This commit is contained in:
parent
802b8cd9c9
commit
e863e86e65
18
types.rl
18
types.rl
|
@ -2,28 +2,38 @@
|
||||||
machine z;
|
machine z;
|
||||||
|
|
||||||
action rdata_a {
|
action rdata_a {
|
||||||
|
rr = new(RR_A)
|
||||||
x := rr.(*RR_A)
|
x := rr.(*RR_A)
|
||||||
x.Hdr = *hdr
|
x.Hdr = *hdr
|
||||||
|
x.Hdr.Rrtype = TypeA
|
||||||
x.A = net.ParseIP(tok.T[0])
|
x.A = net.ParseIP(tok.T[0])
|
||||||
}
|
}
|
||||||
action rdata_aaaa {
|
action rdata_aaaa {
|
||||||
|
rr = new(RR_AAAA)
|
||||||
x := rr.(*RR_AAAA)
|
x := rr.(*RR_AAAA)
|
||||||
x.Hdr = *hdr
|
x.Hdr = *hdr
|
||||||
|
x.Hdr.Rrtype = TypeAAAA
|
||||||
x.AAAA = net.ParseIP(tok.T[0])
|
x.AAAA = net.ParseIP(tok.T[0])
|
||||||
}
|
}
|
||||||
action rdata_ns {
|
action rdata_ns {
|
||||||
|
rr = new(RR_NS)
|
||||||
x := rr.(*RR_NS)
|
x := rr.(*RR_NS)
|
||||||
x.Hdr = *hdr
|
x.Hdr = *hdr
|
||||||
|
x.Hdr.Rrtype = TypeNS
|
||||||
x.Ns = tok.T[0]
|
x.Ns = tok.T[0]
|
||||||
}
|
}
|
||||||
action rdata_cname {
|
action rdata_cname {
|
||||||
|
rr = new(RR_CNAME)
|
||||||
x := rr.(*RR_CNAME)
|
x := rr.(*RR_CNAME)
|
||||||
x.Hdr = *hdr
|
x.Hdr = *hdr
|
||||||
|
x.Hdr.Rrtype = TypeCNAME
|
||||||
x.Cname = tok.T[0]
|
x.Cname = tok.T[0]
|
||||||
}
|
}
|
||||||
action rdata_soa {
|
action rdata_soa {
|
||||||
|
rr = new(RR_SOA)
|
||||||
x := rr.(*RR_SOA)
|
x := rr.(*RR_SOA)
|
||||||
x.Hdr = *hdr
|
x.Hdr = *hdr
|
||||||
|
x.Hdr.Rrtype = TypeSOA
|
||||||
x.Ns = tok.T[0]
|
x.Ns = tok.T[0]
|
||||||
x.Mbox = tok.T[1]
|
x.Mbox = tok.T[1]
|
||||||
x.Serial = uint32(tok.N[0])
|
x.Serial = uint32(tok.N[0])
|
||||||
|
@ -33,30 +43,38 @@
|
||||||
x.Minttl = uint32(tok.N[4])
|
x.Minttl = uint32(tok.N[4])
|
||||||
}
|
}
|
||||||
action rdata_mx {
|
action rdata_mx {
|
||||||
|
rr = new(RR_MX)
|
||||||
x := rr.(*RR_MX)
|
x := rr.(*RR_MX)
|
||||||
x.Hdr = *hdr;
|
x.Hdr = *hdr;
|
||||||
|
x.Hdr.Rrtype = TypeMX
|
||||||
x.Pref = uint16(tok.N[0])
|
x.Pref = uint16(tok.N[0])
|
||||||
x.Mx = tok.T[0]
|
x.Mx = tok.T[0]
|
||||||
}
|
}
|
||||||
action rdata_ds {
|
action rdata_ds {
|
||||||
|
rr = new(RR_DS)
|
||||||
x := rr.(*RR_DS)
|
x := rr.(*RR_DS)
|
||||||
x.Hdr = *hdr;
|
x.Hdr = *hdr;
|
||||||
|
x.Hdr.Rrtype = TypeDS
|
||||||
x.KeyTag = uint16(tok.N[0])
|
x.KeyTag = uint16(tok.N[0])
|
||||||
x.Algorithm = uint8(tok.N[1])
|
x.Algorithm = uint8(tok.N[1])
|
||||||
x.DigestType = uint8(tok.N[2])
|
x.DigestType = uint8(tok.N[2])
|
||||||
x.Digest = tok.T[0]
|
x.Digest = tok.T[0]
|
||||||
}
|
}
|
||||||
action rdata_dnskey {
|
action rdata_dnskey {
|
||||||
|
rr = new(RR_DNSKEY)
|
||||||
x := rr.(*RR_DNSKEY)
|
x := rr.(*RR_DNSKEY)
|
||||||
x.Hdr = *hdr;
|
x.Hdr = *hdr;
|
||||||
|
x.Hdr.Rrtype = TypeDNSKEY
|
||||||
x.Flags = uint16(tok.N[0])
|
x.Flags = uint16(tok.N[0])
|
||||||
x.Protocol = uint8(tok.N[1])
|
x.Protocol = uint8(tok.N[1])
|
||||||
x.Algorithm = uint8(tok.N[2])
|
x.Algorithm = uint8(tok.N[2])
|
||||||
x.PublicKey = tok.T[0]
|
x.PublicKey = tok.T[0]
|
||||||
}
|
}
|
||||||
action rdata_rrsig {
|
action rdata_rrsig {
|
||||||
|
rr = new(RR_RRSIG)
|
||||||
x := rr.(*RR_RRSIG)
|
x := rr.(*RR_RRSIG)
|
||||||
x.Hdr = *hdr;
|
x.Hdr = *hdr;
|
||||||
|
x.Hdr.Rrtype = TypeRRSIG
|
||||||
x.TypeCovered = uint16(tok.N[0])
|
x.TypeCovered = uint16(tok.N[0])
|
||||||
x.Algorithm = uint8(tok.N[1])
|
x.Algorithm = uint8(tok.N[1])
|
||||||
x.Labels = uint8(tok.N[2])
|
x.Labels = uint8(tok.N[2])
|
||||||
|
|
41
zparse.rl
41
zparse.rl
|
@ -77,7 +77,13 @@ func Zparse(q io.Reader) (z *Zone, err os.Error) {
|
||||||
|
|
||||||
data := string(buf)
|
data := string(buf)
|
||||||
cs, p, pe := 0, 0, len(data)
|
cs, p, pe := 0, 0, len(data)
|
||||||
|
ts, te, act := 0, 0, 0
|
||||||
|
// top := 0
|
||||||
|
// stack := make([]int, 100)
|
||||||
eof := len(data)
|
eof := len(data)
|
||||||
|
// keep Go happy
|
||||||
|
ts = ts; te = te; act = act
|
||||||
|
|
||||||
brace := false
|
brace := false
|
||||||
lines := 0
|
lines := 0
|
||||||
mark := 0
|
mark := 0
|
||||||
|
@ -93,21 +99,11 @@ 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 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 }
|
||||||
action linecount { lines++ }
|
action linecount { lines++ }
|
||||||
action qtype {
|
|
||||||
i := Str_rr[data[mark:p]]
|
|
||||||
mk, known := rr_mk[int(i)]
|
|
||||||
if ! known {
|
|
||||||
println("Unknown type seen: " + data[mark:p])
|
|
||||||
// panic?
|
|
||||||
}
|
|
||||||
rr = mk()
|
|
||||||
hdr.Rrtype = i
|
|
||||||
}
|
|
||||||
|
|
||||||
# Newlines
|
# Newlines
|
||||||
nl = [\n]+ $linecount;
|
nl = [\n]+ $linecount;
|
||||||
|
@ -127,9 +123,6 @@ func Zparse(q io.Reader) (z *Zone, err os.Error) {
|
||||||
chars = [^; \t"\n\\)(];
|
chars = [^; \t"\n\\)(];
|
||||||
ttl = digit+ >mark;
|
ttl = digit+ >mark;
|
||||||
qname = chars+ %qname;
|
qname = chars+ %qname;
|
||||||
# If I use this in the definitions at the end, things break.
|
|
||||||
# 6l seems to hang when compiling the resulting .go file...
|
|
||||||
# tb is WITH the space
|
|
||||||
tb = (chars | ' ')+ $1 %0 %text;
|
tb = (chars | ' ')+ $1 %0 %text;
|
||||||
t = chars+ $1 %0 %text;
|
t = chars+ $1 %0 %text;
|
||||||
n = [0-9]+ $1 %0 %number;
|
n = [0-9]+ $1 %0 %number;
|
||||||
|
@ -144,16 +137,14 @@ func Zparse(q io.Reader) (z *Zone, err os.Error) {
|
||||||
|
|
||||||
# RR definitions.
|
# RR definitions.
|
||||||
rhs = (
|
rhs = (
|
||||||
('A'i %qtype bl t) %rdata_a
|
('AAAA'i bl t) %rdata_aaaa
|
||||||
| ('AAAA'i %qtype bl t) %rdata_aaaa
|
| ('A'i bl t) %rdata_a
|
||||||
| ('NS'i %qtype bl t) %rdata_ns
|
| ('NS'i bl t) %rdata_ns
|
||||||
| ('CNAME'i %qtype bl t) %rdata_cname
|
| ('CNAME'i bl t) %rdata_cname
|
||||||
# | ('SOA'i %qtype bl t bl t bl n bl n bl n bl n bl n) %rdata_soa
|
| ('MX'i 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 tb) %rdata_ds
|
# 'SOA'i; bl; t; bl; t; bl; n; bl; n; bl; n; bl; n; bl; n => rdata_soa; { fret; };
|
||||||
# | ('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 tb) %rdata_rrsig
|
|
||||||
);
|
|
||||||
|
|
||||||
rr = lhs rhs %set;
|
rr = lhs rhs %set;
|
||||||
main := (rr? bl? ((comment? nl) when !brace))*;
|
main := (rr? bl? ((comment? nl) when !brace))*;
|
||||||
|
@ -169,7 +160,7 @@ func Zparse(q io.Reader) (z *Zone, err os.Error) {
|
||||||
println("unexpected eof")
|
println("unexpected eof")
|
||||||
return z, nil
|
return z, nil
|
||||||
} else {
|
} else {
|
||||||
println("error at position ", p)
|
println("error at position ", p, "\"",data[mark:p],"\"")
|
||||||
return z, nil
|
return z, nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue