Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type DelimitedReader ¶
type DelimitedReader struct {
// contains filtered or unexported fields
}
DelimitedReader reads arbitrarily sized bytes slices until a delimiter is found. It depends on and it keeps track of Ragel's state variables.
func ArbitraryReader ¶
func ArbitraryReader(r io.Reader, delim byte) *DelimitedReader
ArbitraryReader returns a Reader that reads from r but stops when it finds a delimiter. The underlying implementation is a *DelimitedReader.
func (*DelimitedReader) Read ¶
func (r *DelimitedReader) Read() (line []byte, err error)
Read reads a chunk of bytes until it finds a delimiter.
It always works on the current boundaries of the data, and updates them accordingly. It returns the chunk of bytes read and, eventually, an error. When delim is not found it returns an io.ErrUnexpectedEOF.
func (*DelimitedReader) Seek ¶
func (r *DelimitedReader) Seek(until byte, backwards bool) (n int, err error)
Seek look for the first instance of until.
It always works on the current boundaries of the data. When it finds what it looks for it returns the number of bytes sought before to find it. Otherwise will also return an error. Search is only backwards at the moment, from the right boundary (end) to the left one (start position). It returns the number of bytes read to find the first occurrence of the until byte. It sets the right boundary (end) of the data to the character after the until byte, so the user can eventually start again from here.
func (DelimitedReader) State ¶
func (r DelimitedReader) State() *State
State returns a pointer to the current State.
type Machiner ¶
type Machiner interface { // Exec contains the ragel finite-state machine code and returns boundaries. Exec(state *State) (p int, pe int) // OnErr is a method called when an error is encountered. OnErr(chunk []byte, err error) // OnEOF is a method called when an EOF is encountered. OnEOF(chunk []byte) // OnCompletion is a method called when the parser loop completes. OnCompletion() }
Machiner is an interface that wraps the Exec method.
type Option ¶
type Option func(*parser)
Option represents an option for parser brokers.
func WithFirstFinal ¶
WithFirstFinal serves to specify the ragel first final state.
type Parser ¶
type Parser parser
Parser creates ragel parsers for stream inputs.
Its scope is to let the user concentrate on the definition of the ragel machines. To do so it allows the user to specify (and delegates to) how to read the input chunks and how to parse them.
func (*Parser) Parse ¶
func (p *Parser) Parse()
Parse is the standard parsing method for stream inputs.
It calls the Read method of the Reader, which defines how and what to read and then it calls on such data window the finite-state machine to parse its content. It stops whenever and EOF or an error happens.
type Reader ¶
Reader is the interface that wraps the Read method. Its implementations are intended to be used with Ragel parsers or scanners.
type Seeker ¶
Seeker is the interface that wraps the Seek method. Its implementations are intended to be used with Ragel parsers or scanners.