excellent

package
v0.110.1 Latest Latest
Warning

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

Go to latest
Published: Jan 18, 2021 License: AGPL-3.0 Imports: 15 Imported by: 6

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EvaluateExpression

func EvaluateExpression(env envs.Environment, context *types.XObject, expression string) types.XValue

EvaluateExpression evalutes the passed in Excellent expression, returning the typed value it evaluates to, which might be an error, e.g. "2 / 3" or "contact.fields.age"

func EvaluateTemplate

func EvaluateTemplate(env envs.Environment, context *types.XObject, template string, escaping Escaping) (string, error)

EvaluateTemplate evaluates the passed in template

func EvaluateTemplateValue added in v0.28.14

func EvaluateTemplateValue(env envs.Environment, context *types.XObject, template string) (types.XValue, error)

EvaluateTemplateValue is equivalent to EvaluateTemplate except in the case where the template contains a single identifier or expression, ie: "@contact" or "@(first(contact.urns))". In these cases we return the typed value from EvaluateExpression instead of stringifying the result.

func HasExpressions added in v0.76.1

func HasExpressions(template string, allowedTopLevels []string) bool

HasExpressions returns whether the given template contains any expressions or identifiers

func VisitExpression added in v0.28.14

func VisitExpression(expression string, visitor antlr.ParseTreeVisitor) (interface{}, error)

VisitExpression parses and visits the given expression with the given visitor

func VisitTemplate added in v0.28.14

func VisitTemplate(template string, allowedTopLevels []string, callback func(XTokenType, string) error) error

VisitTemplate scans the given template and calls the callback for each token encountered

Types

type ErrorListener added in v0.28.14

type ErrorListener struct {
	*antlr.DefaultErrorListener
	// contains filtered or unexported fields
}

ErrorListener records syntax errors

func NewErrorListener added in v0.6.2

func NewErrorListener(expression string) *ErrorListener

NewErrorListener creates a new error listener

func (*ErrorListener) Errors added in v0.28.14

func (l *ErrorListener) Errors() []error

Errors returns the errors encountered so far

func (*ErrorListener) SyntaxError added in v0.28.14

func (l *ErrorListener) SyntaxError(recognizer antlr.Recognizer, offendingSymbol interface{}, line, column int, msg string, e antlr.RecognitionException)

SyntaxError handles a new syntax error encountered by the recognizer

type Escaping added in v0.55.0

type Escaping func(string) string

Escaping is a function applied to expressions in a template after they've been evaluated

type Scanner added in v0.13.3

type Scanner interface {
	Scan() (XTokenType, string)
	SetUnescapeBody(bool)
}

Scanner is something which can scan tokens from input

func NewXScanner added in v0.6.2

func NewXScanner(r io.Reader, identifierTopLevels []string) Scanner

NewXScanner returns a new instance of our excellent scanner

type TemplateError added in v0.10.1

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

TemplateError is an error which occurs during evaluation of an expression

func (TemplateError) Error added in v0.10.1

func (e TemplateError) Error() string

type TemplateErrors

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

TemplateErrors represents the list of all errors encountered during evaluation of a template

func NewTemplateErrors added in v0.10.1

func NewTemplateErrors() *TemplateErrors

NewTemplateErrors creates a new empty lsit of template errors

func (*TemplateErrors) Add added in v0.10.1

func (e *TemplateErrors) Add(expression, message string)

Add adds an error for the given expression

func (*TemplateErrors) Error

func (e *TemplateErrors) Error() string

Error returns a single string describing all the errors encountered

func (*TemplateErrors) HasErrors added in v0.10.1

func (e *TemplateErrors) HasErrors() bool

HasErrors returns whether there are errors

type XTokenType added in v0.13.3

type XTokenType int

XTokenType is a set of types than can be scanned

const (
	// BODY - Not in expression
	BODY XTokenType = iota

	// IDENTIFIER - 'contact.age' in '@contact.age'
	IDENTIFIER

	// EXPRESSION - the body of an expression '1+2' in '@(1+2)'
	EXPRESSION

	// EOF - end of expression
	EOF
)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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