More tweaks for parsing

This commit is contained in:
Miek Gieben 2011-12-16 10:48:33 +01:00
parent a5baf52283
commit 4d5f6d66e2
2 changed files with 9 additions and 9 deletions

View File

@ -9,9 +9,7 @@ import (
)
// Only used when debugging the parser itself.
var _DEBUG = false
var _DEBUG = true
// Tokinize a RFC 1035 zone file. The tokenizer will normalize it:
// * Add ownernames if they are left blank;
@ -51,8 +49,10 @@ type ParseError struct {
}
func (e *ParseError) Error() string {
s := e.err + ": `" + e.lex.token + "' at line: " + strconv.Itoa(e.lex.line) +
" and column: " + strconv.Itoa(e.lex.column)
va := strconv.Itoa(e.lex.value)
s := e.err + ": `" + e.lex.token + "' (value: " + va + ") at line: " +
strconv.Itoa(e.lex.line) + " and column: " +
strconv.Itoa(e.lex.column)
return s
}

View File

@ -88,24 +88,24 @@ func setRR(h RR_Header, c chan Lex) (RR, *ParseError) {
func slurpRemainder(c chan Lex) *ParseError {
l := <-c
if _DEBUG {
fmt.Printf("%\v", l)
fmt.Printf("%v\n", l)
}
switch l.value {
case _BLANK:
l = <-c
if _DEBUG {
fmt.Printf("%\v", l)
fmt.Printf("%v\n", l)
}
if l.value != _NEWLINE && l.value != _EOF {
return &ParseError{"garbage after rdata", l}
}
// Ok
case _NEWLINE:
// Ok
// Ok
case _EOF:
// Ok
default:
return &ParseError{"garbage after rdata", l}
return &ParseError{"garbage after directly rdata", l}
}
return nil
}