Compare commits
No commits in common. "19e0a61345d8e8b0a033b52bd5431bbfc0538484" and "9d4da8ef95cbbebad580f2d4f1685d79d4b444f1" have entirely different histories.
19e0a61345
...
9d4da8ef95
@ -10,7 +10,7 @@ func (p *Position) Advance(rn rune) {
|
||||
p.Index++
|
||||
if rn == '\n' {
|
||||
p.Line++
|
||||
p.Column = 1
|
||||
p.Column = 0
|
||||
} else {
|
||||
p.Column++
|
||||
}
|
||||
|
@ -18,7 +18,7 @@ func New(r io.Reader) *Reader {
|
||||
return &Reader{
|
||||
buf: ds.NewArrayStack[posRune](),
|
||||
src: bufio.NewReader(r),
|
||||
pos: &Position{Index: 0, Line: 1, Column: 1},
|
||||
pos: &Position{Index: 0, Line: 1, Column: 0},
|
||||
}
|
||||
}
|
||||
|
||||
@ -33,8 +33,8 @@ func (r *Reader) psrn(rn rune) posRune {
|
||||
}
|
||||
}
|
||||
|
||||
func (r *Reader) Pos() Position {
|
||||
return *r.pos
|
||||
func (r *Reader) Pos() (index, line, column int) {
|
||||
return r.pos.Index, r.pos.Line, r.pos.Column
|
||||
}
|
||||
|
||||
// Rune returns the next rune in r
|
||||
|
@ -11,8 +11,8 @@ func TestPos(t *testing.T) {
|
||||
|
||||
unread := false
|
||||
for rn, err := r.Rune(); err == nil; rn, err = r.Rune() {
|
||||
pos := r.Pos()
|
||||
fmt.Println(string(rn), pos.Index, pos.Line, pos.Column)
|
||||
index, line, col := r.Pos()
|
||||
fmt.Println(string(rn), index, line, col)
|
||||
|
||||
if !unread && rn == '\n' {
|
||||
for i := 0; i < 5; i++ {
|
||||
|
Loading…
Reference in New Issue
Block a user