|
|
@ -1,6 +1,11 @@ |
|
|
|
// 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) |
|
|
|
|
|
|
|
|
|
|
@ -11,7 +16,11 @@ func Run(fn StateFn) error { |
|
|
|
var err error |
|
|
|
var err error |
|
|
|
|
|
|
|
|
|
|
|
fn, err = fn() |
|
|
|
fn, err = fn() |
|
|
|
if err != nil { |
|
|
|
switch { |
|
|
|
|
|
|
|
case errors.Is(err, io.EOF): |
|
|
|
|
|
|
|
// EOF
|
|
|
|
|
|
|
|
return nil |
|
|
|
|
|
|
|
case err != nil: |
|
|
|
// failed
|
|
|
|
// failed
|
|
|
|
return err |
|
|
|
return err |
|
|
|
} |
|
|
|
} |
|
|
|