excellent

package
v0.214.3 Latest Latest
Warning

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

Go to latest
Published: May 21, 2024 License: AGPL-3.0, AGPL-3.0-or-later Imports: 14 Imported by: 6

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

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, unescapeBody bool, 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 {
	Exp1 Expression
	Exp2 Expression
}

func (*Addition) Evaluate added in v0.141.0

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

func (*Addition) String added in v0.141.0

func (x *Addition) String() string

func (*Addition) Visit added in v0.204.0

func (x *Addition) Visit(v func(Expression))

type AnonFunction added in v0.141.0

type AnonFunction struct {
	Args []string
	Body Expression
}

func (*AnonFunction) Evaluate added in v0.141.0

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

func (*AnonFunction) String added in v0.141.0

func (x *AnonFunction) String() string

func (*AnonFunction) Visit added in v0.204.0

func (x *AnonFunction) Visit(v func(Expression))

type ArrayLookup added in v0.141.0

type ArrayLookup struct {
	Container Expression
	Lookup    Expression
}

func (*ArrayLookup) Evaluate added in v0.141.0

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

func (*ArrayLookup) String added in v0.141.0

func (x *ArrayLookup) String() string

func (*ArrayLookup) Visit added in v0.204.0

func (x *ArrayLookup) Visit(v func(Expression))

type BooleanLiteral added in v0.141.0

type BooleanLiteral struct {
	Value *types.XBoolean
}

BooleanLiteral is a literal bool

func (*BooleanLiteral) Evaluate added in v0.141.0

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

func (*BooleanLiteral) String added in v0.141.0

func (x *BooleanLiteral) String() string

func (*BooleanLiteral) Visit added in v0.204.0

func (x *BooleanLiteral) Visit(v func(Expression))

type Concatenation added in v0.141.0

type Concatenation struct {
	Exp1 Expression
	Exp2 Expression
}

func (*Concatenation) Evaluate added in v0.141.0

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

func (*Concatenation) String added in v0.141.0

func (x *Concatenation) String() string

func (*Concatenation) Visit added in v0.204.0

func (x *Concatenation) Visit(v func(Expression))

type ContextReference added in v0.141.0

type ContextReference struct {
	Name string
}

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, warnings *Warnings) types.XValue

func (*ContextReference) String added in v0.141.0

func (x *ContextReference) String() string

func (*ContextReference) Visit added in v0.204.0

func (x *ContextReference) Visit(v func(Expression))

type Division added in v0.141.0

type Division struct {
	Exp1 Expression
	Exp2 Expression
}

func (*Division) Evaluate added in v0.141.0

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

func (*Division) String added in v0.141.0

func (x *Division) String() string

func (*Division) Visit added in v0.204.0

func (x *Division) Visit(v func(Expression))

type DotLookup added in v0.141.0

type DotLookup struct {
	Container Expression
	Lookup    string
}

func (*DotLookup) Evaluate added in v0.141.0

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

func (*DotLookup) String added in v0.141.0

func (x *DotLookup) String() string

func (*DotLookup) Visit added in v0.204.0

func (x *DotLookup) Visit(v func(Expression))

type Equality added in v0.141.0

type Equality struct {
	Exp1 Expression
	Exp2 Expression
}

func (*Equality) Evaluate added in v0.141.0

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

func (*Equality) String added in v0.141.0

func (x *Equality) String() string

func (*Equality) Visit added in v0.204.0

func (x *Equality) Visit(v func(Expression))

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 any, 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 Evaluator added in v0.202.0

type Evaluator struct{}

Evaluator evaluates templates and expressions.

func NewEvaluator added in v0.202.0

func NewEvaluator() *Evaluator

NewEvaluator creates a new evaluator

func (*Evaluator) Expression added in v0.202.0

func (e *Evaluator) Expression(env envs.Environment, ctx *types.XObject, expression string) (types.XValue, []string)

Expression 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 (*Evaluator) Template added in v0.202.0

func (e *Evaluator) Template(env envs.Environment, ctx *types.XObject, template string, escaping Escaping) (string, []string, error)

Template evaluates the passed in template

func (*Evaluator) TemplateValue added in v0.202.0

func (e *Evaluator) TemplateValue(env envs.Environment, ctx *types.XObject, template string) (types.XValue, []string, error)

TemplateValue is equivalent to Template 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.

type Exponent added in v0.141.0

type Exponent struct {
	Expression Expression
	Exponent   Expression
}

func (*Exponent) Evaluate added in v0.141.0

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

func (*Exponent) String added in v0.141.0

func (x *Exponent) String() string

func (*Exponent) Visit added in v0.204.0

func (x *Exponent) Visit(v func(Expression))

type Expression added in v0.141.0

type Expression interface {
	Evaluate(envs.Environment, *Scope, *Warnings) types.XValue
	Visit(func(Expression))
	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 {
	Func   Expression
	Params []Expression
}

func (*FunctionCall) Evaluate added in v0.141.0

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

func (*FunctionCall) String added in v0.141.0

func (x *FunctionCall) String() string

func (*FunctionCall) Visit added in v0.204.0

func (x *FunctionCall) Visit(v func(Expression))

type GreaterThan added in v0.141.0

type GreaterThan struct {
	Exp1 Expression
	Exp2 Expression
}

func (*GreaterThan) Evaluate added in v0.141.0

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

func (*GreaterThan) String added in v0.141.0

func (x *GreaterThan) String() string

func (*GreaterThan) Visit added in v0.204.0

func (x *GreaterThan) Visit(v func(Expression))

type GreaterThanOrEqual added in v0.141.0

type GreaterThanOrEqual struct {
	Exp1 Expression
	Exp2 Expression
}

func (*GreaterThanOrEqual) Evaluate added in v0.141.0

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

func (*GreaterThanOrEqual) String added in v0.141.0

func (x *GreaterThanOrEqual) String() string

func (*GreaterThanOrEqual) Visit added in v0.204.0

func (x *GreaterThanOrEqual) Visit(v func(Expression))

type InEquality added in v0.141.0

type InEquality struct {
	Exp1 Expression
	Exp2 Expression
}

func (*InEquality) Evaluate added in v0.141.0

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

func (*InEquality) String added in v0.141.0

func (x *InEquality) String() string

func (*InEquality) Visit added in v0.204.0

func (x *InEquality) Visit(v func(Expression))

type LessThan added in v0.141.0

type LessThan struct {
	Exp1 Expression
	Exp2 Expression
}

func (*LessThan) Evaluate added in v0.141.0

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

func (*LessThan) String added in v0.141.0

func (x *LessThan) String() string

func (*LessThan) Visit added in v0.204.0

func (x *LessThan) Visit(v func(Expression))

type LessThanOrEqual added in v0.141.0

type LessThanOrEqual struct {
	Exp1 Expression
	Exp2 Expression
}

func (*LessThanOrEqual) Evaluate added in v0.141.0

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

func (*LessThanOrEqual) String added in v0.141.0

func (x *LessThanOrEqual) String() string

func (*LessThanOrEqual) Visit added in v0.204.0

func (x *LessThanOrEqual) Visit(v func(Expression))

type Multiplication added in v0.141.0

type Multiplication struct {
	Exp1 Expression
	Exp2 Expression
}

func (*Multiplication) Evaluate added in v0.141.0

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

func (*Multiplication) String added in v0.141.0

func (x *Multiplication) String() string

func (*Multiplication) Visit added in v0.204.0

func (x *Multiplication) Visit(v func(Expression))

type Negation added in v0.141.0

type Negation struct {
	Exp Expression
}

func (*Negation) Evaluate added in v0.141.0

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

func (*Negation) String added in v0.141.0

func (x *Negation) String() string

func (*Negation) Visit added in v0.204.0

func (x *Negation) Visit(v func(Expression))

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, warnings *Warnings) types.XValue

func (*NullLiteral) String added in v0.141.0

func (x *NullLiteral) String() string

func (*NullLiteral) Visit added in v0.204.0

func (x *NullLiteral) Visit(v func(Expression))

type NumberLiteral added in v0.141.0

type NumberLiteral struct {
	Value *types.XNumber
}

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, warnings *Warnings) types.XValue

func (*NumberLiteral) String added in v0.141.0

func (x *NumberLiteral) String() string

func (*NumberLiteral) Visit added in v0.204.0

func (x *NumberLiteral) Visit(v func(Expression))

type Parentheses added in v0.141.0

type Parentheses struct {
	Exp Expression
}

func (*Parentheses) Evaluate added in v0.141.0

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

func (*Parentheses) String added in v0.141.0

func (x *Parentheses) String() string

func (*Parentheses) Visit added in v0.204.0

func (x *Parentheses) Visit(v func(Expression))

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 {
	Exp1 Expression
	Exp2 Expression
}

func (*Subtraction) Evaluate added in v0.141.0

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

func (*Subtraction) String added in v0.141.0

func (x *Subtraction) String() string

func (*Subtraction) Visit added in v0.204.0

func (x *Subtraction) Visit(v func(Expression))

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 {
	Value *types.XText
}

func (*TextLiteral) Evaluate added in v0.141.0

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

func (*TextLiteral) String added in v0.141.0

func (x *TextLiteral) String() string

func (*TextLiteral) Visit added in v0.204.0

func (x *TextLiteral) Visit(v func(Expression))

type Warnings added in v0.202.0

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

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