state

package
v0.0.15 Latest Latest
Warning

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

Go to latest
Published: Dec 14, 2022 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const (
	LeafString = LeafType(iota + 1)
	LeafFloat
	LeafInteger
	LeafBoolean
	LeafRaw
)
View Source
const BindingSep = "<=>"
View Source
const BindingSepIn = "->"
View Source
const BindingSepOut = "<-"
View Source
const LibSep = "."
View Source
const StateSep = "/"
View Source
const ValueSep = "."

Variables

This section is empty.

Functions

This section is empty.

Types

type Action

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

func (*Action) Compile

func (u *Action) Compile(lib *Library) error

func (*Action) Exec

func (u *Action) Exec(stt State) error

func (Action) MarshalJSON

func (u Action) MarshalJSON() ([]byte, error)

func (Action) MarshalYAML

func (u Action) MarshalYAML() (interface{}, error)

func (*Action) MustExecUpdate

func (u *Action) MustExecUpdate(stt *MemState)

func (*Action) UnmarshalJSON

func (u *Action) UnmarshalJSON(data []byte) error

func (*Action) UnmarshalYAML

func (u *Action) UnmarshalYAML(value *yaml.Node) error

type ActionBound

type ActionBound struct {
	Binding *TwoBinding `yaml:"binding"`
	Action  *Action     `yaml:"update"`
}

type ActionIf

type ActionIf struct {
	Condition  *Condition `yaml:"condition"`
	Expression *Expression
	Then       *Action `yaml:"then"`
	Else       *Action `yaml:"else"`
}

type ActionNative

type ActionNative func(stateInterface NativeInterface) error

type ActionWhile

type ActionWhile struct {
	Condition *Condition `yaml:"condition"`
	Do        *Action    `yaml:"do"`
}

type Binding

type Binding map[string]string

Binding maps values from a context onto another context, where keys are the targets and values are the source

type BoundState

type BoundState struct {
	Binding Binding
	State   State
}

type Condition

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

func (*Condition) Compile

func (c *Condition) Compile(lib *Library) error

func (*Condition) Eval

func (c *Condition) Eval(stt State) (bool, error)

func (Condition) MarshalJSON

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

func (Condition) MarshalYAML

func (c Condition) MarshalYAML() (interface{}, error)

func (Condition) MustEval

func (c Condition) MustEval(stt State) bool

func (*Condition) UnmarshalJSON

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

func (*Condition) UnmarshalYAML

func (c *Condition) UnmarshalYAML(value *yaml.Node) error

type ConditionNative

type ConditionNative func(stateInterface NativeInterface) (bool, error)

type Definitions

type Definitions struct {
	Types       map[string]*Type       `json:"types" yaml:"types"`
	Expressions map[string]*Expression `json:"expressions" yaml:"expressions"`
	Conditions  map[string]*Condition  `json:"conditions" yaml:"conditions"`
	Actions     map[string]*Action     `json:"actions" yaml:"actions"`
}

type Expression

type Expression struct {
	Name string `json:"name" yaml:"name"`

	Value     any           `json:"value" yaml:"value"`
	Variable  string        `json:"variable" yaml:"variable"`
	Reference string        `json:"reference" yaml:"reference"`
	Operation string        `json:"operation" yaml:"operation"`
	Children  []*Expression `json:"children" yaml:"children"`

	Native ExpressionNative `json:"-" yaml:"-"`
	// contains filtered or unexported fields
}

func (*Expression) Compile

func (c *Expression) Compile(lib *Library) error

func (*Expression) Eval

func (c *Expression) Eval(stt State) (any, error)

func (Expression) MustEval

func (c Expression) MustEval(stt State) any

type ExpressionNative

type ExpressionNative func(stateInterface NativeInterface) (any, error)

type Factory

type Factory struct {
	Name  string `json:"name"`
	Token string `json:"token"`
	// contains filtered or unexported fields
}

func (*Factory) Produce

func (f *Factory) Produce() (*MemState, error)

type GenericMap

type GenericMap map[string]*Type

type LangError

type LangError struct {
	Ctx antlr.ParserRuleContext
	Err error
	// contains filtered or unexported fields
}

func (LangError) String

func (err LangError) String() string

type LeafType

type LeafType int

func (*LeafType) FromString

func (tb *LeafType) FromString(str string) error

func (LeafType) MarshalJSON

func (tb LeafType) MarshalJSON() ([]byte, error)

func (LeafType) MarshalYAML

func (tb LeafType) MarshalYAML() (interface{}, error)

func (LeafType) String

func (tb LeafType) String() string

func (*LeafType) UnmarshalJSON

func (tb *LeafType) UnmarshalJSON(data []byte) error

func (*LeafType) UnmarshalYAML

func (tb *LeafType) UnmarshalYAML(value *yaml.Node) error

type Library

type Library struct {
	Name     string
	Parent   *Library
	Children map[string]*Library

	Definitions Definitions
}

Library contains definitions and hooks to the native environment. It is independent of states.

func NewLibrary

func NewLibrary() *Library

func (*Library) AddDefinitions

func (lib *Library) AddDefinitions(defs Definitions) error

func (*Library) Compile

func (lib *Library) Compile() error

func (*Library) Copy

func (lib *Library) Copy() *Library

func (*Library) FullName

func (lib *Library) FullName() string

func (*Library) GetAction

func (lib *Library) GetAction(name string) (*Action, error)

func (*Library) GetCondition

func (lib *Library) GetCondition(name string) (*Condition, error)

func (*Library) GetExpression

func (lib *Library) GetExpression(name string) (*Expression, error)

func (*Library) GetLibrary

func (lib *Library) GetLibrary(name string) (*Library, error)

func (*Library) GetType

func (lib *Library) GetType(name string) (*Type, error)

func (*Library) LoadFromDir

func (lib *Library) LoadFromDir(dir string) error

func (*Library) MustGetAction

func (lib *Library) MustGetAction(name string) *Action

func (*Library) MustGetCondition

func (lib *Library) MustGetCondition(name string) *Condition

func (*Library) MustGetExpression

func (lib *Library) MustGetExpression(name string) *Expression

func (*Library) MustGetType

func (lib *Library) MustGetType(name string) *Type

func (*Library) RegisterAction

func (lib *Library) RegisterAction(name string, native ActionNative, valueType *Type) error

func (*Library) RegisterCondition

func (lib *Library) RegisterCondition(name string, cond ConditionNative) error

type MemState

type MemState struct {
	// Name of the state
	Name string

	// Parent contains the parent state to achieve mapping
	Parent *BoundState

	// Children were produced from this state
	Children map[string]*BoundState

	// ValueHolder contains values of this state
	Values *ValueHolder

	// Actions are invoked on each state change
	Actions []*StateAction
	// contains filtered or unexported fields
}

func NewMemState

func NewMemState(name string, values *ValueHolder) (*MemState, error)

func (*MemState) AddUpdate

func (stt *MemState) AddUpdate(cond *Condition, udt *Action)

func (*MemState) Detach

func (stt *MemState) Detach()

func (*MemState) FullName

func (stt *MemState) FullName() string

func (*MemState) GetValue

func (stt *MemState) GetValue(name string) (*ValueHolder, error)

func (*MemState) Interface

func (stt *MemState) Interface() NativeInterface

func (*MemState) Mem

func (stt *MemState) Mem() *MemState

func (*MemState) NewChild

func (stt *MemState) NewChild(name string, values *ValueHolder, childBinding *TwoBinding) (*MemState, error)

func (*MemState) RemoveChild

func (stt *MemState) RemoveChild(name string) error

func (*MemState) RunUpdates

func (stt *MemState) RunUpdates() error

func (*MemState) SetValue

func (stt *MemState) SetValue(name string, value any) error

func (*MemState) String

func (stt *MemState) String() string

func (*MemState) Take

func (stt *MemState) Take(state *MemState, mapping Binding) error

func (*MemState) Type

func (stt *MemState) Type() *Type

func (*MemState) ValueMux

func (stt *MemState) ValueMux() *sync.Mutex

type NativeInterface

type NativeInterface interface {
	Set(name string, value any) error
	Get(name string) (any, error)
}

type Parser

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

func NewParser

func NewParser(lib *Library) *Parser

func (*Parser) ParseDir

func (c *Parser) ParseDir(dir string) error

func (*Parser) ParseFile

func (c *Parser) ParseFile(file string) error

func (*Parser) ParseSource

func (c *Parser) ParseSource(source string) error

type State

type State interface {
	String() string
	FullName() string
	Interface() NativeInterface
	SetValue(name string, value any) error
	GetValue(name string) (*ValueHolder, error)
	RemoveChild(name string) error
	Type() *Type
	Mem() *MemState
}

type StateAction

type StateAction struct {
	Condition *Condition `json:"condition" yaml:"condition"`
	Update    *Action    `json:"update" yaml:"update"`
}

type TwoBinding

type TwoBinding struct {
	In  Binding
	Out Binding
}

TwoBinding specifies how two states should update each other At some point, we can think of an extension to allow for cross-machine bindings

func MustParseBinding

func MustParseBinding(strs ...string) *TwoBinding

func ParseTwoBinding

func ParseTwoBinding(strs []string) (*TwoBinding, error)

func (TwoBinding) MarshalJSON

func (tb TwoBinding) MarshalJSON() ([]byte, error)

func (TwoBinding) MarshalYAML

func (tb TwoBinding) MarshalYAML() (interface{}, error)

func (*TwoBinding) UnmarshalJSON

func (tb *TwoBinding) UnmarshalJSON(data []byte) error

func (*TwoBinding) UnmarshalYAML

func (tb *TwoBinding) UnmarshalYAML(value *yaml.Node) error

type Type

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

func MustParseType

func MustParseType(typeJSON string) *Type

func ParseType

func ParseType(typeJSON string, lib *Library) (*Type, error)

func (*Type) Accepts

func (t *Type) Accepts(src *Type) (bool, error)

func (*Type) Compile

func (t *Type) Compile(lib *Library) error

func (Type) MarshalJSON

func (t Type) MarshalJSON() ([]byte, error)

func (Type) MarshalYAML

func (t Type) MarshalYAML() (interface{}, error)

func (*Type) UnmarshalJSON

func (t *Type) UnmarshalJSON(data []byte) error

func (*Type) UnmarshalYAML

func (t *Type) UnmarshalYAML(value *yaml.Node) error

type ValueHolder

type ValueHolder struct {
	Type  *Type `json:"type,omitempty"`
	Value any   `json:"value,omitempty"`
	// contains filtered or unexported fields
}

func (*ValueHolder) Copy

func (v *ValueHolder) Copy() *ValueHolder

func (*ValueHolder) GetValue

func (v *ValueHolder) GetValue(name string) (*ValueHolder, error)

func (*ValueHolder) SetValue

func (v *ValueHolder) SetValue(name string, value any) error

func (*ValueHolder) String

func (v *ValueHolder) String() string

type WebState

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

func NewWebState

func NewWebState(addr string, path string, factory string, token string) (*WebState, error)

func (*WebState) FullName

func (wst *WebState) FullName() string

func (*WebState) GetValue

func (wst *WebState) GetValue(name string) (*ValueHolder, error)

func (*WebState) Interface

func (wst *WebState) Interface() NativeInterface

func (*WebState) Mem

func (wst *WebState) Mem() *MemState

func (*WebState) RemoveChild

func (wst *WebState) RemoveChild(name string) error

func (*WebState) Run

func (wst *WebState) Run()

func (*WebState) SetValue

func (wst *WebState) SetValue(name string, value any) error

func (*WebState) String

func (wst *WebState) String() string

func (*WebState) Sync

func (wst *WebState) Sync(name string) error

func (*WebState) Type

func (wst *WebState) Type() *Type

type WebsocketServer

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

func NewWebsocketServer

func NewWebsocketServer(addr string, path string) (*WebsocketServer, error)

func (*WebsocketServer) AddFactory

func (ws *WebsocketServer) AddFactory(st *MemState, factory string, token string, binding *TwoBinding, value *ValueHolder) (*Factory, error)

func (*WebsocketServer) Shutdown

func (ws *WebsocketServer) Shutdown() error

func (*WebsocketServer) Start

func (ws *WebsocketServer) Start() error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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