diff --git a/parse/api.go b/parse/api.go index 67fcd72..ab1928a 100644 --- a/parse/api.go +++ b/parse/api.go @@ -22,40 +22,23 @@ type API struct { stopped bool // a boolean set to true by Stop() } -// PeekWithResult checks if the upcoming input data matches the provided tokenize.Handler. -// If it does, then true will be returned, false otherwise. The read cursor -// will be kept at the same position, so the next call to Peek() or Accept() -// will start from the same cursor position. -// -// On a successful peek, the results (data + tokens) are returned by the peek. -// They are availablel (as with Accept()) through parse.API.Result. -func (parseAPI *API) PeekWithResult(tokenHandler tokenize.Handler) bool { - tokenAPI := parseAPI.tokenAPI - snap := tokenAPI.MakeSnapshot() - parseAPI.Result.Tokens = nil - parseAPI.Result.Bytes = nil - ok := parseAPI.invokeTokenizeHandler("PeekWithResult", tokenHandler) - if ok { - parseAPI.Result.Tokens = tokenAPI.Output.Tokens() - parseAPI.Result.Bytes = tokenAPI.Output.Bytes() - } - tokenAPI.RestoreSnapshot(snap) - return ok -} - // Peek checks if the upcoming input data matches the provided tokenize.Handler. // If it does, then true will be returned, false otherwise. The read cursor // will be kept at the same position, so the next call to Peek() or Accept() // will start from the same cursor position. // // No results (data + tokens) are returned by Peek(). If want access to the data -// through parse.API.Result, make use of PeekWithResult() instead. +// through parse.API.Result, make use of Peek() instead. func (parseAPI *API) Peek(tokenHandler tokenize.Handler) bool { tokenAPI := parseAPI.tokenAPI snap := tokenAPI.MakeSnapshot() parseAPI.Result.Tokens = nil parseAPI.Result.Bytes = nil ok := parseAPI.invokeTokenizeHandler("Peek", tokenHandler) + if ok { + parseAPI.Result.Tokens = tokenAPI.Output.Tokens() + parseAPI.Result.Bytes = tokenAPI.Output.Bytes() + } tokenAPI.RestoreSnapshot(snap) return ok }