parsley

package
v0.17.0 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2021 License: MPL-2.0 Imports: 4 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

View Source
var ErrNoValue = errors.New("node does not have a value")

Functions

func Evaluate

func Evaluate(ctx *Context, p Parser) (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 IsNotFoundError added in v0.17.0

func IsNotFoundError(err error) bool

func IsWhitespaceError added in v0.17.0

func IsWhitespaceError(err error) bool

func NewWhitespaceError added in v0.17.0

func NewWhitespaceError(msg string) error

NewWhitespaceError creates a new whitespace error

func Transform added in v0.17.0

func Transform(userCtx interface{}, node Node) (Node, Error)

Transform transforms the given node recursively, in a breadth-first manner

func Walk added in v0.17.0

func Walk(node Node, f func(n Node) bool) bool

Walk applies the given function to the node recursively, in a depth-first manner

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(fileSet *FileSet, 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) EnableStaticCheck added in v0.17.0

func (c *Context) EnableStaticCheck()

EnableStaticCheck will turn on static checking

func (*Context) EnableTransformation added in v0.17.0

func (c *Context) EnableTransformation()

EnableTransformation will turn on node transformation

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) FileSet added in v0.17.0

func (c *Context) FileSet() *FileSet

FileSet returns with the file set

func (*Context) IsKeyword added in v0.17.0

func (c *Context) IsKeyword(word string) bool

IsKeyword checks if the given string is a keyword

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) RegisterKeywords added in v0.17.0

func (c *Context) RegisterKeywords(keywords ...string)

RegisterKeywords registers one or more keywords

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(err Error)

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

func (*Context) SetUserContext added in v0.17.0

func (c *Context) SetUserContext(userCtx interface{})

SetUserContext sets the user context

func (*Context) StaticCheckEnabled added in v0.17.0

func (c *Context) StaticCheckEnabled() bool

StaticCheckEnabled will return true if static checking is enabled

func (*Context) TransformationEnabled added in v0.17.0

func (c *Context) TransformationEnabled() bool

TransformationEnabled will return true if transformation is enabled

func (*Context) UserContext added in v0.17.0

func (c *Context) UserContext() interface{}

UserContext returns with the user context

type Error added in v0.6.0

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

Error is an error with a position

func EvaluateNode added in v0.17.0

func EvaluateNode(ctx interface{}, node Node) (interface{}, Error)

EvaluateNode evaluates the value of a node If the node doesn't have a value, it returns with an ErrNoValue error

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 StaticCheck added in v0.17.0

func StaticCheck(userCtx interface{}, node Node) Error

StaticCheck will run static checking on the given node

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(userCtx interface{}, node NonTerminalNode) (interface{}, Error)
}

Interpreter defines an interface to evaluate the given nonterminal node

type LiteralNode added in v0.17.0

type LiteralNode interface {
	Node
	Value() interface{}
}

type Node added in v0.6.0

type Node interface {
	Token() string
	Schema() interface{}
	Pos() Pos
	ReaderPos() Pos
}

Node represents an AST node

func Parse

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

Parse parses the given input and returns with the root node of the AST. If a transformer is set on the context then the result will be transformed using it. If there are multiple possible parse trees only the first one is returned.

type NodeTransformFunc added in v0.17.0

type NodeTransformFunc func(userCtx interface{}, node Node) (Node, Error)

NodeTransformFunc is a function which implements the NodeTransformer interface

func (NodeTransformFunc) TransformNode added in v0.17.0

func (f NodeTransformFunc) TransformNode(userCtx interface{}, node Node) (Node, Error)

TransformNode transforms an AST node to an other

type NodeTransformer added in v0.17.0

type NodeTransformer interface {
	TransformNode(userCtx interface{}, node Node) (Node, Error)
}

NodeTransformer defines an interface to transform an AST node to an other

type NodeTransformerInterpreter added in v0.17.0

type NodeTransformerInterpreter interface {
	Interpreter
	NodeTransformer
}

NodeTransformerInterpreter defines an interpreter which is also a node transformer

type NodeTransformerRegistry added in v0.17.0

type NodeTransformerRegistry interface {
	NodeTransformer(name string) (NodeTransformer, bool)
}

NodeTransformerRegistry contains named node registries

type NonLiteralNode added in v0.17.0

type NonLiteralNode interface {
	Node
	Value(userCtx interface{}) (interface{}, Error)
}

type NonTerminalNode added in v0.17.0

type NonTerminalNode interface {
	NonLiteralNode
	Children() []Node
}

NonTerminalNode represents a nonterminal AST node

type NotFoundError added in v0.17.0

type NotFoundError string

func (NotFoundError) Error added in v0.17.0

func (n NotFoundError) Error() string

type Parser added in v0.6.0

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

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
	Error             Error
	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

NewResultCache 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

type StaticCheckable added in v0.17.0

type StaticCheckable interface {
	StaticCheck(userCtx interface{}) Error
}

StaticCheckable is an interface for nodes that can run a static analysis

type StaticCheckableNode added in v0.17.0

type StaticCheckableNode interface {
	Node
	StaticCheckable
}

StaticCheckableNode defines a node which also implements the StaticCheckable interface

type StaticChecker added in v0.17.0

type StaticChecker interface {
	StaticCheck(userCtx interface{}, node NonTerminalNode) (interface{}, Error)
}

StaticChecker defines an interface to run a static analysis on the given nonterminal node

type StaticCheckerInterpreter added in v0.17.0

type StaticCheckerInterpreter interface {
	Interpreter
	StaticChecker
}

StaticCheckerInterpreter defines an interpreter which is also a static checker

type Transformable added in v0.17.0

type Transformable interface {
	Transform(userCtx interface{}) (Node, Error)
}

Transformable defines an interface about a transformable Node

type TransformableNode added in v0.17.0

type TransformableNode interface {
	Node
	Transformable
}

TransformableNode defines a transformable node

type Walkable added in v0.17.0

type Walkable interface {
	Walk(f func(n Node) bool) bool
}

Walkable is a generic interface to allow to apply a function on the node The Walk function should return true if the walk should be interrupted

type WalkableNode added in v0.17.0

type WalkableNode interface {
	Node
	Walk(f func(n Node) bool) bool
}

WalkableNode defines a node which also implements the Walkable interface

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