dcell

package module
v0.0.0-...-e90178e Latest Latest
Warning

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

Go to latest
Published: May 16, 2025 License: Apache-2.0, MIT Imports: 8 Imported by: 0

README ¶

🔋 D-Cell

D-Cell is the batteries-included Dynamic Condition Evaluation Language for Go.

Documentation ¶

Index ¶

Constants ¶

This section is empty.

Variables ¶

This section is empty.

Functions ¶

This section is empty.

Types ¶

type Expr ¶

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

Expr is a compiled dcell expression that can be evaluated.

func Compile ¶

func Compile(expression string, opts ...Option) (*Expr, error)

Compile compiles a dcell expression string into an Expr.

func MustCompile ¶

func MustCompile(expr string, opts ...Option) *Expr

MustCompile compiles a dcell expression string into an Expr and panics if it fails.

func (*Expr) Eval ¶

func (e *Expr) Eval(v any) (*Result, error)

Eval evaluates the expression with the provided value context.

func (*Expr) MarshalText ¶

func (e *Expr) MarshalText() ([]byte, error)

MarshalText marshals the expression to a textual format.

func (*Expr) MustEval ¶

func (e *Expr) MustEval(v any) *Result

MustEval evaluates the expression with the provided value context and panics if it fails.

func (*Expr) String ¶

func (e *Expr) String() string

String returns the string representation of the expression.

func (*Expr) UnmarshalText ¶

func (e *Expr) UnmarshalText(b []byte) error

UnmarshalText unmarshals a dcell expression from text.

type Option ¶

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

Option is an option that can be used to configure the dcell compiler.

func WithFunc ¶

func WithFunc(name string, fn any) Option

WithFunc adds a function to the dcell function table.

fn may be any function type, including variadic functions, and must return (T, error) or just T. The implementation will automatically handle conversions from the input types to the function's parameter types and from the function's return types to the output types.

Example:

dcell.WithFunc(func(base, exponent int) (int, error) {
    return int(math.Pow(float64(base), float64(exponent))), nil
})

type Result ¶

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

Result is the result of evaluating a dcell expression. This may be a

func (*Result) Bool ¶

func (r *Result) Bool() (bool, error)

Bool attempts to convert the result to a boolean value.

func (*Result) Equal ¶

func (r *Result) Equal(other *Result) bool

Equal returns true if the two results are semantically equal. This is a deep comparison of the underlying values, but not the underlying storage or types -- meaning that two results carrying different types with the same value are considered equal, such as `int(42)` and `int8(42)`.

This check is done recursively for structures, maps, and slices.

func (*Result) Float32 ¶

func (r *Result) Float32() (float32, error)

Float32 attempts to convert the result to a 32-bit floating point value. If the value is not convertible to a string, or would lose information in the conversion, an error is returned.

func (*Result) Float64 ¶

func (r *Result) Float64() (float64, error)

Float64 attempts to convert the result to a 64-bit floating point value. If the value is not convertible to a string, or would lose information in the conversion, an error is returned.

func (*Result) Int ¶

func (r *Result) Int() (int, error)

Int attempts to convert the result to a signed integer value. If the value is not convertible to a string, or would lose information in the conversion, an error is returned.

func (*Result) Int16 ¶

func (r *Result) Int16() (int16, error)

Int16 attempts to convert the result to a 16-bit signed integer value. If the value is not convertible to a string, or would lose information in the conversion, an error is returned.

func (*Result) Int32 ¶

func (r *Result) Int32() (int32, error)

Int32 attempts to convert the result to a 32-bit signed integer value. If the value is not convertible to a string, or would lose information in the conversion, an error is returned.

func (*Result) Int64 ¶

func (r *Result) Int64() (int64, error)

Int64 attempts to convert the result to a 64-bit signed integer value. If the value is not convertible to a string, or would lose information in the conversion, an error is returned.

func (*Result) Int8 ¶

func (r *Result) Int8() (int8, error)

Int8 attempts to convert the result to an 8-bit signed integer value. If the value is not convertible to a string, or would lose information in the conversion, an error is returned.

func (*Result) Interface ¶

func (r *Result) Interface() any

Interface returns the underlying value of the result. If the IsNil would return true, this will return nil.

func (*Result) IsNil ¶

func (r *Result) IsNil() bool

IsNil returns true if there is no value in the result, or if the value that would be returned is a nil value -- such as a pointer, slice, or map.

func (*Result) IsTruthy ¶

func (r *Result) IsTruthy() bool

IsTruthy returns true if the result is a truthy value. Truthiness is determined by the following rules:

  • Numeric values are truthy if they are not zero.
  • Strings are truthy if they are not empty.
  • Slices and maps are truthy if they are not nil and contain at least one element.
  • Pointers are truthy if they are not nil.
  • Structs are always truthy
  • All else is considered truthy only if reflect.Value.IsZero returns false.

func (*Result) IsZero ¶

func (r *Result) IsZero() bool

IsZero returns true if the result is a zero value, or nil.

func (*Result) String ¶

func (r *Result) String() (string, error)

String returns the result as a string.

func (*Result) Uint ¶

func (r *Result) Uint() (uint, error)

Uint attempts to convert the result to an unsigned integer value. If the value is not convertible to a string, or would lose information in the conversion, an error is returned.

func (*Result) Uint16 ¶

func (r *Result) Uint16() (uint16, error)

Uint16 attempts to convert the result to a 16-bit unsigned integer value. If the value is not convertible to a string, or would lose information in the conversion, an error is returned.

func (*Result) Uint32 ¶

func (r *Result) Uint32() (uint32, error)

Uint32 attempts to convert the result to a 32-bit unsigned integer value. If the value is not convertible to a string, or would lose information in the conversion, an error is returned.

func (*Result) Uint64 ¶

func (r *Result) Uint64() (uint64, error)

Uint64 attempts to convert the result to a 64-bit unsigned integer value. If the value is not convertible to a string, or would lose information in the conversion, an error is returned.

func (*Result) Uint8 ¶

func (r *Result) Uint8() (uint8, error)

Uint8 attempts to convert the result to an 8-bit unsigned integer value. If the value is not convertible to a string, or would lose information in the conversion, an error is returned.

func (*Result) Value ¶

func (r *Result) Value() reflect.Value

Value returns the underlying value of the result. If the IsNil would return true, this will return a zero value of the type of the result.

Directories ¶

Path Synopsis
internal
errs
Package errs is an internal package that provides shared errors across the go-dcell library.
Package errs is an internal package that provides shared errors across the go-dcell library.
intcmp
Package intcmp provides integer comparison functions for comparing signed and unsigned integers.
Package intcmp provides integer comparison functions for comparing signed and unsigned integers.
intconv
Package intconv provides functions for narrowing conversions between signed and unsigned integers.
Package intconv provides functions for narrowing conversions between signed and unsigned integers.
invocation
Package invocation provides a mechanism for defining and invoking functions in a yamlpath expression.
Package invocation provides a mechanism for defining and invoking functions in a yamlpath expression.
invocation/arity
Package arity is a micro-package for providing the Arity type, which is used to identify whether the number of arguments being provided to an invocation is valid.
Package arity is a micro-package for providing the Arity type, which is used to identify whether the number of arguments being provided to an invocation is valid.
levenshtein
Package levenshtein provides a function to calculate the Damerau-Levenshtein distance between two strings.
Package levenshtein provides a function to calculate the Damerau-Levenshtein distance between two strings.

Jump to

Keyboard shortcuts

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