WIP: lexer: introduce StateFn, Accept()/AcceptAll() and Position to aid parsing #3

Closed
amery wants to merge 3 commits from pr-amery-lexer into main
Showing only changes of commit d760902dce - Show all commits
+17
View File
@@ -0,0 +1,17 @@
// Package lexer provides basic helpers to implement parsers
package lexer
// StateFn is a State Function of the parser
type StateFn func() (StateFn, error)
// Run runs a state machine until the state function either
// returns nil or an error
func Run(fn StateFn) error {
var err error
for fn != nil && err == nil {
fn, err = fn()
}
return err
}