2 Commits

Author SHA1 Message Date
amery 73cda64c4b lexer: introduce a Position (Line, Column) handler
Signed-off-by: Alejandro Mery <amery@jpi.io>
2023-08-29 15:36:57 +00:00
amery df82e043bb Merge branch 'pr-amery-lexer' into next-amery 2023-08-29 15:36:31 +00:00
2 changed files with 0 additions and 30 deletions
-6
View File
@@ -1,7 +1,6 @@
package lexer
import (
"errors"
"fmt"
"strings"
)
@@ -10,11 +9,6 @@ var (
_ error = (*Error)(nil)
)
var (
// ErrUnacceptableRune indicates the read rune
ErrUnacceptableRune = errors.New("rune not acceptable in context")
)
// Error represents a generic parsing error
type Error struct {
Filename string
-24
View File
@@ -41,30 +41,6 @@ func (p *Position) Step() {
p.Column++
}
// StepN moves the column N places forward
func (p *Position) StepN(n int) {
if p.Line == 0 {
p.Reset()
}
switch {
case n > 0:
p.Column += n
default:
panic(fmt.Errorf("invalid %v increment", n))
}
}
// StepLine moves position to the start of the next line
func (p *Position) StepLine() {
if p.Line == 0 {
p.Reset()
}
p.Line++
p.Column = 1
}
// Next returns a new Position one rune forward
// on the line
func (p Position) Next() Position {