mito

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

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

Go to latest
Published: Sep 7, 2023 License: MIT Imports: 9 Imported by: 1

README

mito

it's the powerhouse of the cel

mito is my attempt at a simple version of google's CEL common expression language. instead of using protobufs for value types, it lets you use your own types, kind of like userdata in lua.

License

Released under the MIT license. See LICENSE.

Documentation

Overview

Package mito is an attempt at making CEL (the "common expression language"), but much more simply. instead of using protobufs it lets you use your own types, kind of like userdata in lua.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrParser        = errors.New("parser error")
	ErrUnboundVar    = errors.New("unbound variable")
	ErrUnknownOp     = errors.New("unknown op")
	ErrInvalidOp     = errors.New("invalid op")
	ErrTypeMismatch  = errors.New("type mismatch")
	ErrValueMismatch = errors.New("value mismatch")
)

Functions

func Eval

func Eval(expression string, env map[any]any) (any, error)

Types

type Call

type Call struct {
	Func Evaluable
	Args []Evaluable
}

func (*Call) Run

func (c *Call) Run(env map[any]any) (rv any, err error)

type Evaluable

type Evaluable interface {
	Run(env map[any]any) (any, error)
}

func Parse

func Parse(expression string) (Evaluable, error)

type Ident

type Ident struct {
	Name string
}

func (*Ident) Run

func (i *Ident) Run(env map[any]any) (any, error)

type ModType

type ModType string
const (
	ModNeg ModType = "-"
	ModNot ModType = "!"
)

type Modifier

type Modifier struct {
	Type ModType
	Val  Evaluable
}

func (*Modifier) Run

func (m *Modifier) Run(env map[any]any) (any, error)

type OpType

type OpType string
const (
	OpOrModNil            = ""
	OpExp          OpType = "^"
	OpMul          OpType = "*"
	OpDiv          OpType = "/"
	OpAdd          OpType = "+"
	OpSub          OpType = "-"
	OpLess         OpType = "<"
	OpLessEqual    OpType = "<="
	OpEqual        OpType = "=="
	OpNotEqual     OpType = "!="
	OpGreater      OpType = ">"
	OpGreaterEqual OpType = ">="
	OpAnd          OpType = "&&"
	OpOr           OpType = "||"
)

type Operation

type Operation struct {
	Type  OpType
	Left  Evaluable
	Right Evaluable
}

func (*Operation) Run

func (o *Operation) Run(env map[any]any) (any, error)

type Parser

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

func NewParser

func NewParser(source string) *Parser

func (*Parser) Parse

func (p *Parser) Parse() (Evaluable, error)

type Subexpression

type Subexpression struct {
	Expr Evaluable
}

func (*Subexpression) Run

func (s *Subexpression) Run(env map[any]any) (any, error)

type Value

type Value[T any] struct {
	Val T
}

func (*Value[T]) Run

func (v *Value[T]) Run(env map[any]any) (any, error)

Jump to

Keyboard shortcuts

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