From 05d504346efa610284fa9ea8e7eecba80f57b859 Mon Sep 17 00:00:00 2001 From: Alejandro Mery Date: Wed, 30 Aug 2023 01:50:12 +0100 Subject: [PATCH] lexer: extend Run() to treat io.EOF as non-error termination Signed-off-by: Alejandro Mery --- lexer/lexer.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/lexer/lexer.go b/lexer/lexer.go index e23ecad..991372c 100644 --- a/lexer/lexer.go +++ b/lexer/lexer.go @@ -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 }