commands

package
v0.0.0-...-6247a41 Latest Latest
Warning

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

Go to latest
Published: Jan 17, 2023 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNotLoopScope = errors.New("top scope is not a loop scope")

Return from endLoop if last opened scope is not a loop scope

Functions

This section is empty.

Types

type Command

type Command[T state.StateType] interface {
	HandleCommand(passive bool, vm Controller[T]) error
}

Define Command interface. HandleCommand would be called each time the command need to be run by the interpreter.

func NewDecrementPointer

func NewDecrementPointer[T state.StateType]() Command[T]

Move the pointer to the left

func NewDecrementPointerValue

func NewDecrementPointerValue[T state.StateType]() Command[T]

Decrement the pointer value by one

func NewEndLoop

func NewEndLoop[T state.StateType]() Command[T]

If pointer value is not 0 return to the last openLoop, else move to next command

func NewIncrementPointer

func NewIncrementPointer[T state.StateType]() Command[T]

Move the pointer to the right

func NewIncrementPointerValue

func NewIncrementPointerValue[T state.StateType]() Command[T]

Increment the pointer value by one

func NewReadByte

func NewReadByte[T state.StateType](
	reader io.Reader,
	promptWriter,
	errWriter io.Writer,
) Command[T]

Read a single byte a numeric value from reader. If promptWriter is not nil, it will use to show the prompt message if user input have any error, it will be write to errWriter

func NewStartLoop

func NewStartLoop[T state.StateType]() Command[T]

If pointer value is 0 skip till next endLoop, else move to next command

func NewWriteByte

func NewWriteByte[T state.StateType](writer io.Writer, errWriter io.Writer) Command[T]

Write a single byte a numeric value from writer. if user pointer value does not fit in a byte, write an error to errWriter

type CommandFn

type CommandFn[T state.StateType] func(bool, Controller[T]) error

convert a function to a Command and will call the provided function on HandleCommand

func (CommandFn[T]) HandleCommand

func (fn CommandFn[T]) HandleCommand(passive bool, wm Controller[T]) error

type Controller

type Controller[T state.StateType] interface {
	state.State[T]
	Symbol() Symbol
	PushScope(symbol Symbol, needed, lazy bool)
	PopScope() Symbol
	Rewind()
}

Define the Controller interface which Commands can use to controll state and execution of the program

type Symbol

type Symbol chan interface{}

For traking uniqe values as each call to make(chan interface{}) would return a uniqe value

func NewSymbol

func NewSymbol() Symbol

Return a new Symbol

Jump to

Keyboard shortcuts

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