Documentation
¶
Index ¶
- Constants
- func AreAllExpressions(e []Expression, fn func(Expression) bool) bool
- func AsIntegerLiteral(expr Expression) (int, bool)
- func AsStringLiteral(expr Expression) (string, bool)
- func AttributeAliasFromExpr(expr Expression) (string, bool)
- func Contains(expr Expression, visitor func(Expression) bool) bool
- func HasArrayTraversal(expr Expression) bool
- func InterfaceFromLiteral(expr interface{}) interface{}
- func IsArithmeticOperator(token Token) bool
- func IsAttribute(e Expression) bool
- func IsFalse(expr Expression) bool
- func IsLiteral(e Expression) bool
- func IsSubscriptExpression(e Expression) bool
- func IsTrue(expr Expression) bool
- func ValidateParentAccess(expr Expression) error
- func Walk(expr Expression, visitor func(Expression) bool) bool
- type Array
- type ArrayTraversal
- type Attribute
- type BinaryOperator
- type BooleanLiteral
- type Constraint
- type DotOperator
- type Element
- type Ellipsis
- type Everything
- type Expression
- type Filter
- type FloatLiteral
- type FunctionCall
- type FunctionDefinition
- type FunctionID
- type FunctionParam
- type FunctionParamDefinition
- type FunctionPipe
- type Group
- type IntegerLiteral
- type Literal
- type NullLiteral
- type Object
- type Param
- type Parent
- type ParseError
- type PipeOperator
- type Position
- type PostfixOperator
- type PrefixOperator
- type Projection
- type Range
- type Slice
- type StringLiteral
- type Subscript
- type This
- type Token
- type TransformFunc
- type Tuple
Constants ¶
const ( KeywordLimit = "limit" KeywordOffset = "offset" KeywordOrder = "order" )
Variables ¶
This section is empty.
Functions ¶
func AreAllExpressions ¶
func AreAllExpressions(e []Expression, fn func(Expression) bool) bool
AreAllExpressions returns true if all expressions satisfy a function.
func AsIntegerLiteral ¶
func AsIntegerLiteral(expr Expression) (int, bool)
func AsStringLiteral ¶
func AsStringLiteral(expr Expression) (string, bool)
func AttributeAliasFromExpr ¶
func AttributeAliasFromExpr(expr Expression) (string, bool)
AttributeAliasFromExpr will return "bar" for "bar" or "foo.bar". Returns false if the expression includes anything else, such as parent references or array subscripting.
func Contains ¶
func Contains(expr Expression, visitor func(Expression) bool) bool
Contains is like Walk(), except its return value is the reverse: If the walk visitor returns true, walking is aborted, and the function returns true.
func HasArrayTraversal ¶
func HasArrayTraversal(expr Expression) bool
func InterfaceFromLiteral ¶
func InterfaceFromLiteral(expr interface{}) interface{}
InterfaceFromLiteral returns a value from a Literal interface. Returns nil if the expression is not a literal.
func IsArithmeticOperator ¶
IsArithmeticOperator checks whether an operator is an arithmetic operator.
func IsAttribute ¶
func IsAttribute(e Expression) bool
func IsFalse ¶
func IsFalse(expr Expression) bool
func IsLiteral ¶
func IsLiteral(e Expression) bool
func IsSubscriptExpression ¶
func IsSubscriptExpression(e Expression) bool
IsSubscriptExpression checks whether an expression is a valid subscript expression. Since subscripts and filters share the same syntax, we limit subscripts to only contain numeric literals and the arithmetic operators.
func IsTrue ¶
func IsTrue(expr Expression) bool
func ValidateParentAccess ¶
func ValidateParentAccess(expr Expression) error
func Walk ¶
func Walk(expr Expression, visitor func(Expression) bool) bool
Walk walks an expression top-down, i.e. the outer struct first. If the visitor returns false, the walking is halted.
Types ¶
type Array ¶
type Array struct { Pos Position Expressions []Expression }
Array is a an array on the form `[a, b, 1, 2, 3]`
func (*Array) Equal ¶
func (e *Array) Equal(b Expression) bool
func (*Array) MarshalJSON ¶
MarshalJSON marshals an AST node to JSON.
func (*Array) Transform ¶
func (e *Array) Transform(f TransformFunc) Expression
type ArrayTraversal ¶
type ArrayTraversal struct { Pos Position // Expr is NOT used by the old engine, where it is combined with a PipeOperator. Expr Expression }
ArrayTraversal marks the expression for array traversal.
func (*ArrayTraversal) Equal ¶
func (e *ArrayTraversal) Equal(b Expression) bool
func (*ArrayTraversal) GetPos ¶
func (e *ArrayTraversal) GetPos() Position
func (*ArrayTraversal) MarshalJSON ¶
func (e *ArrayTraversal) MarshalJSON() ([]byte, error)
MarshalJSON marshals an AST node to JSON.
func (*ArrayTraversal) Transform ¶
func (e *ArrayTraversal) Transform(f TransformFunc) Expression
type Attribute ¶
Attribute represents specification of a field on the form `title` as in `book.title`
func AsAttribute ¶
func AsAttribute(expr Expression) (*Attribute, bool)
func (*Attribute) Equal ¶
func (e *Attribute) Equal(b Expression) bool
func (*Attribute) MarshalJSON ¶
MarshalJSON marshals an AST node to JSON.
func (*Attribute) Transform ¶
func (e *Attribute) Transform(f TransformFunc) Expression
type BinaryOperator ¶
type BinaryOperator struct { Pos Position LHS Expression RHS Expression Operator Token }
BinaryOperator represents two expressions joint with an operator
func (*BinaryOperator) Equal ¶
func (e *BinaryOperator) Equal(b Expression) bool
func (*BinaryOperator) GetPos ¶
func (e *BinaryOperator) GetPos() Position
func (*BinaryOperator) MarshalJSON ¶
func (expr *BinaryOperator) MarshalJSON() ([]byte, error)
MarshalJSON marshals an AST node to JSON.
func (*BinaryOperator) Transform ¶
func (e *BinaryOperator) Transform(f TransformFunc) Expression
type BooleanLiteral ¶
BooleanLiteral is a literal bool
func (*BooleanLiteral) Equal ¶
func (e *BooleanLiteral) Equal(b Expression) bool
func (*BooleanLiteral) GetPos ¶
func (e *BooleanLiteral) GetPos() Position
func (*BooleanLiteral) LiteralValue ¶
func (e *BooleanLiteral) LiteralValue() interface{}
LiteralValue implements Literal.
func (*BooleanLiteral) MarshalJSON ¶
func (expr *BooleanLiteral) MarshalJSON() ([]byte, error)
MarshalJSON marshals an AST node to JSON.
func (*BooleanLiteral) Transform ¶
func (e *BooleanLiteral) Transform(f TransformFunc) Expression
type Constraint ¶
type Constraint struct { Pos Position Expression Expression }
A Constraint operation, on the form `*[is "article" && expiresAt < $now && _createdAt desc]`
func (*Constraint) Equal ¶
func (e *Constraint) Equal(b Expression) bool
func (*Constraint) GetPos ¶
func (e *Constraint) GetPos() Position
func (*Constraint) MarshalJSON ¶
func (e *Constraint) MarshalJSON() ([]byte, error)
MarshalJSON marshals an AST node to JSON.
func (*Constraint) Transform ¶
func (e *Constraint) Transform(f TransformFunc) Expression
type DotOperator ¶
type DotOperator struct { Pos Position LHS Expression RHS Expression }
DotOperator is a convenience class for the common operator '.'
func (*DotOperator) Equal ¶
func (e *DotOperator) Equal(b Expression) bool
func (*DotOperator) GetPos ¶
func (e *DotOperator) GetPos() Position
func (*DotOperator) MarshalJSON ¶
func (e *DotOperator) MarshalJSON() ([]byte, error)
MarshalJSON marshals an AST node to JSON.
func (*DotOperator) Transform ¶
func (e *DotOperator) Transform(f TransformFunc) Expression
type Element ¶
type Element struct { Pos Position LHS Expression Idx *Subscript }
Element returns an indexed element of an array.
func (*Element) Equal ¶
func (e *Element) Equal(b Expression) bool
func (*Element) Transform ¶
func (e *Element) Transform(f TransformFunc) Expression
type Ellipsis ¶
type Ellipsis struct {
Pos Position
}
Ellipsis represents a '...'-statement
func (*Ellipsis) Equal ¶
func (*Ellipsis) Equal(b Expression) bool
func (*Ellipsis) MarshalJSON ¶
MarshalJSON marshals an AST node to JSON.
func (*Ellipsis) Transform ¶
func (e *Ellipsis) Transform(f TransformFunc) Expression
type Everything ¶
type Everything struct {
Pos Position
}
Everything is the `*`, the root of all queries
func (*Everything) Equal ¶
func (*Everything) Equal(b Expression) bool
func (*Everything) GetPos ¶
func (e *Everything) GetPos() Position
func (*Everything) MarshalJSON ¶
func (*Everything) MarshalJSON() ([]byte, error)
MarshalJSON marshals an AST node to JSON.
func (*Everything) Transform ¶
func (e *Everything) Transform(f TransformFunc) Expression
type Expression ¶
type Expression interface { GetPos() Position Transform(TransformFunc) Expression Equal(Expression) bool // contains filtered or unexported methods }
Expression is the common interface for all GROQ expressions
func CombineAnd ¶
func CombineAnd(lhs, rhs Expression) Expression
func CombineOr ¶
func CombineOr(lhs, rhs Expression) Expression
func LiteralFromInterface ¶
func LiteralFromInterface(value interface{}, pos Position) (Expression, error)
LiteralFromInterface takes a value and returns a value wrapped in a Literal interface.
func Transform ¶
func Transform(expr Expression, f TransformFunc) Expression
Transform walks an expression depth-first.
type Filter ¶
type Filter struct { Pos Position LHS Expression Constraint *Constraint }
A Filter filters an array using another expression.
func (*Filter) Equal ¶
func (e *Filter) Equal(b Expression) bool
func (*Filter) Transform ¶
func (e *Filter) Transform(f TransformFunc) Expression
type FloatLiteral ¶
FloatLiteral is literal float
func (*FloatLiteral) Equal ¶
func (e *FloatLiteral) Equal(b Expression) bool
func (*FloatLiteral) GetPos ¶
func (e *FloatLiteral) GetPos() Position
func (*FloatLiteral) LiteralValue ¶
func (e *FloatLiteral) LiteralValue() interface{}
LiteralValue implements Literal.
func (*FloatLiteral) MarshalJSON ¶
func (expr *FloatLiteral) MarshalJSON() ([]byte, error)
MarshalJSON marshals an AST node to JSON.
func (*FloatLiteral) Transform ¶
func (e *FloatLiteral) Transform(f TransformFunc) Expression
type FunctionCall ¶
type FunctionCall struct { Namespace string Pos Position Name string Arguments []Expression }
FunctionCall represents a function invocation on the form function(expression). Namespace represents namespaced function call like string::length()
func (*FunctionCall) Equal ¶
func (e *FunctionCall) Equal(b Expression) bool
func (*FunctionCall) GetPos ¶
func (e *FunctionCall) GetPos() Position
func (*FunctionCall) MarshalJSON ¶
func (expr *FunctionCall) MarshalJSON() ([]byte, error)
MarshalJSON marshals an AST node to JSON.
func (*FunctionCall) Transform ¶
func (e *FunctionCall) Transform(f TransformFunc) Expression
type FunctionDefinition ¶
type FunctionDefinition struct { Pos Position ID FunctionID Body Expression Parameters []*FunctionParamDefinition }
func (*FunctionDefinition) GetID ¶
func (fd *FunctionDefinition) GetID() FunctionID
type FunctionID ¶
func (FunctionID) String ¶
func (id FunctionID) String() string
type FunctionParam ¶
type FunctionParam struct { Definition *FunctionParamDefinition Pos Position }
func (FunctionParam) Equal ¶
func (fp FunctionParam) Equal(e Expression) bool
func (FunctionParam) GetPos ¶
func (fp FunctionParam) GetPos() Position
func (FunctionParam) Transform ¶
func (fp FunctionParam) Transform(f TransformFunc) Expression
type FunctionParamDefinition ¶
type FunctionPipe ¶
type FunctionPipe struct { Pos Position LHS Expression Func *FunctionCall }
A FunctionPipe maps an object or array of objects through a function.
func (*FunctionPipe) Equal ¶
func (e *FunctionPipe) Equal(b Expression) bool
func (*FunctionPipe) GetPos ¶
func (e *FunctionPipe) GetPos() Position
func (*FunctionPipe) Transform ¶
func (e *FunctionPipe) Transform(f TransformFunc) Expression
type Group ¶
type Group struct { Pos Position Expression Expression }
Group is a node inserted around an expression to indicate places where explicit parentheses have special meaning.
It is currently only used to stop array traversal, i.e. to indicate that an expression should not be folded over by subsequent expressions.
For example, while a[][0] means "the first element of each a", (a[])[0] means "the first element of a". Rather than resolving this in the parser, we wrap the left side in a group node.
func (*Group) Equal ¶
func (e *Group) Equal(b Expression) bool
func (*Group) MarshalJSON ¶
MarshalJSON marshals an AST node to JSON.
func (*Group) Transform ¶
func (e *Group) Transform(f TransformFunc) Expression
type IntegerLiteral ¶
IntegerLiteral is literal integer
func (*IntegerLiteral) Equal ¶
func (e *IntegerLiteral) Equal(b Expression) bool
func (*IntegerLiteral) GetPos ¶
func (e *IntegerLiteral) GetPos() Position
func (*IntegerLiteral) LiteralValue ¶
func (e *IntegerLiteral) LiteralValue() interface{}
LiteralValue implements Literal.
func (*IntegerLiteral) MarshalJSON ¶
func (expr *IntegerLiteral) MarshalJSON() ([]byte, error)
MarshalJSON marshals an AST node to JSON.
func (*IntegerLiteral) Transform ¶
func (e *IntegerLiteral) Transform(f TransformFunc) Expression
type Literal ¶
type Literal interface {
LiteralValue() interface{}
}
Literal is the common interface implemented by all literal nodes
type NullLiteral ¶
type NullLiteral struct {
Pos Position
}
NullLiteral is a literal null
func (*NullLiteral) Equal ¶
func (e *NullLiteral) Equal(b Expression) bool
func (*NullLiteral) GetPos ¶
func (e *NullLiteral) GetPos() Position
func (*NullLiteral) LiteralValue ¶
func (e *NullLiteral) LiteralValue() interface{}
LiteralValue implements Literal.
func (*NullLiteral) MarshalJSON ¶
func (expr *NullLiteral) MarshalJSON() ([]byte, error)
MarshalJSON marshals an AST node to JSON.
func (*NullLiteral) Transform ¶
func (e *NullLiteral) Transform(f TransformFunc) Expression
type Object ¶
type Object struct { Pos Position Expressions []Expression }
Object is a `{title, body, somethingsomething}`
func (*Object) Equal ¶
func (e *Object) Equal(b Expression) bool
func (*Object) MarshalJSON ¶
MarshalJSON marshals an AST node to JSON.
func (*Object) Transform ¶
func (e *Object) Transform(f TransformFunc) Expression
type Param ¶
Param represents a placeholder parameter, e.g. $foo.
func (*Param) Equal ¶
func (e *Param) Equal(b Expression) bool
func (*Param) Transform ¶
func (e *Param) Transform(f TransformFunc) Expression
type Parent ¶
type Parent struct {
Pos Position
}
Parent is the `^`, the item being processed in a mapping operation
func (*Parent) Equal ¶
func (*Parent) Equal(b Expression) bool
func (*Parent) MarshalJSON ¶
MarshalJSON marshals an AST node to JSON.
func (*Parent) Transform ¶
func (e *Parent) Transform(f TransformFunc) Expression
type ParseError ¶
type ParseError struct {
// contains filtered or unexported fields
}
ParseError represents an error during parsing
func NewParseError ¶
func NewParseError(msg string, pos Position) *ParseError
func (*ParseError) Error ¶
func (e *ParseError) Error() string
func (*ParseError) Message ¶
func (e *ParseError) Message() string
func (*ParseError) Pos ¶
func (e *ParseError) Pos() Position
type PipeOperator ¶
type PipeOperator struct { Pos Position LHS Expression RHS Expression }
PipeOperator is a convenience class for the very common operator '|'
func (*PipeOperator) Equal ¶
func (e *PipeOperator) Equal(b Expression) bool
func (*PipeOperator) GetPos ¶
func (e *PipeOperator) GetPos() Position
func (*PipeOperator) MarshalJSON ¶
func (expr *PipeOperator) MarshalJSON() ([]byte, error)
MarshalJSON marshals an AST node to JSON.
func (*PipeOperator) Transform ¶
func (e *PipeOperator) Transform(f TransformFunc) Expression
type PostfixOperator ¶
type PostfixOperator struct { Pos Position LHS Expression Operator Token }
PostfixOperator represents an expression followed by an operator `_createdAt desc`
func (*PostfixOperator) Equal ¶
func (e *PostfixOperator) Equal(b Expression) bool
func (*PostfixOperator) GetPos ¶
func (e *PostfixOperator) GetPos() Position
func (*PostfixOperator) MarshalJSON ¶
func (expr *PostfixOperator) MarshalJSON() ([]byte, error)
MarshalJSON marshals an AST node to JSON.
func (*PostfixOperator) Transform ¶
func (e *PostfixOperator) Transform(f TransformFunc) Expression
type PrefixOperator ¶
type PrefixOperator struct { Pos Position RHS Expression Operator Token }
PrefixOperator represents a prefix operator `!completed`
func (*PrefixOperator) Equal ¶
func (e *PrefixOperator) Equal(b Expression) bool
func (*PrefixOperator) GetPos ¶
func (e *PrefixOperator) GetPos() Position
func (*PrefixOperator) MarshalJSON ¶
func (expr *PrefixOperator) MarshalJSON() ([]byte, error)
MarshalJSON marshals an AST node to JSON.
func (*PrefixOperator) Transform ¶
func (e *PrefixOperator) Transform(f TransformFunc) Expression
type Projection ¶
type Projection struct { Pos Position LHS Expression Object *Object }
A Projection maps an object or array of objects to a new object.
func (*Projection) Equal ¶
func (e *Projection) Equal(b Expression) bool
func (*Projection) GetPos ¶
func (e *Projection) GetPos() Position
func (*Projection) Transform ¶
func (e *Projection) Transform(f TransformFunc) Expression
type Range ¶
type Range struct { Pos Position Start Expression End Expression Inclusive bool }
Range is a literal range expression on the form `[1..10]` (inclusive), `[1...10]` (exclusive)
func (*Range) Equal ¶
func (e *Range) Equal(b Expression) bool
func (*Range) MarshalJSON ¶
MarshalJSON marshals an AST node to JSON.
func (*Range) Transform ¶
func (e *Range) Transform(f TransformFunc) Expression
type Slice ¶
type Slice struct { Pos Position LHS Expression Range *Subscript }
Slice retrieves a range of an array.
func (*Slice) Equal ¶
func (e *Slice) Equal(b Expression) bool
func (*Slice) Transform ¶
func (e *Slice) Transform(f TransformFunc) Expression
type StringLiteral ¶
StringLiteral is literal strings
func (*StringLiteral) Equal ¶
func (e *StringLiteral) Equal(b Expression) bool
func (*StringLiteral) GetPos ¶
func (e *StringLiteral) GetPos() Position
func (*StringLiteral) LiteralValue ¶
func (e *StringLiteral) LiteralValue() interface{}
LiteralValue implements Literal.
func (*StringLiteral) MarshalJSON ¶
func (e *StringLiteral) MarshalJSON() ([]byte, error)
MarshalJSON marshals an AST node to JSON.
func (*StringLiteral) Transform ¶
func (e *StringLiteral) Transform(f TransformFunc) Expression
type Subscript ¶
type Subscript struct { Pos Position Value Expression }
Subscript is on the form `[0]`
func (*Subscript) Equal ¶
func (e *Subscript) Equal(b Expression) bool
func (*Subscript) MarshalJSON ¶
MarshalJSON marshals an AST node to JSON.
func (*Subscript) Transform ¶
func (e *Subscript) Transform(f TransformFunc) Expression
type This ¶
type This struct {
Pos Position
}
This `@` is the current root value of the scope
func (*This) Equal ¶
func (*This) Equal(b Expression) bool
func (*This) Transform ¶
func (e *This) Transform(f TransformFunc) Expression
type Token ¶
type Token int
Token represents one token
const ( Illegal Token = iota EOF // End of File Whitespace // A contiguous sequence of white space ParenLeft // ( ParenRight // ) BraceLeft // { BraceRight // } BracketLeft // [ BracketRight // ] Dot // . Equals // == Or // || And // && GT // > LT // < GTE // >= LTE // <= NEQ // != Not // ! Null // null Arrow // -> At // @ Comma // , Colon // : Name // A valid field or type identifier DotDot // .. DotDotDot // ... MatchOperator // match InOperator // in AscOperator // asc DescOperator // desc Integer // 1234 Float // 123.4 Bool // true or false String // 'literal string' or "literal string" Hat // ^ Asterisk // * Exponentiation // ** Slash // / Percent // % Plus // + Minus // - Pipe // | Rocket // => DoubleColon // :: TokenMax // Always last EqualSign // = Semicolon // ; )
The different tokens
func InvertOperator ¶
func MatchingBrace ¶
MatchingBrace returns the brace matching the provided token, as in '(' returns ')' and '[' returns ']'
func (Token) MarshalJSON ¶
MarshalJSON marshals an AST node to JSON.
type TransformFunc ¶
type TransformFunc func(Expression) Expression
type Tuple ¶
type Tuple struct { Pos Position Members []Expression }
Tuple represents parenthesized expression: (foo, bar)
func (*Tuple) Equal ¶
func (e *Tuple) Equal(b Expression) bool
func (*Tuple) Transform ¶
func (e *Tuple) Transform(f TransformFunc) Expression