parsley

package
v0.8.2 Latest Latest
Warning

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

Go to latest
Published: Oct 1, 2018 License: MPL-2.0 Imports: 5 Imported by: 14

Documentation

Index

Constants

View Source
const NilPos = Pos(0)

NilPos represents an invalid position

View Source
const NilPosition = nilPosition(0)

NilPosition represents an invalid position

Variables

This section is empty.

Functions

func Parse

func Parse(ctx *Context, p Parser) (Node, Error)

Parse parses the given input and returns with the root node of the AST. It expects a reader and the root parser. If there are multiple possible parse trees only the first one is returned.

Types

type Context added in v0.8.0

type Context struct {
	// contains filtered or unexported fields
}

Context is the parsing context passed to all parsers

func NewContext added in v0.8.0

func NewContext(reader Reader) *Context

NewContext creates a new parsing context

func (*Context) CallCount added in v0.8.0

func (c *Context) CallCount() int

CallCount returns with the call count

func (*Context) Error added in v0.8.0

func (c *Context) Error() Error

Error returns with the parse error with the highest position (if any)

func (*Context) OverrideError added in v0.8.0

func (c *Context) OverrideError(err Error)

OverrideError overrides any previously set errors

func (*Context) Reader added in v0.8.0

func (c *Context) Reader() Reader

Reader returns with the reader

func (*Context) RegisterCall added in v0.8.0

func (c *Context) RegisterCall()

RegisterCall registers a call

func (*Context) ResultCache added in v0.8.0

func (c *Context) ResultCache() ResultCache

ResultCache returns with the result cache object

func (*Context) SetError added in v0.8.0

func (c *Context) SetError(pos Pos, cause error)

SetError saves the error if it has the highest position for found errors

func (*Context) SetErrorf added in v0.8.0

func (c *Context) SetErrorf(pos Pos, format string, values ...interface{})

SetErrorf saves the error if it has the highest position for found errors

type Error added in v0.6.0

type Error interface {
	error
	Cause() error
	Pos() Pos
}

Error is an error with a position

func Evaluate

func Evaluate(ctx *Context, p Parser, evalCtx interface{}) (interface{}, Error)

Evaluate parses the given input and evaluates it. It expects a reader, the root parser and the evaluation context. If there are multiple possible parse trees only the first one is used for evaluation.

func NewError added in v0.6.0

func NewError(pos Pos, cause error) Error

NewError creates a new error with the given position If the passed error is already a parsley.Error it returns the original error as it should have already the correct position.

func NewErrorf added in v0.7.0

func NewErrorf(pos Pos, format string, values ...interface{}) Error

NewErrorf creates a new error with the given position and message

func WrapError added in v0.6.0

func WrapError(e Error, format string, values ...interface{}) Error

WrapError wraps the given error in a error If format contains the "{{err}}" placeholder it will be replaced with the original error message

type File added in v0.6.0

type File interface {
	Position(int) Position
	Pos(int) Pos
	Len() int
	SetOffset(int)
}

File is an interface to translate a byte offset in a file to a position object

type FileSet added in v0.6.0

type FileSet struct {
	// contains filtered or unexported fields
}

FileSet contains multiple files

func NewFileSet added in v0.6.0

func NewFileSet(files ...File) *FileSet

NewFileSet creates a new file set

func (*FileSet) AddFile added in v0.6.0

func (fs *FileSet) AddFile(f File)

AddFile adds a new file

func (*FileSet) ErrorWithPosition added in v0.6.0

func (fs *FileSet) ErrorWithPosition(err Error) error

ErrorWithPosition creates an error with a human-readable position

func (*FileSet) Position added in v0.6.0

func (fs *FileSet) Position(pos Pos) Position

Position returns with a position object for a given global position

type Interpreter added in v0.6.0

type Interpreter interface {
	Eval(ctx interface{}, nodes []Node) (interface{}, Error)
}

Interpreter defines an interface to evaluate AST nodes

type Node added in v0.6.0

type Node interface {
	Token() string
	Value(ctx interface{}) (interface{}, Error)
	Pos() Pos
	ReaderPos() Pos
}

Node represents an AST node

type Parser added in v0.6.0

type Parser interface {
	Parse(ctx *Context, leftRecCtx data.IntMap, pos Pos) (Node, data.IntSet)
	Name() string
}

Parser defines a parser interface

type Pos added in v0.6.0

type Pos int

Pos is a global offset in a file set which can be translated into a concrete file position

type Position added in v0.6.0

type Position interface {
	fmt.Stringer
}

Position is an interface to translate a file position to a string

type Reader added in v0.6.0

type Reader interface {
	Pos(int) Pos
	Remaining(Pos) int
	IsEOF(Pos) bool
}

Reader is a reader interface for parsing

type Result added in v0.6.0

type Result struct {
	LeftRecCtx        data.IntMap
	CurtailingParsers data.IntSet
	Node              Node
}

Result is a stored parser result

type ResultCache added in v0.8.0

type ResultCache map[int]map[Pos]*Result

ResultCache records information about parser calls

func NewResultCache added in v0.8.0

func NewResultCache() ResultCache

NewHistory creates a history instance

func (ResultCache) Get added in v0.8.0

func (rc ResultCache) Get(parserIndex int, pos Pos, leftRecCtx data.IntMap) (*Result, bool)

Get return with a previously saved result

func (ResultCache) Save added in v0.8.0

func (rc ResultCache) Save(parserIndex int, pos Pos, result *Result)

Save registers a parser result for a certain position

Directories

Path Synopsis
Code generated by counterfeiter.
Code generated by counterfeiter.

Jump to

Keyboard shortcuts

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