Skip to content

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

@pachecot

Description

@pachecot

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions