Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 43b2cff5b7 | |||
| 5f816300f6 | |||
| 5f81eb0ea5 | |||
| ce75299e74 | |||
| 1d7ee69ab7 | |||
| ec0fc8e508 |
@@ -64,3 +64,49 @@ func (p *Position) StepLine() {
|
|||||||
p.Line++
|
p.Line++
|
||||||
p.Column = 1
|
p.Column = 1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Add adds a relative position considering
|
||||||
|
// potential new lines
|
||||||
|
func (p *Position) Add(rel Position) {
|
||||||
|
if p.Line == 0 {
|
||||||
|
p.Reset()
|
||||||
|
}
|
||||||
|
|
||||||
|
switch {
|
||||||
|
case rel.Line == 0:
|
||||||
|
// nothing
|
||||||
|
case rel.Line > 1:
|
||||||
|
// includes new lines
|
||||||
|
p.Line += rel.Line - 1
|
||||||
|
p.Column = rel.Column
|
||||||
|
default:
|
||||||
|
// same line
|
||||||
|
p.Column += rel.Column - 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Next returns a new Position one rune forward
|
||||||
|
// on the line
|
||||||
|
func (p Position) Next() Position {
|
||||||
|
if p.Line == 0 {
|
||||||
|
p.Reset()
|
||||||
|
}
|
||||||
|
|
||||||
|
return Position{
|
||||||
|
Line: p.Line,
|
||||||
|
Column: p.Column + 1,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// NextLine returns a new Position at the beginning of the next
|
||||||
|
// line.
|
||||||
|
func (p Position) NextLine() Position {
|
||||||
|
if p.Line == 0 {
|
||||||
|
p.Reset()
|
||||||
|
}
|
||||||
|
|
||||||
|
return Position{
|
||||||
|
Line: p.Line + 1,
|
||||||
|
Column: 1,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user