Documentation ¶
Overview ¶
Package expressions is an internal package that parses and evaluates the expression language.
This is the language that is used inside Liquid object and tags; e.g. "a.b[c]" in {{ a.b[c] }}, and "pages = site.pages | reverse" in {% assign pages = site.pages | reverse %}.
Index ¶
Constants ¶
const ( AssignStatementSelector = "%assign " CycleStatementSelector = "{%cycle " LoopStatementSelector = "%loop " WhenStatementSelector = "{%when " )
These strings match lexer tokens.
const AND = 57359
const ASSIGN = 57350
const CONTAINS = 57361
const CYCLE = 57351
const DOTDOT = 57362
const EQ = 57354
const GE = 57356
const IDENTIFIER = 57347
const IN = 57358
const KEYWORD = 57348
const LE = 57357
const LITERAL = 57346
const LOOP = 57352
const NEQ = 57355
const OR = 57360
const PROPERTY = 57349
const WHEN = 57353
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Assignment ¶
type Assignment struct { Variable string ValueFn Expression }
An Assignment is a parse of an {% assign %} statement
type Closure ¶
type Closure interface { // Bind creates a new closure with a new binding. Bind(name string, value any) Closure Evaluate() (any, error) }
A Closure is an expression within a lexical environment. A closure may refer to variables that are not defined in the environment. (Therefore it's not a technically a closure.)
type Config ¶
type Config struct {
// contains filtered or unexported fields
}
Config holds configuration information for expression interpretation.
type Context ¶
type Context interface { ApplyFilter(string, valueFn, []valueFn) (any, error) // Clone returns a copy with a new variable binding map // (so that copy.Set does effect the source context.) Clone() Context Get(string) any Set(string, any) }
Context is the expression evaluation context. It maps variables names to values.
type Expression ¶
type Expression interface { // Evaluate evaluates an expression in a context. Evaluate(ctx Context) (any, error) }
An Expression is a compiled expression.
func Constant ¶
func Constant(k any) Expression
Constant creates an expression that returns a constant value.
func Not ¶
func Not(e Expression) Expression
Not creates an expression that returns ! of the wrapped expression.
func Parse ¶
func Parse(source string) (expr Expression, err error)
Parse parses an expression string into an Expression.
type FilterError ¶ added in v1.2.1
FilterError is the error returned by a filter when it is applied
func (FilterError) Error ¶ added in v1.2.1
func (e FilterError) Error() string
type InterpreterError ¶
type InterpreterError string
An InterpreterError is an error during expression interpretation. It is used for errors in the input expression, to distinguish them from implementation errors in the interpreter.
func (InterpreterError) Error ¶
func (e InterpreterError) Error() string
type Loop ¶
type Loop struct { Variable string Expr Expression // contains filtered or unexported fields }
A Loop is a parse of a {% loop %} statement
type Statement ¶
type Statement struct {
// contains filtered or unexported fields
}
A Statement is the result of parsing a string.
func ParseStatement ¶
ParseStatement parses an statement into an Expression that can evaluated to return a structure specific to the statement.
type SyntaxError ¶ added in v1.1.2
type SyntaxError string
SyntaxError represents a syntax error. The yacc-generated compiler doesn't use error returns; this lets us recognize them.
func (SyntaxError) Error ¶ added in v1.1.2
func (e SyntaxError) Error() string
type UndefinedFilter ¶
type UndefinedFilter string
UndefinedFilter is an error that the named filter is not defined.
func (UndefinedFilter) Error ¶
func (e UndefinedFilter) Error() string