expr

package
v1.1.4 Latest Latest
Warning

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

Go to latest
Published: Jul 20, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	PrecOR int
	PrecAND
	PrecNOT
	PrecComparison
	PrecArithmetic
)

Variables

View Source
var (
	ErrValuePlaceholderNotFound    = errors.New("value placeholder not found")
	ErrUnsupportedNodeType         = errors.New("unsupported node type")
	ErrSizeExpectsOneArg           = errors.New("size() expects 1 argument")
	ErrAttributeExistsExpectsPath  = errors.New("attribute_exists() expects a path")
	ErrAttributeExistsExpectsOne   = errors.New("attribute_exists() expects 1 argument")
	ErrAttributeNExistsExpectsPath = errors.New("attribute_not_exists() expects a path")
	ErrAttributeNExistsExpectsOne  = errors.New("attribute_not_exists() expects 1 argument")
	ErrBeginsWithExpectsTwo        = errors.New("begins_with() expects 2 arguments")
	ErrContainsExpectsTwo          = errors.New("contains() expects 2 arguments")
	ErrAttributeTypeExpectsTwo     = errors.New("attribute_type() expects 2 arguments")
	ErrListAppendExpectsTwo        = errors.New("list_append() expects 2 arguments")
	ErrUnknownFunction             = errors.New("unknown function")
	ErrUpdatePathMustBePathExpr    = errors.New("update item path must be a PathExpr")
	ErrExpectedMapForKey           = errors.New("expected map for key")
	ErrExpectedListAtIndex         = errors.New("expected list at index")
	ErrExpectedListForIndex        = errors.New("expected list for index")
	ErrIndexOutOfRange             = errors.New("index out of range")
	ErrExpectedMapForM             = errors.New("expected map for M")
	ErrExpectedListForL            = errors.New("expected list for L")
	ErrUnsupportedArithmeticOp     = errors.New("unsupported arithmetic operator")
	ErrIfNotExistsExpectsTwo       = errors.New("if_not_exists() expects 2 arguments")
	ErrDeleteValueMustBeSet        = errors.New("DELETE value must be a set")
	ErrSSValueMustBeSlice          = errors.New("SS value must be []string")
	ErrCurrentValueMustBeMap       = errors.New("current value must be a map")
	ErrCurrentSSValueMustBeSlice   = errors.New("current SS value must be []string")
	ErrNSValueMustBeSlice          = errors.New("NS value must be []string")
	ErrCurrentNSValueMustBeSlice   = errors.New("current NS value must be []string")
	ErrBSValueMustBeSlice          = errors.New("BS value must be [][]byte")
	ErrCurrentBSValueMustBeSlice   = errors.New("current BS value must be [][]byte")
	ErrSetTypeMismatch             = errors.New(
		"ADD: existing set type does not match the type being added",
	)
	ErrSetSizeOverflow = errors.New("set size overflow")
	ErrInvalidSizeArg  = errors.New(
		"size() only supports String, Binary, Map, List, and Set types",
	)
	ErrUnsupportedAddType = errors.New(
		"ADD action is only supported for Number and Set types",
	)
)

Sentinel errors for evaluator.

View Source
var (
	ErrExpectedRParen        = errors.New("expected ) after function args")
	ErrExpectedLParen        = errors.New("expected ( after function name")
	ErrExpectedIdentifierDot = errors.New("expected identifier after dot")
	ErrExpectedRBracket      = errors.New("expected ]")
	ErrExpectedANDInBetween  = errors.New("expected AND in BETWEEN")
	ErrExpectedLParenAfterIN = errors.New("expected ( after IN")
	ErrExpectedRParenAfterIN = errors.New("expected ) after IN candidates")
	ErrExpectedEqualInSET    = errors.New("expected = in SET")
	ErrUnexpectedToken       = errors.New("unexpected token")
	ErrUnexpectedOperand     = errors.New("unexpected operand token")
	ErrExpectedIndex         = errors.New("expected index")
	ErrExpectedRParen2       = errors.New("expected )")
)

Sentinel errors for parser.

Functions

This section is empty.

Types

type BetweenExpr

type BetweenExpr struct {
	Value Node
	Lower Node
	Upper Node
}

type ComparisonExpr

type ComparisonExpr struct {
	Left     Node
	Right    Node
	Operator TokenType
}

ComparisonExpr represents a comparison expression (=, <>, <, >, <=, >=).

type Evaluator

type Evaluator struct {
	Item       map[string]any
	AttrNames  map[string]string
	AttrValues map[string]any

	// UpdatedPaths tracks the top-level attribute names touched by ApplyUpdate.
	UpdatedPaths map[string]struct{}
}

func (*Evaluator) ApplyProjection

func (e *Evaluator) ApplyProjection(p *ProjectionExpr) map[string]any

func (*Evaluator) ApplyUpdate

func (e *Evaluator) ApplyUpdate(u *UpdateExpr) error

func (*Evaluator) Evaluate

func (e *Evaluator) Evaluate(node Node) (any, error)

type FunctionExpr

type FunctionExpr struct {
	Name string
	Args []Node
}

FunctionExpr represents a function call expression (e.g., size, attribute_exists).

type InExpr

type InExpr struct {
	Value      Node
	Candidates []Node
}

type Lexer

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

func NewLexer

func NewLexer(input string) *Lexer

func (*Lexer) NextToken

func (l *Lexer) NextToken() Token

type LogicalExpr

type LogicalExpr struct {
	Left     Node
	Right    Node
	Operator TokenType
}

LogicalExpr represents a logical expression (AND, OR) combining two nodes.

type Node

type Node interface {
	// contains filtered or unexported methods
}

type NotExpr

type NotExpr struct {
	Expression Node
}

type Parser

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

func NewParser

func NewParser(l *Lexer) *Parser

func (*Parser) ParseCondition

func (p *Parser) ParseCondition() (Node, error)

ParseCondition parses a ConditionExpression.

func (*Parser) ParseProjection

func (p *Parser) ParseProjection() (*ProjectionExpr, error)

ParseProjection parses a ProjectionExpression.

func (*Parser) ParseUpdate

func (p *Parser) ParseUpdate() (*UpdateExpr, error)

ParseUpdate parses an UpdateExpression.

type PathElement

type PathElement struct {
	Name  string
	Index int
	Type  PathElementType
}

type PathElementType

type PathElementType int
const (
	ElementKey PathElementType = iota
	ElementIndex
)

type PathExpr

type PathExpr struct {
	Elements []PathElement
}

PathExpr represents a path expression (e.g., a.b[0]).

type ProjectionExpr

type ProjectionExpr struct {
	Paths []Node // PathExpr
}

ProjectionExpr represents a projection expression listing the paths to include.

type Token

type Token struct {
	Literal string
	Type    TokenType
}

func (Token) String

func (t Token) String() string

type TokenType

type TokenType int
const (
	TokenEOF TokenType = iota
	TokenError

	// TokenIdentifier represents identifiers and placeholders.
	TokenIdentifier // #name or pk or info.tags
	TokenValue      // :val

	// TokenEqual represents operators.
	TokenEqual        // =
	TokenNotEqual     // <>
	TokenLess         // <
	TokenGreater      // >
	TokenLessEqual    // <=
	TokenGreaterEqual // >=
	TokenPlus         // +
	TokenMinus        // -
	TokenLParen       // (
	TokenRParen       // )
	TokenComma        // ,
	TokenDot          // .
	TokenLBracket     // [
	TokenRBracket     // ]

	// TokenAND represents keywords.
	TokenAND
	TokenOR
	TokenNOT
	TokenBETWEEN
	TokenIN
	TokenSET
	TokenREMOVE
	TokenADD
	TokenDELETE

	// TokenSize represents function keywords.
	TokenSize
	TokenAttributeExists
	TokenAttributeNotExists
	TokenBeginsWith
	TokenContains
	TokenAttributeType
	TokenIfNotExists
	TokenListAppend
)

type UpdateAction

type UpdateAction struct {
	Items []UpdateItem
	Type  TokenType
}

type UpdateExpr

type UpdateExpr struct {
	Actions []UpdateAction
}

UpdateExpr represents an update expression with one or more actions (SET, REMOVE, ADD, DELETE).

type UpdateItem

type UpdateItem struct {
	Path  Node // PathExpr
	Value Node // Used for SET, ADD, DELETE
}

type ValuePlaceholder

type ValuePlaceholder struct {
	Name string
}

ValuePlaceholder represents a value placeholder (e.g., :val).

Jump to

Keyboard shortcuts

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