expr

package
v0.16.0 Latest Latest
Warning

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

Go to latest
Published: Dec 25, 2023 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	TrueLiteral  = types.NewBoolValue(true)
	FalseLiteral = types.NewBoolValue(false)
	NullLiteral  = types.NewNullValue()
)

Functions

func Between

func Between(a Expr) func(x, b Expr) Expr

Between returns a function that creates a BETWEEN operator that returns true if x is between a and b.

func Equal

func Equal(a, b Expr) bool

Equal reports whether a and b are equal by first calling IsEqual if they have an IsEqual method with this signature:

IsEqual(Expr) bool

If not, it returns whether a and b values are equal.

func IsArithmeticOperator

func IsArithmeticOperator(op Operator) bool

IsArithmeticOperator returns true if e is one of +, -, *, /, %, &, |, or ^ operators.

func IsComparisonOperator

func IsComparisonOperator(op Operator) bool

IsComparisonOperator returns true if e is one of =, !=, >, >=, <, <=, IS, IS NOT, IN, or NOT IN operators.

func Walk

func Walk(e Expr, fn func(Expr) bool) bool

Types

type Aggregator

type Aggregator interface {
	Expr

	Aggregate(env *environment.Environment) error
}

An Aggregator is an expression that aggregates objects into one result.

type AggregatorBuilder

type AggregatorBuilder interface {
	Expr

	Aggregator() Aggregator
}

An AggregatorBuilder is a type that can create aggregators.

type AndOp

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

AndOp is the And operator.

func (*AndOp) Eval

func (op *AndOp) Eval(env *environment.Environment) (types.Value, error)

Eval implements the Expr interface. It evaluates a and b and returns true if both evaluate to true.

func (AndOp) IsEqual

func (op AndOp) IsEqual(other Expr) bool

Equal compares this expression with the other expression and returns true if they are equal.

func (AndOp) LeftHand

func (op AndOp) LeftHand() Expr

func (AndOp) Precedence

func (op AndOp) Precedence() int

func (AndOp) RightHand

func (op AndOp) RightHand() Expr

func (AndOp) SetLeftHandExpr

func (op AndOp) SetLeftHandExpr(a Expr)

func (AndOp) SetRightHandExpr

func (op AndOp) SetRightHandExpr(b Expr)

func (AndOp) String

func (op AndOp) String() string

func (AndOp) Token

func (op AndOp) Token() scanner.Token

type BetweenOperator

type BetweenOperator struct {
	X Expr
	// contains filtered or unexported fields
}

func (*BetweenOperator) Eval

func (BetweenOperator) IsEqual

func (op BetweenOperator) IsEqual(other Expr) bool

Equal compares this expression with the other expression and returns true if they are equal.

func (BetweenOperator) LeftHand

func (op BetweenOperator) LeftHand() Expr

func (BetweenOperator) Precedence

func (op BetweenOperator) Precedence() int

func (BetweenOperator) RightHand

func (op BetweenOperator) RightHand() Expr

func (BetweenOperator) SetLeftHandExpr

func (op BetweenOperator) SetLeftHandExpr(a Expr)

func (BetweenOperator) SetRightHandExpr

func (op BetweenOperator) SetRightHandExpr(b Expr)

func (*BetweenOperator) String

func (op *BetweenOperator) String() string

func (BetweenOperator) Token

func (op BetweenOperator) Token() scanner.Token

type Cast

type Cast struct {
	Expr   Expr
	CastAs types.ValueType
}

Cast represents the CAST expression.

func (Cast) Eval

func (c Cast) Eval(env *environment.Environment) (types.Value, error)

Eval returns the primary key of the current object.

func (Cast) IsEqual

func (c Cast) IsEqual(other Expr) bool

IsEqual compares this expression with the other expression and returns true if they are equal.

func (Cast) Params

func (c Cast) Params() []Expr

func (Cast) String

func (c Cast) String() string

type ConcatOperator

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

func (*ConcatOperator) Eval

func (ConcatOperator) IsEqual

func (op ConcatOperator) IsEqual(other Expr) bool

Equal compares this expression with the other expression and returns true if they are equal.

func (ConcatOperator) LeftHand

func (op ConcatOperator) LeftHand() Expr

func (ConcatOperator) Precedence

func (op ConcatOperator) Precedence() int

func (ConcatOperator) RightHand

func (op ConcatOperator) RightHand() Expr

func (ConcatOperator) SetLeftHandExpr

func (op ConcatOperator) SetLeftHandExpr(a Expr)

func (ConcatOperator) SetRightHandExpr

func (op ConcatOperator) SetRightHandExpr(b Expr)

func (ConcatOperator) String

func (op ConcatOperator) String() string

func (ConcatOperator) Token

func (op ConcatOperator) Token() scanner.Token

type ConstraintExpr

type ConstraintExpr struct {
	Expr Expr
}

func Constraint

func Constraint(e Expr) *ConstraintExpr

func (*ConstraintExpr) Eval

func (*ConstraintExpr) String

func (t *ConstraintExpr) String() string

type Expr

type Expr interface {
	Eval(*environment.Environment) (types.Value, error)
	String() string
}

An Expr evaluates to a value.

func Add

func Add(a, b Expr) Expr

Add creates an expression thats evaluates to the result of a + b.

func And

func And(a, b Expr) Expr

And creates an expression that evaluates a And b And returns true if both are truthy.

func BitwiseAnd

func BitwiseAnd(a, b Expr) Expr

BitwiseAnd creates an expression thats evaluates to the result of a & b.

func BitwiseOr

func BitwiseOr(a, b Expr) Expr

BitwiseOr creates an expression thats evaluates to the result of a | b.

func BitwiseXor

func BitwiseXor(a, b Expr) Expr

BitwiseXor creates an expression thats evaluates to the result of a ^ b.

func Concat

func Concat(a, b Expr) Expr

Concat creates an expression that concatenates two text values together. It returns null if one of the values is not a text.

func Div

func Div(a, b Expr) Expr

Div creates an expression thats evaluates to the result of a / b.

func Eq

func Eq(a, b Expr) Expr

Eq creates an expression that returns true if a equals b.

func Gt

func Gt(a, b Expr) Expr

Gt creates an expression that returns true if a is greater than b.

func Gte

func Gte(a, b Expr) Expr

Gte creates an expression that returns true if a is greater than or equal to b.

func In

func In(a, b Expr) Expr

In creates an expression that evaluates to the result of a IN b.

func Is

func Is(a, b Expr) Expr

Is creates an expression that evaluates to the result of a IS b.

func IsNot

func IsNot(a, b Expr) Expr

IsNot creates an expression that evaluates to the result of a IS NOT b.

func Like

func Like(a, b Expr) Expr

Like creates an expression that evaluates to the result of a LIKE b.

func Lt

func Lt(a, b Expr) Expr

Lt creates an expression that returns true if a is lesser than b.

func Lte

func Lte(a, b Expr) Expr

Lte creates an expression that returns true if a is lesser than or equal to b.

func Mod

func Mod(a, b Expr) Expr

Mod creates an expression thats evaluates to the result of a % b.

func Mul

func Mul(a, b Expr) Expr

Mul creates an expression thats evaluates to the result of a * b.

func Neq

func Neq(a, b Expr) Expr

Neq creates an expression that returns true if a equals b.

func Not

func Not(e Expr) Expr

Not creates an expression that returns true if e is falsy.

func NotIn

func NotIn(a, b Expr) Expr

NotIn creates an expression that evaluates to the result of a NOT IN b.

func NotLike

func NotLike(a, b Expr) Expr

NotLike creates an expression that evaluates to the result of a NOT LIKE b.

func Or

func Or(a, b Expr) Expr

Or creates an expression that first evaluates a, returns true if truthy, then evaluates b, returns true if truthy Or false if falsy.

func Sub

func Sub(a, b Expr) Expr

Sub creates an expression thats evaluates to the result of a - b.

type Function

type Function interface {
	Expr

	// Params returns the list of parameters this function has received.
	Params() []Expr
}

A Function is an expression whose evaluation calls a function previously defined.

type InOperator

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

func (*InOperator) Eval

func (op *InOperator) Eval(env *environment.Environment) (types.Value, error)

func (InOperator) IsEqual

func (op InOperator) IsEqual(other Expr) bool

Equal compares this expression with the other expression and returns true if they are equal.

func (InOperator) LeftHand

func (op InOperator) LeftHand() Expr

func (InOperator) Precedence

func (op InOperator) Precedence() int

func (InOperator) RightHand

func (op InOperator) RightHand() Expr

func (InOperator) SetLeftHandExpr

func (op InOperator) SetLeftHandExpr(a Expr)

func (InOperator) SetRightHandExpr

func (op InOperator) SetRightHandExpr(b Expr)

func (InOperator) String

func (op InOperator) String() string

func (InOperator) Token

func (op InOperator) Token() scanner.Token

type IsNotOperator

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

func (*IsNotOperator) Eval

func (IsNotOperator) IsEqual

func (op IsNotOperator) IsEqual(other Expr) bool

Equal compares this expression with the other expression and returns true if they are equal.

func (IsNotOperator) LeftHand

func (op IsNotOperator) LeftHand() Expr

func (IsNotOperator) Precedence

func (op IsNotOperator) Precedence() int

func (IsNotOperator) RightHand

func (op IsNotOperator) RightHand() Expr

func (IsNotOperator) SetLeftHandExpr

func (op IsNotOperator) SetLeftHandExpr(a Expr)

func (IsNotOperator) SetRightHandExpr

func (op IsNotOperator) SetRightHandExpr(b Expr)

func (*IsNotOperator) String

func (op *IsNotOperator) String() string

func (IsNotOperator) Token

func (op IsNotOperator) Token() scanner.Token

type IsOperator

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

func (*IsOperator) Eval

func (op *IsOperator) Eval(env *environment.Environment) (types.Value, error)

func (IsOperator) IsEqual

func (op IsOperator) IsEqual(other Expr) bool

Equal compares this expression with the other expression and returns true if they are equal.

func (IsOperator) LeftHand

func (op IsOperator) LeftHand() Expr

func (IsOperator) Precedence

func (op IsOperator) Precedence() int

func (IsOperator) RightHand

func (op IsOperator) RightHand() Expr

func (IsOperator) SetLeftHandExpr

func (op IsOperator) SetLeftHandExpr(a Expr)

func (IsOperator) SetRightHandExpr

func (op IsOperator) SetRightHandExpr(b Expr)

func (IsOperator) String

func (op IsOperator) String() string

func (IsOperator) Token

func (op IsOperator) Token() scanner.Token

type KVPair

type KVPair struct {
	K string
	V Expr
}

KVPair associates an identifier with an expression.

func (KVPair) String

func (p KVPair) String() string

String implements the fmt.Stringer interface.

type KVPairs

type KVPairs struct {
	Pairs          []KVPair
	SelfReferenced bool
}

KVPairs is a list of KVPair.

func (*KVPairs) Eval

func (kvp *KVPairs) Eval(env *environment.Environment) (types.Value, error)

Eval turns a list of KVPairs into an object.

func (*KVPairs) IsEqual

func (kvp *KVPairs) IsEqual(other Expr) bool

IsEqual compares this expression with the other expression and returns true if they are equal.

func (*KVPairs) String

func (kvp *KVPairs) String() string

String implements the fmt.Stringer interface.

type LikeOperator

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

func (*LikeOperator) Eval

func (LikeOperator) IsEqual

func (op LikeOperator) IsEqual(other Expr) bool

Equal compares this expression with the other expression and returns true if they are equal.

func (LikeOperator) LeftHand

func (op LikeOperator) LeftHand() Expr

func (LikeOperator) Precedence

func (op LikeOperator) Precedence() int

func (LikeOperator) RightHand

func (op LikeOperator) RightHand() Expr

func (LikeOperator) SetLeftHandExpr

func (op LikeOperator) SetLeftHandExpr(a Expr)

func (LikeOperator) SetRightHandExpr

func (op LikeOperator) SetRightHandExpr(b Expr)

func (LikeOperator) String

func (op LikeOperator) String() string

func (LikeOperator) Token

func (op LikeOperator) Token() scanner.Token

type LiteralExprList

type LiteralExprList []Expr

LiteralExprList is a list of expressions.

func (LiteralExprList) Eval

Eval evaluates all the expressions and returns a literalValueList. It implements the Expr interface.

func (LiteralExprList) IsEqual

func (l LiteralExprList) IsEqual(other Expr) bool

IsEqual compares this expression with the other expression and returns true if they are equal.

func (LiteralExprList) String

func (l LiteralExprList) String() string

String implements the fmt.Stringer interface.

type LiteralValue

type LiteralValue struct {
	Value types.Value
}

A LiteralValue represents a literal value of any type defined by the value package.

func (LiteralValue) Eval

Eval returns l. It implements the Expr interface.

func (LiteralValue) IsEqual

func (v LiteralValue) IsEqual(other Expr) bool

IsEqual compares this expression with the other expression and returns true if they are equal.

func (LiteralValue) String

func (v LiteralValue) String() string

String implements the fmt.Stringer interface.

type NamedExpr

type NamedExpr struct {
	Expr

	ExprName string
}

NamedExpr is an expression with a name.

func (*NamedExpr) Name

func (e *NamedExpr) Name() string

Name returns ExprName.

func (*NamedExpr) String

func (e *NamedExpr) String() string

type NamedParam

type NamedParam string

NamedParam is an expression which represents the name of a parameter.

func (NamedParam) Eval

Eval looks up for the parameters in the env for the one that has the same name as p and returns the value.

func (NamedParam) IsEqual

func (p NamedParam) IsEqual(other Expr) bool

IsEqual compares this expression with the other expression and returns true if they are equal.

func (NamedParam) String

func (p NamedParam) String() string

String implements the fmt.Stringer interface.

type NextValueFor

type NextValueFor struct {
	SeqName string
}

func (NextValueFor) Eval

Eval calls the underlying expression Eval method.

func (NextValueFor) IsEqual

func (n NextValueFor) IsEqual(other Expr) bool

IsEqual compares this expression with the other expression and returns true if they are equal.

func (NextValueFor) String

func (n NextValueFor) String() string

type NotInOperator

type NotInOperator struct {
	InOperator
}

func (*NotInOperator) Eval

func (NotInOperator) IsEqual

func (op NotInOperator) IsEqual(other Expr) bool

Equal compares this expression with the other expression and returns true if they are equal.

func (NotInOperator) LeftHand

func (op NotInOperator) LeftHand() Expr

func (NotInOperator) Precedence

func (op NotInOperator) Precedence() int

func (NotInOperator) RightHand

func (op NotInOperator) RightHand() Expr

func (NotInOperator) SetLeftHandExpr

func (op NotInOperator) SetLeftHandExpr(a Expr)

func (NotInOperator) SetRightHandExpr

func (op NotInOperator) SetRightHandExpr(b Expr)

func (*NotInOperator) String

func (op *NotInOperator) String() string

func (NotInOperator) Token

func (op NotInOperator) Token() scanner.Token

type NotLikeOperator

type NotLikeOperator struct {
	*LikeOperator
}

func (*NotLikeOperator) Eval

func (NotLikeOperator) IsEqual

func (op NotLikeOperator) IsEqual(other Expr) bool

Equal compares this expression with the other expression and returns true if they are equal.

func (NotLikeOperator) LeftHand

func (op NotLikeOperator) LeftHand() Expr

func (NotLikeOperator) Precedence

func (op NotLikeOperator) Precedence() int

func (NotLikeOperator) RightHand

func (op NotLikeOperator) RightHand() Expr

func (NotLikeOperator) SetLeftHandExpr

func (op NotLikeOperator) SetLeftHandExpr(a Expr)

func (NotLikeOperator) SetRightHandExpr

func (op NotLikeOperator) SetRightHandExpr(b Expr)

func (*NotLikeOperator) String

func (op *NotLikeOperator) String() string

func (NotLikeOperator) Token

func (op NotLikeOperator) Token() scanner.Token

type NotOp

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

NotOp is the NOT unary operator.

func (*NotOp) Eval

func (op *NotOp) Eval(env *environment.Environment) (types.Value, error)

Eval implements the Expr interface. It evaluates e and returns true if b is falsy

func (NotOp) IsEqual

func (op NotOp) IsEqual(other Expr) bool

Equal compares this expression with the other expression and returns true if they are equal.

func (NotOp) LeftHand

func (op NotOp) LeftHand() Expr

func (NotOp) Precedence

func (op NotOp) Precedence() int

func (NotOp) RightHand

func (op NotOp) RightHand() Expr

func (NotOp) SetLeftHandExpr

func (op NotOp) SetLeftHandExpr(a Expr)

func (NotOp) SetRightHandExpr

func (op NotOp) SetRightHandExpr(b Expr)

func (*NotOp) String

func (op *NotOp) String() string

String implements the fmt.Stringer interface.

func (NotOp) Token

func (op NotOp) Token() scanner.Token

type Operator

type Operator interface {
	Expr

	Precedence() int
	LeftHand() Expr
	RightHand() Expr
	SetLeftHandExpr(Expr)
	SetRightHandExpr(Expr)
	Token() scanner.Token
}

An Operator is a binary expression that takes two operands and executes an operation on them.

type OrOp

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

OrOp is the Or operator.

func (*OrOp) Eval

func (op *OrOp) Eval(env *environment.Environment) (types.Value, error)

Eval implements the Expr interface. It evaluates a and b and returns true if a or b evalutate to true.

func (OrOp) IsEqual

func (op OrOp) IsEqual(other Expr) bool

Equal compares this expression with the other expression and returns true if they are equal.

func (OrOp) LeftHand

func (op OrOp) LeftHand() Expr

func (OrOp) Precedence

func (op OrOp) Precedence() int

func (OrOp) RightHand

func (op OrOp) RightHand() Expr

func (OrOp) SetLeftHandExpr

func (op OrOp) SetLeftHandExpr(a Expr)

func (OrOp) SetRightHandExpr

func (op OrOp) SetRightHandExpr(b Expr)

func (OrOp) String

func (op OrOp) String() string

func (OrOp) Token

func (op OrOp) Token() scanner.Token

type Parentheses

type Parentheses struct {
	E Expr
}

Parentheses is a special expression which turns any sub-expression as unary. It hides the underlying operator, if any, from the parser so that it doesn't get reordered by precedence.

func (Parentheses) Eval

Eval calls the underlying expression Eval method.

func (Parentheses) IsEqual

func (p Parentheses) IsEqual(other Expr) bool

IsEqual compares this expression with the other expression and returns true if they are equal.

func (Parentheses) String

func (p Parentheses) String() string

type Path

type Path object.Path

A Path is an expression that extracts a value from a object at a given path.

func (Path) Eval

func (p Path) Eval(env *environment.Environment) (types.Value, error)

Eval extracts the current value from the environment and returns the value stored at p. It implements the Expr interface.

func (Path) IsEqual

func (p Path) IsEqual(other Expr) bool

IsEqual compares this expression with the other expression and returns true if they are equal.

func (Path) String

func (p Path) String() string

type PositionalParam

type PositionalParam int

PositionalParam is an expression which represents the position of a parameter.

func (PositionalParam) Eval

Eval looks up for the parameters in the env for the one that is has the same position as p and returns the value.

func (PositionalParam) IsEqual

func (p PositionalParam) IsEqual(other Expr) bool

IsEqual compares this expression with the other expression and returns true if they are equal.

func (PositionalParam) String

func (p PositionalParam) String() string

String implements the fmt.Stringer interface.

type Wildcard

type Wildcard struct{}

A Wildcard is an expression that iterates over all the fields of a object.

func (Wildcard) Eval

func (w Wildcard) Eval(env *environment.Environment) (types.Value, error)

func (Wildcard) Iterate

func (w Wildcard) Iterate(env environment.Environment, fn func(field string, value types.Value) error) error

Iterate call the object iterate method.

func (Wildcard) String

func (w Wildcard) String() string

Directories

Path Synopsis
Package glob implements wildcard pattern matching algorithms for strings.
Package glob implements wildcard pattern matching algorithms for strings.

Jump to

Keyboard shortcuts

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