nanocms_compiler

package
v0.0.0-...-7574d5e Latest Latest
Warning

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

Go to latest
Published: Mar 6, 2021 License: MIT Imports: 13 Imported by: 0

README

Nanostate Compiler

YAML declaration with call of functions, using embedded Python dialect.

Documentation

Index

Constants

View Source
const (
	CDL_T_INCLUSION = iota
	CDL_T_DEPENDENCY
	CDL_T_LOOP
	CDL_T_OPTIONAL_INCLUSION
)

Variables

This section is empty.

Functions

This section is empty.

Types

type CDLDependency

type CDLDependency struct {
	Stateid     string
	AnchorBlock string
	Blocks      []string
}

type CDLFunc

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

func NewCDLFunc

func NewCDLFunc() *CDLFunc

func (*CDLFunc) BlockType

func (cdl *CDLFunc) BlockType(stateid string, line string) (int, error)

BlockType returns a type of a block: reference or inclusion

func (*CDLFunc) Condition

func (cdl *CDLFunc) Condition(stateid string, line string) bool

Condition evaluates all possible conditions.

Although Wiz CDL supports multiple conditions in one line, yet they are not encouraged and are evaluated with "OR" statement (any).

Example:

something ?one ?two

If "one" or "two" results to "true", then "something" will happen. For complex conditions they needs to be combined in Skylark function and expressed in Wiz CDL as a single condition.

Example:

something ?onetwo

def onetwo():

return one() and two()

func (*CDLFunc) GetDependency

func (cdl *CDLFunc) GetDependency(stateid, line string) (*CDLDependency, error)

Dependency can include specific list of blocks from a state in the order they are defined. It does not allow to include the entire state with all the blocks:

<BLOCK-ID> &<STATE-ID>/<BLOCK-ID>:[BLOCK-ID]:...

Blocks are delimited with colon ":" symbol. For example, to add only one block from some state:

do-something &my-state/my-block

To add few blocks from that state:

do-something &my-state/my-block:my-other-block

func (*CDLFunc) GetInclusion

func (cdl *CDLFunc) GetInclusion(stateid string, line string) (*CDLInclusion, error)

Inclusion can have the entire state included or only specific blocks from it. The format is the following:

~<STATE-ID>/[BLOCK-A]:[BLOCK-B]:...

Blocks are delimited with colon ":" symbol. For example, to add the entire state:

~my-state

To add only one block from that state:

~my-state/my-block

To add few blocks from that state:

~my-state/my-block:my-other-block

All jobs from that block will be included.

func (*CDLFunc) ImportSource

func (cdl *CDLFunc) ImportSource(id string, srcpath string)

ImportSource of Starlark script and evaluate it into a running thread. StarlarkProcess has extra-check for the source contains only functions.

func (*CDLFunc) Loop

func (cdl *CDLFunc) Loop(stateid string, line string) (*CDLLoop, error)

Loop returns an array of key/value maps as keyword arguments and applies given function or module on each.

Example:

my-job:
	- my_module []my_function

The "my_function" is expected to return an array with keywords map inside, e.g.:

def my_function():
	return [
		{
			"name": "value",
			"other": "value",
		},
		{
			"name": "something",
			"other": "something-else".
		}
	]

In this case the example above will be compiled to the following:

my-job:
	- my_module:
		name: value
		other: value
	- my_module:
		name: something
		other: something-else

func (*CDLFunc) ToCDLKey

func (cdl *CDLFunc) ToCDLKey(stateid string, line string) string

ToCDLKey removes all controlling macros, leaving only ready to final use key.

type CDLInclusion

type CDLInclusion struct {
	Stateid string
	Blocks  []string
}

type CDLLoop

type CDLLoop struct {
	StateId string
	Module  string
	Params  []map[interface{}]interface{}
}

type NstCompiler

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

func NewNstCompiler

func NewNstCompiler() *NstCompiler

func (*NstCompiler) Compile

func (nstc *NstCompiler) Compile() error

Compile tree

func (*NstCompiler) Cycle

func (nstc *NstCompiler) Cycle() string

Cycle compiles current state and returns a next state Id to be found and loaded, if any. If returns an empty string, then no more cycles are found and Tree is ready.

func (*NstCompiler) Dump

func (nstc *NstCompiler) Dump()

func (*NstCompiler) LoadFile

func (nstc *NstCompiler) LoadFile(nstpath string) error

LoadFile loads a nanostate from the YAML file

func (*NstCompiler) SetDebug

func (nstc *NstCompiler) SetDebug(state bool) *NstCompiler

SetDebug state

func (*NstCompiler) SquashState

func (nstc *NstCompiler) SquashState(id string)

func (*NstCompiler) Tree

func (nstc *NstCompiler) Tree() *OTree

Tree returns completed tree

type OTree

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

func NewOTree

func NewOTree() *OTree

func (*OTree) Delete

func (tree *OTree) Delete(key interface{}) *OTree

Delete key. Nothing happens if the key wasn't there.

func (*OTree) Exists

func (tree *OTree) Exists(key interface{}) bool

Check if key is there

func (*OTree) Flush

func (tree *OTree) Flush() *OTree

Flush the content of the tree

func (*OTree) Get

func (tree *OTree) Get(key interface{}, bydefault interface{}) interface{}

Get key with the default

func (*OTree) GetBranch

func (tree *OTree) GetBranch(key interface{}) *OTree

GetBranch of the current tree. If branch is not an OTree object or not found, nil is returned.

func (*OTree) GetList

func (tree *OTree) GetList(key interface{}) []interface{}

GetList returns an object as an array of the interfaces. If an object is not a slice, nil is returned.

func (*OTree) GetString

func (tree *OTree) GetString(key interface{}) string

GetString returns a string, blindly assuming it is one. XXX: better implementation needed. :)

func (*OTree) Items

func (tree *OTree) Items() [][]interface{}

func (*OTree) Keys

func (tree *OTree) Keys() []interface{}

Return keys

func (*OTree) LoadMapSlice

func (tree *OTree) LoadMapSlice(data yaml.MapSlice) *OTree

LoadMapSlice loads a yaml.MapSlice object that keeps the ordering

func (*OTree) Serialise

func (tree *OTree) Serialise() map[string]interface{}

func (*OTree) Set

func (tree *OTree) Set(key interface{}, value interface{}) *OTree

Set the key/value

func (*OTree) ToYAML

func (tree *OTree) ToYAML() string

ToYAML exports ordered tree to an unordered YAML (!)

type RefList

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

func NewRefList

func NewRefList() *RefList

func (*RefList) FindRefs

func (rl *RefList) FindRefs(state *OTree)

Get all mentioned references

func (*RefList) Flush

func (rl *RefList) Flush() *RefList

Flush and forget everything

func (*RefList) GetIncluded

func (rl *RefList) GetIncluded() []string

func (*RefList) GetMandatoryUnresolved

func (rl *RefList) GetMandatoryUnresolved() []string

func (*RefList) GetReferencedJobs

func (rl *RefList) GetReferencedJobs() []string

func (*RefList) GetRequiredJobs

func (rl *RefList) GetRequiredJobs() []string

func (*RefList) MarkStateRequested

func (rl *RefList) MarkStateRequested(id string) string

MarkVisited marks a reference as "seen" and "requested". If it gets marked again, it means the request wasn't completed, so we hit a infinite cycle, which needs to be broken out.

func (*RefList) MarkStateResolved

func (rl *RefList) MarkStateResolved(id string) *RefList

MarkResolved marks a reference as "resolved" and removes from the stack

type StarTuple

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

func NewStarTuple

func NewStarTuple() *StarTuple

func (*StarTuple) Value

func (st *StarTuple) Value() []interface{}

type StarType

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

//////

func NewStarType

func NewStarType(v starlark.Value) *StarType

Constructor

func (*StarType) Interface

func (st *StarType) Interface() interface{}

Interface returns Go interface from Starlark type

func (*StarType) StarType

func (st *StarType) StarType() string

StarType tells a type of returned Starlark value

type StarlarkProcess

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

func NewStarlarkProcess

func NewStarlarkProcess() *StarlarkProcess

func (*StarlarkProcess) Call

func (sp *StarlarkProcess) Call(fn string, args starlark.Tuple, kwargs []starlark.Tuple) (starlark.Value, error)

func (*StarlarkProcess) LoadFile

func (sp *StarlarkProcess) LoadFile(src string) error

Jump to

Keyboard shortcuts

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