Compare commits
3 Commits
322e383012
..
v0.3.5
| Author | SHA1 | Date | |
|---|---|---|---|
| f8f6ff9e11 | |||
| 05d504346e | |||
| 93c58cdc26 |
@@ -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
|
||||
|
||||
+10
-1
@@ -1,6 +1,11 @@
|
||||
// Package lexer provides basic helpers to implement parsers
|
||||
package lexer
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"io"
|
||||
)
|
||||
|
||||
// StateFn is a State Function of the parser
|
||||
type StateFn func() (StateFn, error)
|
||||
|
||||
@@ -11,7 +16,11 @@ func Run(fn StateFn) error {
|
||||
var err error
|
||||
|
||||
fn, err = fn()
|
||||
if err != nil {
|
||||
switch {
|
||||
case errors.Is(err, io.EOF):
|
||||
// EOF
|
||||
return nil
|
||||
case err != nil:
|
||||
// failed
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -64,29 +64,3 @@ 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,
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user