builtins

package
v0.70.0 Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2024 License: Apache-2.0 Imports: 6 Imported by: 34

Documentation

Overview

Package builtins contains utilities for implementing built-in functions.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ArrayOperand added in v0.9.1

func ArrayOperand(x ast.Value, pos int) (*ast.Array, error)

ArrayOperand converts x to an array. If the cast fails, a descriptive error is returned.

func BigIntOperand added in v0.18.0

func BigIntOperand(x ast.Value, pos int) (*big.Int, error)

BigIntOperand converts x to a big int. If the cast fails, a descriptive error is returned.

func FloatToNumber

func FloatToNumber(f *big.Float) ast.Number

FloatToNumber converts f to a number.

func IntOperand

func IntOperand(x ast.Value, pos int) (int, error)

IntOperand converts x to an int. If the cast fails, a descriptive error is returned.

func IntToNumber added in v0.8.0

func IntToNumber(i *big.Int) ast.Number

IntToNumber converts i to a number.

func NewOperandElementErr

func NewOperandElementErr(pos int, composite ast.Value, got ast.Value, expected ...string) error

NewOperandElementErr returns an operand error indicating an element in the composite operand was wrong.

func NewOperandEnumErr

func NewOperandEnumErr(pos int, expected ...string) error

NewOperandEnumErr returns an operand error indicating a value was wrong.

func NewOperandErr

func NewOperandErr(pos int, f string, a ...interface{}) error

NewOperandErr returns a generic operand error.

func NewOperandTypeErr

func NewOperandTypeErr(pos int, got ast.Value, expected ...string) error

NewOperandTypeErr returns an operand error indicating the operand's type was wrong.

func NumberOperand

func NumberOperand(x ast.Value, pos int) (ast.Number, error)

NumberOperand converts x to a number. If the cast fails, a descriptive error is returned.

func NumberToFloat

func NumberToFloat(n ast.Number) *big.Float

NumberToFloat converts n to a big float.

func NumberToInt added in v0.8.0

func NumberToInt(n ast.Number) (*big.Int, error)

NumberToInt converts n to a big int. If n cannot be converted to an big int, an error is returned.

func ObjectOperand added in v0.7.0

func ObjectOperand(x ast.Value, pos int) (ast.Object, error)

ObjectOperand converts x to an object. If the cast fails, a descriptive error is returned.

func RuneSliceOperand added in v0.10.1

func RuneSliceOperand(x ast.Value, pos int) ([]rune, error)

RuneSliceOperand converts x to a []rune. If the cast fails, a descriptive error is returned.

func SetOperand

func SetOperand(x ast.Value, pos int) (ast.Set, error)

SetOperand converts x to a set. If the cast fails, a descriptive error is returned.

func StringOperand

func StringOperand(x ast.Value, pos int) (ast.String, error)

StringOperand converts x to a string. If the cast fails, a descriptive error is returned.

func StringSliceOperand added in v0.10.1

func StringSliceOperand(a ast.Value, pos int) ([]string, error)

StringSliceOperand converts x to a []string. If the cast fails, a descriptive error is returned.

Types

type Cache added in v0.5.0

type Cache map[interface{}]interface{}

Cache defines the built-in cache used by the top-down evaluation. The keys must be comparable and should not be of type string.

func (Cache) Get added in v0.5.0

func (c Cache) Get(k interface{}) (interface{}, bool)

Get returns the cached value for k.

func (Cache) Put added in v0.5.0

func (c Cache) Put(k, v interface{})

Put updates the cache for the named built-in.

type ErrOperand

type ErrOperand string

ErrOperand represents an invalid operand has been passed to a built-in function. Built-ins should return ErrOperand to indicate a type error has occurred.

func (ErrOperand) Error

func (err ErrOperand) Error() string

type NDBCache added in v0.44.0

type NDBCache map[string]ast.Object

We use an ast.Object for the cached keys/values because a naive map[ast.Value]ast.Value will not correctly detect value equality of the member keys.

func (NDBCache) AsValue added in v0.45.0

func (c NDBCache) AsValue() ast.Value

func (NDBCache) Get added in v0.44.0

func (c NDBCache) Get(name string, k ast.Value) (ast.Value, bool)

Get returns the cached value for k for the named builtin.

func (NDBCache) MarshalJSON added in v0.44.0

func (c NDBCache) MarshalJSON() ([]byte, error)

Convenience functions for serializing the data structure.

func (NDBCache) Put added in v0.44.0

func (c NDBCache) Put(name string, k, v ast.Value)

Put updates the cache for the named built-in. Automatically creates the 2-level hierarchy as needed.

func (*NDBCache) UnmarshalJSON added in v0.44.0

func (c *NDBCache) UnmarshalJSON(data []byte) error

Jump to

Keyboard shortcuts

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