interpreter

package
v0.0.2-beta Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2022 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrSyntaxError when a syntax error is detected
	ErrSyntaxError = errors.New("syntax error")
	// ErrUnsupportedFeature when an expression or attribute type in not yet supported by the interpreter
	ErrUnsupportedFeature = errors.New("unsupported expression or attribute type")
)

Functions

This section is empty.

Types

type ExpressionType

type ExpressionType string

ExpressionType type of the evaluated expression

const (
	// ExpressionTypeKey expression used to evalute primary key values
	ExpressionTypeKey ExpressionType = "key"
	// ExpressionTypeFilter expression used to filter items
	ExpressionTypeFilter ExpressionType = "filter"
	// ExpressionTypeConditional expression used for conditional writes
	ExpressionTypeConditional ExpressionType = "conditional"
)

type Interpreter

type Interpreter interface {
	Match(input MatchInput) (bool, error)
	Update(input UpdateInput) error
}

Interpreter types expression interpreter interface

type Language

type Language struct {
	Debug bool
}

Language interpreter

func (*Language) Match

func (li *Language) Match(input MatchInput) (bool, error)

Match evalute the item with given expression and attributes

func (*Language) Update

func (li *Language) Update(input UpdateInput) error

Update change the item with given expression and attributes

type MatchInput

type MatchInput struct {
	TableName      string
	Expression     string
	ExpressionType ExpressionType
	Item           map[string]*types.Item
	Attributes     map[string]*types.Item
	Aliases        map[string]string
}

MatchInput parameters to use match function

type MatcherFunc

type MatcherFunc func(map[string]*types.Item, map[string]*types.Item) bool

MatcherFunc function used to filter data

type Native

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

Native simple interpreter using pure go functions

func NewNativeInterpreter

func NewNativeInterpreter() *Native

NewNativeInterpreter returns a new native interpreter

func (*Native) AddMatcher

func (ni *Native) AddMatcher(tablename string, t ExpressionType, expr string, matcher MatcherFunc)

AddMatcher add expression matcher to use on key or filter queries

func (*Native) AddUpdater

func (ni *Native) AddUpdater(tablename string, expr string, updater UpdaterFunc)

AddUpdater add expression updater to use on key or filter queries

func (*Native) Match

func (ni *Native) Match(input MatchInput) (bool, error)

Match evalute the item with given expression and attributes

func (*Native) Update

func (ni *Native) Update(input UpdateInput) error

Update change the item with given expression and attributes

type UpdateInput

type UpdateInput struct {
	TableName  string
	Expression string
	Item       map[string]*types.Item
	Attributes map[string]*types.Item
	Aliases    map[string]string
}

UpdateInput parameters to use Update function

type UpdaterFunc

type UpdaterFunc func(map[string]*types.Item, map[string]*types.Item)

UpdaterFunc function used emule to UpdateItem expressions

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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