Ugly hack to get line count correct

When the parser has read a \n to error messsage is off-by-one.
This fixes that.
This commit is contained in:
Miek Gieben 2012-11-21 17:19:16 +01:00
parent 534b3ddfd8
commit c15d4fe3a3
2 changed files with 10 additions and 2 deletions

View File

@ -11,6 +11,7 @@ import (
type scan struct {
src *bufio.Reader
position scanner.Position
eof int // have we just seen an EOF (0 no, 1 yes)
}
func scanInit(r io.Reader) *scan {
@ -26,9 +27,11 @@ func (s *scan) tokenText() (byte, error) {
if err != nil {
return c, err
}
s.eof = 0
if c == '\n' {
s.position.Line++
s.position.Column = 0
s.eof = 1
}
s.position.Column++
return c, nil

View File

@ -72,8 +72,11 @@ func (e *ParseError) Error() (s string) {
if e.file != "" {
s = e.file + ": "
}
// the -e.lex.eof is used for a file line number correction. The error
// we are printing happend on the line N, but the tokenizer already
// saw the \n and incremented the linenumber counter
s += "dns: " + e.err + ": " + strconv.QuoteToASCII(e.lex.token) + " at line: " +
strconv.Itoa(e.lex.line) + ":" + strconv.Itoa(e.lex.column)
strconv.Itoa(e.lex.line-e.lex.eof) + ":" + strconv.Itoa(e.lex.column)
return
}
@ -83,6 +86,7 @@ type lex struct {
value uint8 // Value: _STRING, _BLANK, etc.
line int // Line in the file
column int // Column in the file
eof int // Has the tokenizer just seen a newline (0 no, 1 yes)
torc uint16 // Type or class as parsed in the lexer, we only need to look this up in the grammar
}
@ -447,6 +451,7 @@ func zlexer(s *scan, c chan lex) {
for err == nil {
l.column = s.position.Column
l.line = s.position.Line
l.eof = s.eof
if stri > maxTok {
l.token = "tok length insufficient for parsing"
l.err = true
@ -838,7 +843,7 @@ func stringToNodeID(l lex) (uint64, *ParseError) {
return 0, &ParseError{l.token, "bad NID/L64 NodeID/Locator64", l}
}
s := l.token[0:4] + l.token[5:9] + l.token[10:14] + l.token[15:19]
u, e := strconv.ParseUint(s, 16,64)
u, e := strconv.ParseUint(s, 16, 64)
if e != nil {
return 0, &ParseError{l.token, "bad NID/L64 NodeID/Locator64", l}
}