gates

package module
v0.0.14 Latest Latest
Warning

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

Go to latest
Published: Dec 12, 2020 License: MIT Imports: 12 Imported by: 0

README

Gates

An embedded language for Go.

Features

  • Easily embedded in Go.
  • JavaScript-like syntax with native int64 support.
  • First class functions.
  • Execution time limit.

Comparision

Gates Lua 5.3+ JavaScript
Int64 support Y Y N
Compatible with JSON Y N (hard to distinguish between [] and {}) Y
Easily embedded in Go Y N N

Try Gates in Command Line

$ go get -u github.com/lujjjh/gates/cmd/gates
$ echo '[1, 2, 3] | map(x => x * x)' | gates
# 1,4,9

Data Types

  • number (int64 / float64)
  • string
  • bool
  • map
  • array
  • function

Examples

View Examples

Credits

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	True  = Bool(true)
	False = Bool(false)
)
View Source
var (
	ErrStackOverflow       = errors.New("stack overflow")
	ErrCyclesLimitExceeded = errors.New("cycles limit exceeded")
)
View Source
var Null _Null

Functions

func Type added in v0.0.12

func Type(v Value) string

Type returns the type tag of the given value.

Types

type ArgumentScanner added in v0.0.12

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

func NewArgumentScanner added in v0.0.12

func NewArgumentScanner(fc FunctionCall) *ArgumentScanner

func (*ArgumentScanner) Scan added in v0.0.12

func (s *ArgumentScanner) Scan(values ...interface{}) error

type Array

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

func NewArray added in v0.0.12

func NewArray(values []Value) Array

func NewArrayFromStringSlice added in v0.0.12

func NewArrayFromStringSlice(a []string) Array

func (Array) Equals added in v0.0.12

func (a Array) Equals(other Value) bool

func (Array) Get added in v0.0.12

func (a Array) Get(r *Runtime, key Value) Value

func (Array) IsBool added in v0.0.12

func (Array) IsBool() bool

func (Array) IsFloat added in v0.0.12

func (Array) IsFloat() bool

func (Array) IsFunction added in v0.0.12

func (Array) IsFunction() bool

func (Array) IsInt added in v0.0.12

func (Array) IsInt() bool

func (Array) IsString added in v0.0.12

func (Array) IsString() bool

func (Array) Iterator added in v0.0.12

func (a Array) Iterator() Iterator

func (Array) SameAs added in v0.0.12

func (a Array) SameAs(other Value) bool

func (Array) Set added in v0.0.12

func (a Array) Set(r *Runtime, key, value Value)

func (Array) ToBool added in v0.0.12

func (Array) ToBool() bool

func (Array) ToFloat added in v0.0.12

func (Array) ToFloat() float64

func (Array) ToFunction added in v0.0.12

func (Array) ToFunction() Function

func (Array) ToInt added in v0.0.12

func (Array) ToInt() int64

func (Array) ToNative added in v0.0.12

func (a Array) ToNative(ops ...ToNativeOption) interface{}

func (Array) ToNumber added in v0.0.12

func (a Array) ToNumber() Number

func (Array) ToString added in v0.0.12

func (a Array) ToString() string

func (Array) Type added in v0.0.12

func (Array) Type() string

type Bool

type Bool bool

func (Bool) Equals

func (b Bool) Equals(other Value) bool

func (Bool) IsBool

func (Bool) IsBool() bool

func (Bool) IsFloat

func (Bool) IsFloat() bool

func (Bool) IsFunction

func (Bool) IsFunction() bool

func (Bool) IsInt

func (Bool) IsInt() bool

func (Bool) IsString

func (Bool) IsString() bool

func (Bool) SameAs

func (b Bool) SameAs(bv Value) bool

func (Bool) ToBool

func (b Bool) ToBool() bool

func (Bool) ToFloat

func (b Bool) ToFloat() float64

func (Bool) ToFunction

func (b Bool) ToFunction() Function

func (Bool) ToInt

func (b Bool) ToInt() int64

func (Bool) ToNative

func (b Bool) ToNative(...ToNativeOption) interface{}

func (Bool) ToNumber

func (b Bool) ToNumber() Number

func (Bool) ToString

func (b Bool) ToString() string

type Callback added in v0.0.12

type Callback func(...Value) Value

type CompilerError

type CompilerError struct {
	Message string
	File    *syntax.File
	Pos     syntax.Pos
}

type CompilerSyntaxError

type CompilerSyntaxError struct {
	CompilerError
}

func (*CompilerSyntaxError) Error

func (e *CompilerSyntaxError) Error() string

type ErrTooFewArguments added in v0.0.12

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

func (*ErrTooFewArguments) Error added in v0.0.12

func (e *ErrTooFewArguments) Error() string

type ErrTypeMismatch added in v0.0.12

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

func (*ErrTypeMismatch) Error added in v0.0.12

func (e *ErrTypeMismatch) Error() string

type ErrTypeNotSupported added in v0.0.12

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

func (*ErrTypeNotSupported) Error added in v0.0.12

func (e *ErrTypeNotSupported) Error() string

type ErrWithArgumentIndex added in v0.0.12

type ErrWithArgumentIndex struct {
	Err error
	// contains filtered or unexported fields
}

func (*ErrWithArgumentIndex) Error added in v0.0.12

func (e *ErrWithArgumentIndex) Error() string

type Float

type Float float64

func (Float) Equals

func (f Float) Equals(other Value) bool

func (Float) IsBool

func (Float) IsBool() bool

func (Float) IsFloat

func (Float) IsFloat() bool

func (Float) IsFunction

func (Float) IsFunction() bool

func (Float) IsInt

func (Float) IsInt() bool

func (Float) IsString

func (Float) IsString() bool

func (Float) SameAs

func (f Float) SameAs(b Value) bool

func (Float) ToBool

func (f Float) ToBool() bool

func (Float) ToFloat

func (f Float) ToFloat() float64

func (Float) ToFunction

func (f Float) ToFunction() Function

func (Float) ToInt

func (f Float) ToInt() int64

func (Float) ToNative

func (f Float) ToNative(...ToNativeOption) interface{}

func (Float) ToNumber

func (f Float) ToNumber() Number

func (Float) ToString

func (f Float) ToString() string

type Function

type Function interface {
	Value
	// contains filtered or unexported methods
}

func CurriedFunctionFunc added in v0.0.12

func CurriedFunctionFunc(n int, f func(FunctionCall) Value) Function

func Curry added in v0.0.12

func Curry(f Function, n int) Function

func FunctionFunc

func FunctionFunc(fun func(FunctionCall) Value) Function

type FunctionCall

type FunctionCall interface {
	Runtime() *Runtime
	Args() []Value
}

type Global

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

func NewGlobal

func NewGlobal() *Global

func (*Global) Get

func (g *Global) Get(name string) Value

func (*Global) Set

func (g *Global) Set(name string, value Value)

type Int

type Int int64

func (Int) Equals

func (i Int) Equals(other Value) bool

func (Int) IsBool

func (Int) IsBool() bool

func (Int) IsFloat

func (Int) IsFloat() bool

func (Int) IsFunction

func (Int) IsFunction() bool

func (Int) IsInt

func (Int) IsInt() bool

func (Int) IsString

func (Int) IsString() bool

func (Int) SameAs

func (i Int) SameAs(b Value) bool

func (Int) ToBool

func (i Int) ToBool() bool

func (Int) ToFloat

func (i Int) ToFloat() float64

func (Int) ToFunction

func (i Int) ToFunction() Function

func (Int) ToInt

func (i Int) ToInt() int64

func (Int) ToNative

func (i Int) ToNative(...ToNativeOption) interface{}

func (Int) ToNumber

func (i Int) ToNumber() Number

func (Int) ToString

func (i Int) ToString() string

type Iterable

type Iterable interface {
	Iterator() Iterator
}

func GetIterable

func GetIterable(v Value) (Iterable, bool)

type Iterator

type Iterator interface {
	Next() (value Value, ok bool)
}

func GetIterator added in v0.0.12

func GetIterator(v Value) (Iterator, bool)

type Map

type Map map[string]Value

func (Map) Equals

func (m Map) Equals(other Value) bool

func (Map) Get

func (m Map) Get(r *Runtime, key Value) Value

func (Map) IsBool

func (Map) IsBool() bool

func (Map) IsFloat

func (Map) IsFloat() bool

func (Map) IsFunction

func (Map) IsFunction() bool

func (Map) IsInt

func (Map) IsInt() bool

func (Map) IsString

func (Map) IsString() bool

func (Map) Iterator

func (m Map) Iterator() Iterator

func (Map) SameAs

func (m Map) SameAs(other Value) bool

func (Map) Set

func (m Map) Set(r *Runtime, key, value Value)

func (Map) ToBool

func (Map) ToBool() bool

func (Map) ToFloat

func (Map) ToFloat() float64

func (Map) ToFunction

func (Map) ToFunction() Function

func (Map) ToInt

func (Map) ToInt() int64

func (Map) ToNative

func (m Map) ToNative(ops ...ToNativeOption) interface{}

func (Map) ToNumber

func (m Map) ToNumber() Number

func (Map) ToString

func (Map) ToString() string

func (Map) Type added in v0.0.12

func (Map) Type() string

type Number

type Number interface {
	Value
	// contains filtered or unexported methods
}

type Program

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

func Compile

func Compile(x string) (program *Program, err error)

func (*Program) InstructionNumber added in v0.0.12

func (p *Program) InstructionNumber() int

type Ref

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

func NewRef

func NewRef(v interface{}) Ref

func (Ref) Equals

func (ref Ref) Equals(other Value) bool

func (Ref) IsBool

func (Ref) IsBool() bool

func (Ref) IsFloat

func (Ref) IsFloat() bool

func (Ref) IsFunction

func (r Ref) IsFunction() bool

func (Ref) IsInt

func (Ref) IsInt() bool

func (Ref) IsString

func (Ref) IsString() bool

func (Ref) SameAs

func (ref Ref) SameAs(other Value) bool

func (Ref) ToBool

func (Ref) ToBool() bool

func (Ref) ToFloat

func (Ref) ToFloat() float64

func (Ref) ToFunction

func (r Ref) ToFunction() Function

func (Ref) ToInt

func (Ref) ToInt() int64

func (Ref) ToNative

func (r Ref) ToNative(...ToNativeOption) interface{}

func (Ref) ToNumber

func (ref Ref) ToNumber() Number

func (Ref) ToString

func (Ref) ToString() string

type Runtime

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

func New

func New() *Runtime

func (*Runtime) Call

func (r *Runtime) Call(f Function, args ...Value) Value

func (*Runtime) Context

func (r *Runtime) Context() context.Context

func (*Runtime) Global

func (r *Runtime) Global() *Global

func (*Runtime) RunProgram

func (r *Runtime) RunProgram(ctx context.Context, program *Program) (Value, error)

func (*Runtime) RunString

func (r *Runtime) RunString(s string) (Value, error)

func (*Runtime) SetCyclesLimit added in v0.0.12

func (r *Runtime) SetCyclesLimit(max int)

func (*Runtime) ToValue

func (r *Runtime) ToValue(i interface{}) Value

type String

type String string

func (String) Equals added in v0.0.12

func (s String) Equals(other Value) bool

func (String) Get added in v0.0.12

func (s String) Get(r *Runtime, key Value) Value

func (String) IsBool added in v0.0.12

func (String) IsBool() bool

func (String) IsFloat added in v0.0.12

func (String) IsFloat() bool

func (String) IsFunction added in v0.0.12

func (String) IsFunction() bool

func (String) IsInt added in v0.0.12

func (String) IsInt() bool

func (String) IsString added in v0.0.12

func (String) IsString() bool

func (String) SameAs added in v0.0.12

func (s String) SameAs(b Value) bool

func (String) ToBool added in v0.0.12

func (s String) ToBool() bool

func (String) ToFloat added in v0.0.12

func (s String) ToFloat() float64

func (String) ToFunction added in v0.0.12

func (s String) ToFunction() Function

func (String) ToInt added in v0.0.12

func (s String) ToInt() int64

func (String) ToNative added in v0.0.12

func (s String) ToNative(...ToNativeOption) interface{}

func (String) ToNumber added in v0.0.12

func (s String) ToNumber() Number

func (String) ToString added in v0.0.12

func (s String) ToString() string

type ToNativeOption added in v0.0.12

type ToNativeOption int
const (
	SkipCircularReference ToNativeOption = 1 << iota
)

type Value

type Value interface {
	IsString() bool
	IsInt() bool
	IsFloat() bool
	IsBool() bool
	IsFunction() bool

	ToString() string
	ToInt() int64
	ToFloat() float64
	ToNumber() Number
	ToBool() bool
	ToFunction() Function

	ToNative(...ToNativeOption) interface{}

	Equals(Value) bool
	SameAs(Value) bool
}

func ToValue

func ToValue(i interface{}) Value

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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