Documentation
¶
Overview ¶
Package parsley a parser/tokeniser used to evaluate expressions
Index ¶
- Constants
- func ToBool(e any) (bool, error)
- func ToFloat64(input any) (float64, error)
- func TypesMatch(a, b any) bool
- type BinaryNodeFunc
- type Function
- type Node
- type Parser
- func (m *Parser) Close()
- func (m *Parser) ParseAsAny(str string, data map[string]any) (any, error)
- func (m *Parser) ParseAsBool(str string, data map[string]any) (bool, error)
- func (m *Parser) ParseAsFloat(str string, data map[string]any) (float64, error)
- func (m *Parser) ParseAsString(str string, data map[string]any) (string, error)
- func (p *Parser) RegisterBinaryNode(token string, fun BinaryNodeFunc)
- func (p *Parser) RegisterFunction(name string, fun Function)
- func (p *Parser) RegisterUnaryNode(token string, fun UnaryNodeFunc)
- type UnaryNodeFunc
Constants ¶
const ErrCacheSetup = cache.ErrCacheSetup
ErrCacheSetup is returned when setting up the cache fails
const ErrComparisonFailed = nodes.ErrComparisonFailed
ErrComparisonFailed is returned when the comparison of two values fails
const ErrFunctionNotFound = helpers.ConstError("function not found")
ErrFunctionNotFound is returned when an unrecognised function is found
const ErrNodeEvalFailed = nodes.ErrNodeEvalFailed
ErrNodeEvalFailed is returned when a node failed to evaluate correctly
Variables ¶
This section is empty.
Functions ¶
func ToBool ¶
ToBool converts the input value in to a bool.
- If the type is a number then any value over 0 will return true - Strings will be checked against known values - Strings not matching a known value will attempt to parse as a float
func ToFloat64 ¶
ToFloat64 attempts to convert the input value in to a float64. It will cast int/uint/flaot types, and attempt to parse strings as floats
func TypesMatch ¶
TypesMatch check if the types of the two values are the same
Types ¶
type BinaryNodeFunc ¶
BinaryNodeFunc is a constructor for a binary node
type Parser ¶
type Parser struct {
Registry *registry
// contains filtered or unexported fields
}
Parser provides parsing and evaluation functionality
func NewParser ¶
NewParser configures a new parser. If a cache it required one will be set up using github.com/dgraph-io/ristretto/v2
func (*Parser) ParseAsAny ¶
ParseAsAny will parse and evaluate the expression provided. Returning the result as a whichever type is most appropriate
func (*Parser) ParseAsBool ¶
ParseAsBool is used to test whether the incoming data matches the given expression. Any numeric value over 0, or strings evaluating to true will match
func (*Parser) ParseAsFloat ¶
ParseAsFloat will parse and evaluate the expression provided. Returning the result as a float64
func (*Parser) ParseAsString ¶
ParseAsString will parse and evaluate the expression provided. Returning the result as a string, if the expression results in any other type it will be printed as a string
func (*Parser) RegisterBinaryNode ¶
func (p *Parser) RegisterBinaryNode(token string, fun BinaryNodeFunc)
RegisterBinaryNode adds a new binary node to the registry
func (*Parser) RegisterFunction ¶
RegisterFunction registers a new function in the available set. Repeated calls will result in the latest one being registered
func (*Parser) RegisterUnaryNode ¶
func (p *Parser) RegisterUnaryNode(token string, fun UnaryNodeFunc)
RegisterUnaryNode adds a new unary node to the registry
type UnaryNodeFunc ¶
UnaryNodeFunc is a constructor for a unary node
Directories
¶
| Path | Synopsis |
|---|---|
|
internal
|
|
|
assert
Package assert is used exclusively for asserting unit test output
|
Package assert is used exclusively for asserting unit test output |
|
cache
Package cache is used to caches parsed expressions ready to be re-evaluated with different data
|
Package cache is used to caches parsed expressions ready to be re-evaluated with different data |
|
helpers
Package helpers is a bunch of useful functions
|
Package helpers is a bunch of useful functions |
|
nodes
Package nodes provides implementation and interfaces for the various supported node types
|
Package nodes provides implementation and interfaces for the various supported node types |