expression

package
Version: v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jul 10, 2017 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package expression 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

View Source
const AND = 57358
View Source
const ASSIGN = 57350
View Source
const CONTAINS = 57360
View Source
const EQ = 57352
View Source
const FOR = 57356
View Source
const GE = 57354
View Source
const IDENTIFIER = 57347
View Source
const IN = 57357
View Source
const KEYWORD = 57348
View Source
const LE = 57355
View Source
const LITERAL = 57346
View Source
const LOOP = 57351
View Source
const NEQ = 57353
View Source
const OR = 57359
View Source
const PROPERTY = 57349

Variables

This section is empty.

Functions

func EvaluateString

func EvaluateString(source string, ctx Context) (interface{}, error)

EvaluateString is a wrapper for Parse and Evaluate.

func ToLiquid

func ToLiquid(value interface{}) interface{}

ToLiquid converts an object to Liquid, if it implements the Drop interface.

Types

type Closure

type Closure interface {
	// Bind creates a new closure with a new binding.
	Bind(name string, value interface{}) Closure
	Evaluate() (interface{}, 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.

func NewConfig

func NewConfig() Config

NewConfig creates a new Settings.

func (*Config) AddFilter

func (c *Config) AddFilter(name string, fn interface{})

AddFilter adds a filter to the filter dictionary.

type Context

type Context interface {
	ApplyFilter(string, valueFn, []valueFn) interface{}
	// Clone returns a copy with a new variable binding map
	// (so that copy.Set does effect the source context.)
	Clone() Context
	Get(string) interface{}
	Set(string, interface{})
}

Context is the expression evaluation context. It maps variables names to values.

func NewContext

func NewContext(vars map[string]interface{}, cfg Config) Context

NewContext makes a new expression evaluation context.

type Expression

type Expression interface {
	// Evaluate evaluates an expression in a context.
	Evaluate(ctx Context) (interface{}, error)
}

An Expression is a compiled expression.

func Constant

func Constant(k interface{}) 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 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     interface{}
	// contains filtered or unexported fields
}

Loop describes the result of parsing and then evaluating a loop statement.

type ParseError

type ParseError string

ParseError represents a parse error.

func (ParseError) Error

func (e ParseError) 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

Jump to

Keyboard shortcuts

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