lexer: introduce Position.Next()/Position.NextLine() factories

Signed-off-by: Alejandro Mery <amery@jpi.io>
This commit is contained in:
2023-08-28 22:56:11 +00:00
parent c31cfb9244
commit 2da187c9c3
+26
View File
@@ -64,3 +64,29 @@ func (p *Position) StepLine() {
p.Line++
p.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 begining of the next
// line.
func (p Position) NextLine() Position {
if p.Line == 0 {
p.Reset()
}
return Position{
Line: p.Line + 1,
Column: 1,
}
}