Documentation
¶
Index ¶
- func HasExpressions(template string, allowedTopLevels []string) bool
- func VisitTemplate(template string, allowedTopLevels []string, unescapeBody bool, ...) error
- type Addition
- type AnonFunction
- type ArrayLookup
- type BooleanLiteral
- type Concatenation
- type ContextReference
- type Division
- type DotLookup
- type Equality
- type ErrorListener
- type ErrorLiteral
- type Escaping
- type Evaluator
- func (e *Evaluator) Expression(env envs.Environment, ctx *types.XObject, expression string) (types.XValue, []string)
- func (e *Evaluator) Template(env envs.Environment, ctx *types.XObject, template string, escaping Escaping) (string, []string, error)
- func (e *Evaluator) TemplateValue(env envs.Environment, ctx *types.XObject, template string) (types.XValue, []string, error)
- type Exponent
- type Expression
- type FunctionCall
- type GreaterThan
- type GreaterThanOrEqual
- type InEquality
- type LessThan
- type LessThanOrEqual
- type Multiplication
- type Negation
- type NullLiteral
- type NumberLiteral
- type Parentheses
- type Scanner
- type Scope
- type Subtraction
- type TemplateError
- type TemplateErrors
- type TextLiteral
- type Warnings
- type XTokenType
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func HasExpressions ¶ added in v0.76.1
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) 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
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) 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) 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) 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 ErrorLiteral ¶ added in v0.268.0
ErrorLiteral is a literal error value
func (*ErrorLiteral) Evaluate ¶ added in v0.268.0
func (x *ErrorLiteral) Evaluate(env envs.Environment, scope *Scope, warnings *Warnings) types.XValue
func (*ErrorLiteral) String ¶ added in v0.268.0
func (x *ErrorLiteral) String() string
func (*ErrorLiteral) Visit ¶ added in v0.268.0
func (x *ErrorLiteral) Visit(v func(Expression))
type Escaping ¶ added in v0.55.0
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) 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
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) 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) 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
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
type Scope ¶ added in v0.141.0
type Scope struct {
// contains filtered or unexported fields
}
Scope provides access to context objects
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
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 {
Errors []*TemplateError
}
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 list 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
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 )