Compare commits
5 Commits
v0.3.6
..
a5f8482842
| Author | SHA1 | Date | |
|---|---|---|---|
| a5f8482842 | |||
| e308b8e284 | |||
| 0c37c9eead | |||
| 03684b19dc | |||
| 1247683981 |
+1
-4
@@ -11,11 +11,8 @@ var (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
// ErrUnacceptableRune indicates the read rune isn't acceptable in the context
|
// ErrUnacceptableRune indicates the read rune
|
||||||
ErrUnacceptableRune = errors.New("rune not acceptable in context")
|
ErrUnacceptableRune = errors.New("rune not acceptable in context")
|
||||||
|
|
||||||
// ErrNotImplemented indicates something hasn't been implemented yet
|
|
||||||
ErrNotImplemented = errors.New("not implemented")
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// Error represents a generic parsing error
|
// Error represents a generic parsing error
|
||||||
|
|||||||
+1
-10
@@ -1,11 +1,6 @@
|
|||||||
// Package lexer provides basic helpers to implement parsers
|
// Package lexer provides basic helpers to implement parsers
|
||||||
package lexer
|
package lexer
|
||||||
|
|
||||||
import (
|
|
||||||
"errors"
|
|
||||||
"io"
|
|
||||||
)
|
|
||||||
|
|
||||||
// StateFn is a State Function of the parser
|
// StateFn is a State Function of the parser
|
||||||
type StateFn func() (StateFn, error)
|
type StateFn func() (StateFn, error)
|
||||||
|
|
||||||
@@ -16,11 +11,7 @@ func Run(fn StateFn) error {
|
|||||||
var err error
|
var err error
|
||||||
|
|
||||||
fn, err = fn()
|
fn, err = fn()
|
||||||
switch {
|
if err != nil {
|
||||||
case errors.Is(err, io.EOF):
|
|
||||||
// EOF
|
|
||||||
return nil
|
|
||||||
case err != nil:
|
|
||||||
// failed
|
// failed
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -64,3 +64,29 @@ func (p *Position) StepLine() {
|
|||||||
p.Line++
|
p.Line++
|
||||||
p.Column = 1
|
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