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