Documentation ¶
Overview ¶
Package ragel provides helper functions and types for building ragel-based parsers.
The ragel state machine compiler is available from http://www.complang.org/ragel/.
Index ¶
Constants ¶
This section is empty.
Variables ¶
Functions ¶
This section is empty.
Types ¶
type AppendReader ¶
type AppendReader struct {
// contains filtered or unexported fields
}
AppendReader implements reading arbitrarily sized, byte delimited data into a slice and updating ragel state machine variables.
func NewAppendReader ¶
func NewAppendReader(r *bufio.Reader, p, pe, eof *int, data *[]byte, delim byte) (*AppendReader, error)
NewAppendReader returns a new AppenReader that reads from r. Pointers to the ragel state machine variables p, pe, eof and data slice must be provided. These variables are updated on each read. An error is returned if a pointer to any of the required ragel variables is nil.
func (*AppendReader) BackupTo ¶
func (r *AppendReader) BackupTo(b byte) error
BackupTo scans backwards from the position pe in the data variable to the first instance of b, setting pe to the next position from the found byte. ErrNotFound is returned and pe is not updated if b is not found.
func (*AppendReader) Buffered ¶
func (r *AppendReader) Buffered() int
Buffered returns the number of bytes that can be processed in the current block.
func (*AppendReader) Read ¶
func (r *AppendReader) Read() (n int, err error)
Read reads data from the underlying reader until the the first instant of the AppendReader's delim byte growing the data slice as necessary, but first moving read but unprocessed data to the start of the data slice if the p ragel variable has passed len(data)/2. Read returns the number of bytes read and any error encountered during the read. io.ErrUnexpectedEOF is returned if data does not end in the specified delimeter. Read sets the ragel eof variable to the value of pe if the read returns an io.EOF or io.ErrUnexpectedEOF error.
type AppendScanner ¶
type AppendScanner struct {
// contains filtered or unexported fields
}
AppendScanner implements reading arbitrarily sized, byte delimited data into a slice and updating ragel state machine variables.
func NewAppendScanner ¶
func NewAppendScanner(r *bufio.Reader, p, pe, ts, te, eof *int, data *[]byte, delim byte) (*AppendScanner, error)
NewAppendScanner returns a new AppenReader that reads from r. Pointers to the ragel state machine variables p, pe, ts, te, eof and data must be provided. These variables are updated on each read. An error is returned if a pointer to any of the required ragel variables is nil.
func (*AppendScanner) Buffered ¶
func (r *AppendScanner) Buffered() int
Buffered returns the number of bytes that can be processed in the current block.
func (*AppendScanner) Read ¶
func (r *AppendScanner) Read() (n int, err error)
Read reads data from the underlying reader until the the first instant of the AppendScanner's delim byte growing the data slice as necessary, but first moving read unprocessed data to the start of the data array if the ts ragel variable is non-zero. Read returns the number of bytes read and any error encountered during the read. io.ErrUnexpectedEOF is returned if data does not end in the specified delimeter. Read sets the ragel eof variable to the value of pe if the read returns an io.EOF or io.ErrUnexpectedEOF error.
type BlockReader ¶
type BlockReader struct {
// contains filtered or unexported fields
}
BlockReader implements reading defined block size data into a provided slice and updating ragel state machine variables.
func NewBlockReader ¶
NewBlockReader returns a new BlockReader that reads from r. Pointers to the ragel state machine variables p, pe and eof, and a data slice must be provided. These variables are updated on each read. An error is returned if a pointer to any of the required ragel variables is nil.
func (*BlockReader) BackupTo ¶
func (r *BlockReader) BackupTo(b byte) error
BackupTo scans backwards from the position pe in the data variable to the first instance of b, setting pe to the next position from the found byte. ErrNotFound is returned and pe is not updated if b is not found.
func (*BlockReader) Buffered ¶
func (r *BlockReader) Buffered() int
Buffered returns the number of bytes that can be processed in the current block.
func (*BlockReader) Read ¶
func (r *BlockReader) Read() (n int, err error)
Read reads data from the underlying reader until the ragel data variable is full, first moving read but unprocessed data to the start of the data slice if the p ragel variable has passed len(data)/2. Read returns the number of bytes read and any error encountered during the read. ErrBufferFull is returned if the data variable is full prior to reading and after any potential data shift. Read sets the ragel eof variable to the value of pe if the read returns an io.EOF error.
type BlockScanner ¶
type BlockScanner struct {
// contains filtered or unexported fields
}
BlockScanner implements reading defined block size data into a provided slice and updating ragel state machine variables.
func NewBlockScanner ¶
NewBlockScanner returns a new BlockScanner that reads from r. Pointers to the ragel state machine variables p, pe, ts, te and eof, and a data slice must be provided. These variables are updated on each read. An error is returned if a pointer to any of the required ragel variables is nil.
func (*BlockScanner) Buffered ¶
func (r *BlockScanner) Buffered() int
Buffered returns the number of bytes that can be processed in the current block.
func (*BlockScanner) Read ¶
func (r *BlockScanner) Read() (n int, err error)
Read reads data from the underlying reader until the ragel data variable is full, first moving read but unprocessed data to the start of the data array if the ts ragel variable is non-zero. Read returns the number of bytes read and any error encountered during the read. ErrBufferFull is returned if the data variable is full prior to reading and after any potential data shift. Read sets the ragel eof variable to the value of pe if the read returns an io.EOF error.