Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ansi: add a End of Sequence item for the ParserDispatcher to complete on #218

Open
pachecot opened this issue Oct 18, 2024 · 0 comments
Open
Labels
enhancement New feature or request

Comments

@pachecot
Copy link
Contributor

I was noticing that the ParserDispatcher can not complete cleanly, it gets no signal that the buffer has ended and you need to check it at the end. You can see it here in the example.

examples/parserlog/main.go

parser.Parse(dispatcher, bts)
if str != "" {
    fmt.Printf("[Print] %s\n", str) 
}

having some irritation with checking and cleaning up state at the end, like shown here with the str != ""

It would be nice to add a nil terminating Sequence item to the sequence to allow the ParserDispatcher a chance to clean any state.
We would need to small change in the parser.Parse function to something like this.

// Parse parses the given dispatcher and byte buffer.
func (p *Parser) Parse(dispatcher ParserDispatcher, b []byte) {
	for i := 0; i < len(b); i++ {
		p.Advance(dispatcher, b[i], i < len(b)-1)
	}
	dispatcher(SequenceEnd(0))  /// <-- added line 
}

Thanks
Tom

@pachecot pachecot added the enhancement New feature or request label Oct 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant