Documentation ¶
Index ¶
- Constants
- Variables
- func Evaluate(ctx *Context, p Parser) (interface{}, error)
- func IsNotFoundError(err error) bool
- func IsWhitespaceError(err error) bool
- func NewWhitespaceError(msg string) error
- func Transform(userCtx interface{}, node Node) (Node, Error)
- func Walk(node Node, f func(n Node) bool) bool
- type Context
- func (c *Context) CallCount() int
- func (c *Context) EnableStaticCheck()
- func (c *Context) EnableTransformation()
- func (c *Context) Error() Error
- func (c *Context) FileSet() *FileSet
- func (c *Context) IsKeyword(word string) bool
- func (c *Context) Reader() Reader
- func (c *Context) RegisterCall()
- func (c *Context) RegisterKeywords(keywords ...string)
- func (c *Context) ResultCache() ResultCache
- func (c *Context) SetError(err Error)
- func (c *Context) SetUserContext(userCtx interface{})
- func (c *Context) StaticCheckEnabled() bool
- func (c *Context) TransformationEnabled() bool
- func (c *Context) UserContext() interface{}
- type Error
- type File
- type FileSet
- type Interpreter
- type LiteralNode
- type Node
- type NodeTransformFunc
- type NodeTransformer
- type NodeTransformerInterpreter
- type NodeTransformerRegistry
- type NonLiteralNode
- type NonTerminalNode
- type NotFoundError
- type Parser
- type Pos
- type Position
- type Reader
- type Result
- type ResultCache
- type StaticCheckable
- type StaticCheckableNode
- type StaticChecker
- type StaticCheckerInterpreter
- type Transformable
- type TransformableNode
- type Walkable
- type WalkableNode
Constants ¶
const NilPos = Pos(0)
NilPos represents an invalid position
const NilPosition = nilPosition(0)
NilPosition represents an invalid position
Variables ¶
var ErrNoValue = errors.New("node does not have a value")
Functions ¶
func Evaluate ¶
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 IsWhitespaceError ¶ added in v0.17.0
func NewWhitespaceError ¶ added in v0.17.0
NewWhitespaceError creates a new whitespace error
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
NewContext creates a new parsing context
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
Error returns with the parse error with the highest position (if any)
func (*Context) RegisterCall ¶ added in v0.8.0
func (c *Context) RegisterCall()
RegisterCall registers a call
func (*Context) RegisterKeywords ¶ added in v0.17.0
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
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
StaticCheckEnabled will return true if static checking is enabled
func (*Context) TransformationEnabled ¶ added in v0.17.0
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
Error is an error with a position
func EvaluateNode ¶ added in v0.17.0
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
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 StaticCheck ¶ added in v0.17.0
StaticCheck will run static checking on the given node
type File ¶ added in v0.6.0
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
NewFileSet creates a new file set
func (*FileSet) ErrorWithPosition ¶ added in v0.6.0
ErrorWithPosition creates an error with a human-readable 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 NodeTransformFunc ¶ added in v0.17.0
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
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 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 ResultCache ¶ added in v0.8.0
ResultCache records information about parser calls
func NewResultCache ¶ added in v0.8.0
func NewResultCache() ResultCache
NewResultCache creates a history instance
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
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