diff --git a/lexer/lexer.go b/lexer/lexer.go index 2ee64ef..39b0c8b 100644 --- a/lexer/lexer.go +++ b/lexer/lexer.go @@ -3,6 +3,35 @@ package lexer import "io" +// Lexer adds Accept and AcceptAll support to a +// [io.RuneScanner] +type Lexer struct { + io.RuneScanner +} + +// Accept consumes a rune from the source if it meets the condition. +// it returns true if the condition was met and false if it wasn't. +func (p Lexer) Accept(cond func(rune) bool) bool { + return Accept(p, cond) +} + +// AcceptAll consumes runes from the source as long as they meet the +// condition. it returns true if the condition was met for at least one rune, +// and false if it wasn't. +func (p Lexer) AcceptAll(cond func(rune) bool) bool { + return AcceptAll(p, cond) +} + +// NewLexer extends a [io.RuneScanner] with Accept()/AcceptAll() +// functionality +func NewLexer(src io.RuneScanner) *Lexer { + if src == nil { + return nil + } + + return &Lexer{src} +} + // StateFn is a State Function of the parser type StateFn func() (StateFn, error)