parser/metadecoders: Consolidate the metadata decoders

See #5324
This commit is contained in:
Bjørn Erik Pedersen
2018-10-20 11:16:18 +02:00
parent 44da60d869
commit 129c27ee6e
22 changed files with 624 additions and 808 deletions

View File

@@ -48,7 +48,7 @@ func Parse(r io.Reader) (Result, error) {
}
func parseMainSection(input []byte, from int) Result {
lexer := newPageLexer(input, pos(from), lexMainSection) // TODO(bep) 2errors
lexer := newPageLexer(input, Pos(from), lexMainSection) // TODO(bep) 2errors
lexer.run()
return lexer
}
@@ -57,7 +57,7 @@ func parseMainSection(input []byte, from int) Result {
// if needed.
type Iterator struct {
l *pageLexer
lastPos pos // position of the last item returned by nextItem
lastPos Pos // position of the last item returned by nextItem
}
// consumes and returns the next item
@@ -69,7 +69,7 @@ func (t *Iterator) Next() Item {
var errIndexOutOfBounds = Item{tError, 0, []byte("no more tokens")}
func (t *Iterator) current() Item {
if t.lastPos >= pos(len(t.l.items)) {
if t.lastPos >= Pos(len(t.l.items)) {
return errIndexOutOfBounds
}
return t.l.items[t.lastPos]
@@ -98,7 +98,7 @@ func (t *Iterator) Peek() Item {
// PeekWalk will feed the next items in the iterator to walkFn
// until it returns false.
func (t *Iterator) PeekWalk(walkFn func(item Item) bool) {
for i := t.lastPos + 1; i < pos(len(t.l.items)); i++ {
for i := t.lastPos + 1; i < Pos(len(t.l.items)); i++ {
item := t.l.items[i]
if !walkFn(item) {
break
@@ -120,5 +120,5 @@ func (t *Iterator) Consume(cnt int) {
// LineNumber returns the current line number. Used for logging.
func (t *Iterator) LineNumber() int {
return bytes.Count(t.l.input[:t.current().pos], lf) + 1
return bytes.Count(t.l.input[:t.current().Pos], lf) + 1
}