parser

package
v0.0.0-...-5f46317 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 25, 2019 License: MIT Imports: 3 Imported by: 9

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 WithError

func WithError(err int) Option

WithError serves to specify the ragel error state.

func WithFirstFinal

func WithFirstFinal(f int) Option

WithFirstFinal serves to specify the ragel first final state.

func WithStart

func WithStart(cs int) Option

WithStart serves to specify the ragel start 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 New

func New(r Reader, m Machiner, opts ...Option) *Parser

New cretes a new Parser.

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

type Reader interface {
	Read() (res []byte, err error)
	State() *State
}

Reader is the interface that wraps the Read method. Its implementations are intended to be used with Ragel parsers or scanners.

type Seeker

type Seeker interface {
	Seek(until byte, backward bool) (n int, err error)
}

Seeker is the interface that wraps the Seek method. Its implementations are intended to be used with Ragel parsers or scanners.

type State

type State parsingState

State represents the ragel state variables for parsing.

func (*State) Get

func (s *State) Get() (cs, p, pe, eof int, data []byte)

Get retrieves the state variables of a ragel parser.

func (*State) Set

func (s *State) Set(cs, p, pe, eof int)

Set sets the state variables of a ragel parser.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL