excellent

package
v0.168.0 Latest Latest
Warning

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

Go to latest
Published: Aug 12, 2022 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, ctx *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, ctx *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, ctx *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 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 Addition added in v0.141.0

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

func (*Addition) Evaluate added in v0.141.0

func (x *Addition) Evaluate(env envs.Environment, scope *Scope) types.XValue

func (*Addition) String added in v0.141.0

func (x *Addition) String() string

type AnonFunction added in v0.141.0

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

func (*AnonFunction) Evaluate added in v0.141.0

func (x *AnonFunction) Evaluate(env envs.Environment, scope *Scope) types.XValue

func (*AnonFunction) String added in v0.141.0

func (x *AnonFunction) String() string

type ArrayLookup added in v0.141.0

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

func (*ArrayLookup) Evaluate added in v0.141.0

func (x *ArrayLookup) Evaluate(env envs.Environment, scope *Scope) types.XValue

func (*ArrayLookup) String added in v0.141.0

func (x *ArrayLookup) String() string

type BooleanLiteral added in v0.141.0

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

BooleanLiteral is a literal bool

func (*BooleanLiteral) Evaluate added in v0.141.0

func (x *BooleanLiteral) Evaluate(env envs.Environment, scope *Scope) types.XValue

func (*BooleanLiteral) String added in v0.141.0

func (x *BooleanLiteral) String() string

type Concatenation added in v0.141.0

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

func (*Concatenation) Evaluate added in v0.141.0

func (x *Concatenation) Evaluate(env envs.Environment, scope *Scope) types.XValue

func (*Concatenation) String added in v0.141.0

func (x *Concatenation) String() string

type ContextReference added in v0.141.0

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

ContextReference is an identifier which is a function name or root variable in the context

func (*ContextReference) Evaluate added in v0.141.0

func (x *ContextReference) Evaluate(env envs.Environment, scope *Scope) types.XValue

func (*ContextReference) String added in v0.141.0

func (x *ContextReference) String() string

type Division added in v0.141.0

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

func (*Division) Evaluate added in v0.141.0

func (x *Division) Evaluate(env envs.Environment, scope *Scope) types.XValue

func (*Division) String added in v0.141.0

func (x *Division) String() string

type DotLookup added in v0.141.0

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

func (*DotLookup) Evaluate added in v0.141.0

func (x *DotLookup) Evaluate(env envs.Environment, scope *Scope) types.XValue

func (*DotLookup) String added in v0.141.0

func (x *DotLookup) String() string

type Equality added in v0.141.0

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

func (*Equality) Evaluate added in v0.141.0

func (x *Equality) Evaluate(env envs.Environment, scope *Scope) types.XValue

func (*Equality) String added in v0.141.0

func (x *Equality) String() string

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 Exponent added in v0.141.0

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

func (*Exponent) Evaluate added in v0.141.0

func (x *Exponent) Evaluate(env envs.Environment, scope *Scope) types.XValue

func (*Exponent) String added in v0.141.0

func (x *Exponent) String() string

type Expression added in v0.141.0

type Expression interface {
	Evaluate(envs.Environment, *Scope) types.XValue
	String() string
}

Expression is the base interface of all syntax elements

func Parse added in v0.141.0

func Parse(expression string, contextCallback func([]string)) (Expression, error)

Parse parses an expression

type FunctionCall added in v0.141.0

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

func (*FunctionCall) Evaluate added in v0.141.0

func (x *FunctionCall) Evaluate(env envs.Environment, scope *Scope) types.XValue

func (*FunctionCall) String added in v0.141.0

func (x *FunctionCall) String() string

type GreaterThan added in v0.141.0

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

func (*GreaterThan) Evaluate added in v0.141.0

func (x *GreaterThan) Evaluate(env envs.Environment, scope *Scope) types.XValue

func (*GreaterThan) String added in v0.141.0

func (x *GreaterThan) String() string

type GreaterThanOrEqual added in v0.141.0

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

func (*GreaterThanOrEqual) Evaluate added in v0.141.0

func (x *GreaterThanOrEqual) Evaluate(env envs.Environment, scope *Scope) types.XValue

func (*GreaterThanOrEqual) String added in v0.141.0

func (x *GreaterThanOrEqual) String() string

type InEquality added in v0.141.0

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

func (*InEquality) Evaluate added in v0.141.0

func (x *InEquality) Evaluate(env envs.Environment, scope *Scope) types.XValue

func (*InEquality) String added in v0.141.0

func (x *InEquality) String() string

type LessThan added in v0.141.0

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

func (*LessThan) Evaluate added in v0.141.0

func (x *LessThan) Evaluate(env envs.Environment, scope *Scope) types.XValue

func (*LessThan) String added in v0.141.0

func (x *LessThan) String() string

type LessThanOrEqual added in v0.141.0

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

func (*LessThanOrEqual) Evaluate added in v0.141.0

func (x *LessThanOrEqual) Evaluate(env envs.Environment, scope *Scope) types.XValue

func (*LessThanOrEqual) String added in v0.141.0

func (x *LessThanOrEqual) String() string

type Multiplication added in v0.141.0

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

func (*Multiplication) Evaluate added in v0.141.0

func (x *Multiplication) Evaluate(env envs.Environment, scope *Scope) types.XValue

func (*Multiplication) String added in v0.141.0

func (x *Multiplication) String() string

type Negation added in v0.141.0

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

func (*Negation) Evaluate added in v0.141.0

func (x *Negation) Evaluate(env envs.Environment, scope *Scope) types.XValue

func (*Negation) String added in v0.141.0

func (x *Negation) String() string

type NullLiteral added in v0.141.0

type NullLiteral struct{}

func (*NullLiteral) Evaluate added in v0.141.0

func (x *NullLiteral) Evaluate(env envs.Environment, scope *Scope) types.XValue

func (*NullLiteral) String added in v0.141.0

func (x *NullLiteral) String() string

type NumberLiteral added in v0.141.0

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

NumberLiteral is a literal number like 123 or 1.5

func (*NumberLiteral) Evaluate added in v0.141.0

func (x *NumberLiteral) Evaluate(env envs.Environment, scope *Scope) types.XValue

func (*NumberLiteral) String added in v0.141.0

func (x *NumberLiteral) String() string

type Parentheses added in v0.141.0

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

func (*Parentheses) Evaluate added in v0.141.0

func (x *Parentheses) Evaluate(env envs.Environment, scope *Scope) types.XValue

func (*Parentheses) String added in v0.141.0

func (x *Parentheses) String() string

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 Scope added in v0.141.0

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

Scope provides access to context objects

func NewScope added in v0.141.0

func NewScope(ctx *types.XObject, parent *Scope) *Scope

NewScope creates a new evaluation scope with an optional parent

func (*Scope) Get added in v0.141.0

func (s *Scope) Get(name string) (types.XValue, bool)

Get looks up a named value in the context

type Subtraction added in v0.141.0

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

func (*Subtraction) Evaluate added in v0.141.0

func (x *Subtraction) Evaluate(env envs.Environment, scope *Scope) types.XValue

func (*Subtraction) String added in v0.141.0

func (x *Subtraction) String() string

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 TextLiteral added in v0.141.0

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

func (*TextLiteral) Evaluate added in v0.141.0

func (x *TextLiteral) Evaluate(env envs.Environment, scope *Scope) types.XValue

func (*TextLiteral) String added in v0.141.0

func (x *TextLiteral) String() string

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