Add parse test and further tweaks
This commit is contained in:
parent
88c149cdb4
commit
525465db6d
|
@ -703,3 +703,19 @@ func TestILNP(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestComment(t *testing.T) {
|
||||||
|
zone := `
|
||||||
|
foo. IN A 10.0.0.1 ; this is a comment1
|
||||||
|
foo. IN A (
|
||||||
|
10.0.0.2 ; this is a comment2
|
||||||
|
)
|
||||||
|
; this is a comment3
|
||||||
|
foo. IN A 10.0.0.3
|
||||||
|
`
|
||||||
|
for x := range ParseZone(strings.NewReader(zone), ".", "") {
|
||||||
|
if x.Error == nil {
|
||||||
|
fmt.Printf("%s\n", x.RR.String())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
20
zscan.go
20
zscan.go
|
@ -305,7 +305,7 @@ func parseZone(r io.Reader, origin, f string, t chan Token, include int) {
|
||||||
t <- Token{Error: &ParseError{f, "expecting $TTL value, not this...", l}}
|
t <- Token{Error: &ParseError{f, "expecting $TTL value, not this...", l}}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if e := slurpRemainder(c, f); e != nil {
|
if e, _ := slurpRemainder(c, f); e != nil {
|
||||||
t <- Token{Error: e}
|
t <- Token{Error: e}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -327,7 +327,7 @@ func parseZone(r io.Reader, origin, f string, t chan Token, include int) {
|
||||||
t <- Token{Error: &ParseError{f, "expecting $ORIGIN value, not this...", l}}
|
t <- Token{Error: &ParseError{f, "expecting $ORIGIN value, not this...", l}}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if e := slurpRemainder(c, f); e != nil {
|
if e, _ := slurpRemainder(c, f); e != nil {
|
||||||
t <- Token{Error: e}
|
t <- Token{Error: e}
|
||||||
}
|
}
|
||||||
if _, _, ok := IsDomainName(l.token); !ok {
|
if _, _, ok := IsDomainName(l.token); !ok {
|
||||||
|
@ -628,7 +628,8 @@ func zlexer(s *scan, c chan lex) {
|
||||||
owner = true
|
owner = true
|
||||||
l.value = _NEWLINE
|
l.value = _NEWLINE
|
||||||
l.token = "\n"
|
l.token = "\n"
|
||||||
debug.Printf("[3 %+v]", l.token)
|
l.comment = string(com[:comi])
|
||||||
|
debug.Printf("[3 %+v %+v]", l.token, l.comment)
|
||||||
c <- l
|
c <- l
|
||||||
comi = 0
|
comi = 0
|
||||||
break
|
break
|
||||||
|
@ -878,24 +879,21 @@ func locCheckEast(token string, longitude uint32) (uint32, bool) {
|
||||||
return longitude, false
|
return longitude, false
|
||||||
}
|
}
|
||||||
|
|
||||||
// "Eat" the rest of the "line"
|
// "Eat" the rest of the "line". Return potential comments
|
||||||
func slurpRemainder(c chan lex, f string) *ParseError {
|
func slurpRemainder(c chan lex, f string) (*ParseError, string) {
|
||||||
l := <-c
|
l := <-c
|
||||||
switch l.value {
|
switch l.value {
|
||||||
case _BLANK:
|
case _BLANK:
|
||||||
l = <-c
|
l = <-c
|
||||||
if l.value != _NEWLINE && l.value != _EOF {
|
if l.value != _NEWLINE && l.value != _EOF {
|
||||||
return &ParseError{f, "garbage after rdata", l}
|
return &ParseError{f, "garbage after rdata", l}, ""
|
||||||
}
|
}
|
||||||
// Ok
|
|
||||||
case _NEWLINE:
|
case _NEWLINE:
|
||||||
// Ok
|
|
||||||
case _EOF:
|
case _EOF:
|
||||||
// Ok
|
|
||||||
default:
|
default:
|
||||||
return &ParseError{f, "garbage after rdata", l}
|
return &ParseError{f, "garbage after rdata", l}, ""
|
||||||
}
|
}
|
||||||
return nil
|
return nil, l.comment
|
||||||
}
|
}
|
||||||
|
|
||||||
// Parse a 64 bit-like ipv6 address: "0014:4fff:ff20:ee64"
|
// Parse a 64 bit-like ipv6 address: "0014:4fff:ff20:ee64"
|
||||||
|
|
19
zscan_rr.go
19
zscan_rr.go
|
@ -12,7 +12,7 @@ import (
|
||||||
// After the rdata there may come a _BLANK and then a _NEWLINE
|
// After the rdata there may come a _BLANK and then a _NEWLINE
|
||||||
// or immediately a _NEWLINE. If this is not the case we flag
|
// or immediately a _NEWLINE. If this is not the case we flag
|
||||||
// an *ParseError: garbage after rdata.
|
// an *ParseError: garbage after rdata.
|
||||||
func setRR(h RR_Header, c chan lex, o, f string) (RR, *ParseError) {
|
func setRR(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) {
|
||||||
var r RR
|
var r RR
|
||||||
e := new(ParseError)
|
e := new(ParseError)
|
||||||
switch h.Rrtype {
|
switch h.Rrtype {
|
||||||
|
@ -146,31 +146,30 @@ func setRR(h RR_Header, c chan lex, o, f string) (RR, *ParseError) {
|
||||||
}
|
}
|
||||||
Slurp:
|
Slurp:
|
||||||
if e != nil {
|
if e != nil {
|
||||||
return nil, e
|
return nil, e, ""
|
||||||
}
|
}
|
||||||
if se := slurpRemainder(c, f); se != nil {
|
if se, com := slurpRemainder(c, f); se != nil {
|
||||||
return nil, se
|
return nil, se, com
|
||||||
}
|
}
|
||||||
return r, e
|
return r, e, ""
|
||||||
}
|
}
|
||||||
|
|
||||||
// A remainder of the rdata with embedded spaces, return the parsed string (sans the spaces)
|
// A remainder of the rdata with embedded spaces, return the parsed string (sans the spaces)
|
||||||
// or an error
|
// or an error
|
||||||
func endingToString(c chan lex, errstr, f string) (string, *ParseError) {
|
func endingToString(c chan lex, errstr, f string) (string, *ParseError, string) {
|
||||||
s := ""
|
s := ""
|
||||||
l := <-c // _STRING
|
l := <-c // _STRING
|
||||||
for l.value != _NEWLINE && l.value != _EOF {
|
for l.value != _NEWLINE && l.value != _EOF {
|
||||||
switch l.value {
|
switch l.value {
|
||||||
case _STRING:
|
case _STRING:
|
||||||
s += l.token
|
s += l.token
|
||||||
case _BLANK:
|
case _BLANK: // Ok
|
||||||
// Ok
|
|
||||||
default:
|
default:
|
||||||
return "", &ParseError{f, errstr, l}
|
return "", &ParseError{f, errstr, l}, ""
|
||||||
}
|
}
|
||||||
l = <-c
|
l = <-c
|
||||||
}
|
}
|
||||||
return s, nil
|
return s, nil, l.comment
|
||||||
}
|
}
|
||||||
|
|
||||||
// A remainder of the rdata with embedded spaces, return the parsed string slice (sans the spaces)
|
// A remainder of the rdata with embedded spaces, return the parsed string slice (sans the spaces)
|
||||||
|
|
Loading…
Reference in New Issue