Merge pull request 'lexer: introduce Position.Add()' (#13)
Reviewed-on: #13
This commit was merged in pull request #13.
This commit is contained in:
@@ -64,3 +64,23 @@ 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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user