util

package
v1.6.2 Latest Latest
Warning

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

Go to latest
Published: May 23, 2021 License: MIT Imports: 13 Imported by: 3

Documentation

Overview

Package util contains utility definitions and functions for the event condition language ECAL.

Index

Constants

View Source
const (
	Debug LogLevel = "debug"
	Info           = "info"
	Error          = "error"
)

Log levels

Variables

View Source
var (
	ErrRuntimeError     = errors.New("Runtime error")
	ErrUnknownConstruct = errors.New("Unknown construct")
	ErrInvalidConstruct = errors.New("Invalid construct")
	ErrInvalidState     = errors.New("Invalid state")
	ErrVarAccess        = errors.New("Cannot access variable")
	ErrNotANumber       = errors.New("Operand is not a number")
	ErrNotABoolean      = errors.New("Operand is not a boolean")
	ErrNotAList         = errors.New("Operand is not a list")
	ErrNotAMap          = errors.New("Operand is not a map")
	ErrNotAListOrMap    = errors.New("Operand is not a list nor a map")
	ErrSink             = errors.New("Error in sink")

	// ErrReturn is not an error. It is used to return when executing a function
	ErrReturn = errors.New("*** return ***")

	// Error codes for loop operations
	ErrIsIterator        = errors.New("Function is an iterator")
	ErrEndOfIteration    = errors.New("End of iteration was reached")
	ErrContinueIteration = errors.New("End of iteration step - Continue iteration")
)

Runtime related error types.

Functions

func NewRuntimeError

func NewRuntimeError(source string, t error, d string, node *parser.ASTNode) error

NewRuntimeError creates a new RuntimeError object.

Types

type BufferLogger

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

BufferLogger logs into a buffer.

func NewBufferLogger

func NewBufferLogger(buf io.Writer) *BufferLogger

NewBufferLogger returns a buffer logger instance.

func (*BufferLogger) LogDebug

func (bl *BufferLogger) LogDebug(m ...interface{})

LogDebug adds a new debug log message.

func (*BufferLogger) LogError

func (bl *BufferLogger) LogError(m ...interface{})

LogError adds a new error log message.

func (*BufferLogger) LogInfo

func (bl *BufferLogger) LogInfo(m ...interface{})

LogInfo adds a new info log message.

type ContType added in v1.0.0

type ContType int

ContType represents a way how to resume code execution of a suspended thread.

const (
	Resume   ContType = iota // Resume code execution until the next breakpoint or the end
	StepIn                   // Step into a function call or over the next non-function call
	StepOver                 // Step over the current statement onto the next line
	StepOut                  // Step out of the current function call
)

Available lexer token types

type DebugCommand added in v1.0.0

type DebugCommand interface {

	/*
		Execute the debug command and return its result. It must be possible to
		convert the output data into a JSON string.
	*/
	Run(debugger ECALDebugger, args []string) (interface{}, error)

	/*
	   DocString returns a descriptive text about this command.
	*/
	DocString() string
}

DebugCommand is command which can modify and interrogate the debugger.

type ECALDebugger added in v1.0.0

type ECALDebugger interface {

	/*
		HandleInput handles a given debug instruction. It must be possible to
		convert the output data into a JSON string.
	*/
	HandleInput(input string) (interface{}, error)

	/*
	   StopThreads will continue all suspended threads and set them to be killed.
	   Returns true if a waiting thread was resumed. Can wait for threads to end
	   by ensuring that for at least d time no state change occurred.
	*/
	StopThreads(d time.Duration) bool

	/*
	   BreakOnStart breaks on the start of the next execution.
	*/
	BreakOnStart(flag bool)

	/*
	   BreakOnError breaks if an error occurs.
	*/
	BreakOnError(flag bool)

	/*
	   SetLockingState sets locking status information.
	*/
	SetLockingState(mutexeOwners map[string]uint64, mutexLog *datautil.RingBuffer)

	/*
	   SetThreadPool sets the reference to the current used thread pool.
	*/
	SetThreadPool(tp *pool.ThreadPool)

	/*
	   VisitState is called for every state during the execution of a program.
	*/
	VisitState(node *parser.ASTNode, vs parser.Scope, tid uint64) TraceableRuntimeError

	/*
	   VisitStepInState is called before entering a function call.
	*/
	VisitStepInState(node *parser.ASTNode, vs parser.Scope, tid uint64) TraceableRuntimeError

	/*
	   VisitStepOutState is called after returning from a function call.
	*/
	VisitStepOutState(node *parser.ASTNode, vs parser.Scope, tid uint64, soErr error) TraceableRuntimeError

	/*
	   RecordThreadFinished lets the debugger know that a thread has finished.
	*/
	RecordThreadFinished(tid uint64)

	/*
	   SetBreakPoint sets a break point.
	*/
	SetBreakPoint(source string, line int)

	/*
	   DisableBreakPoint disables a break point but keeps the code reference.
	*/
	DisableBreakPoint(source string, line int)

	/*
	   RemoveBreakPoint removes a break point.
	*/
	RemoveBreakPoint(source string, line int)

	/*
		ExtractValue copies a value from a suspended thread into the
		global variable scope.
	*/
	ExtractValue(threadID uint64, varName string, destVarName string) error

	/*
		InjectValue copies a value from an expression (using the global
		variable scope) into a suspended thread.
	*/
	InjectValue(threadID uint64, varName string, expression string) error

	/*
	   Continue will continue a suspended thread.
	*/
	Continue(threadID uint64, contType ContType)

	/*
		Status returns the current status of the debugger.
	*/
	Status() interface{}

	/*
	   LockStatus returns the current locking status.
	*/
	LockState() interface{}

	/*
	   Describe describes a thread currently observed by the debugger.
	*/
	Describe(threadID uint64) interface{}
}

ECALDebugger is a debugging object which can be used to inspect and modify a running ECAL environment.

type ECALFunction

type ECALFunction interface {

	/*
		Run executes this function. The envirnment provides a unique instanceID for
		every code location in the running code, the variable scope of the function,
		an instance state which can be used in combinartion with the instanceID
		to store instance specific state (e.g. for iterator functions) and a list
		of argument values which were passed to the function by the calling code.
	*/
	Run(instanceID string, vs parser.Scope, is map[string]interface{}, tid uint64, args []interface{}) (interface{}, error)

	/*
	   DocString returns a descriptive text about this function.
	*/
	DocString() (string, error)
}

ECALFunction models a callable function in ECAL.

type ECALImportLocator

type ECALImportLocator interface {

	/*
		Resolve a given import path and parse the imported file into an AST.
	*/
	Resolve(path string) (string, error)
}

ECALImportLocator is used to resolve imports.

type ECALPluginFunction added in v1.1.0

type ECALPluginFunction interface {

	/*
		Run executes this function with a given list of arguments.
	*/
	Run(args []interface{}) (interface{}, error)

	/*
	   DocString returns a descriptive text about this function.
	*/
	DocString() string
}

ECALPluginFunction models a callable function in ECAL which can be imported via a plugin.

type FileImportLocator

type FileImportLocator struct {
	Root string // Relative root path
}

FileImportLocator tries to locate files on disk relative to a root directory and provide them as imports.

func (*FileImportLocator) Resolve

func (il *FileImportLocator) Resolve(path string) (string, error)

Resolve a given import path and parse the imported file into an AST.

type LogLevel

type LogLevel string

LogLevel represents a logging level

type LogLevelLogger

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

LogLevelLogger is a wrapper around loggers to add log level functionality.

func NewLogLevelLogger

func NewLogLevelLogger(logger Logger, level string) (*LogLevelLogger, error)

NewLogLevelLogger wraps a given logger and adds level based filtering functionality.

func (*LogLevelLogger) Level

func (ll *LogLevelLogger) Level() LogLevel

Level returns the current log level.

func (*LogLevelLogger) LogDebug

func (ll *LogLevelLogger) LogDebug(m ...interface{})

LogDebug adds a new debug log message.

func (*LogLevelLogger) LogError

func (ll *LogLevelLogger) LogError(m ...interface{})

LogError adds a new error log message.

func (*LogLevelLogger) LogInfo

func (ll *LogLevelLogger) LogInfo(m ...interface{})

LogInfo adds a new info log message.

type Logger

type Logger interface {

	/*
	   LogError adds a new error log message.
	*/
	LogError(v ...interface{})

	/*
	   LogInfo adds a new info log message.
	*/
	LogInfo(v ...interface{})

	/*
	   LogDebug adds a new debug log message.
	*/
	LogDebug(v ...interface{})
}

Logger is required external object to which the interpreter releases its log messages.

type MemoryImportLocator

type MemoryImportLocator struct {
	Files map[string]string
}

MemoryImportLocator holds a given set of code in memory and can provide it as imports.

func (*MemoryImportLocator) Resolve

func (il *MemoryImportLocator) Resolve(path string) (string, error)

Resolve a given import path and parse the imported file into an AST.

type MemoryLogger

type MemoryLogger struct {
	*datautil.RingBuffer
}

MemoryLogger collects log messages in a RingBuffer in memory.

func NewMemoryLogger

func NewMemoryLogger(size int) *MemoryLogger

NewMemoryLogger returns a new memory logger instance.

func (*MemoryLogger) LogDebug

func (ml *MemoryLogger) LogDebug(m ...interface{})

LogDebug adds a new debug log message.

func (*MemoryLogger) LogError

func (ml *MemoryLogger) LogError(m ...interface{})

LogError adds a new error log message.

func (*MemoryLogger) LogInfo

func (ml *MemoryLogger) LogInfo(m ...interface{})

LogInfo adds a new info log message.

func (*MemoryLogger) Reset

func (ml *MemoryLogger) Reset()

Reset resets the current log.

func (*MemoryLogger) Size

func (ml *MemoryLogger) Size() int

Size returns the current log size.

func (*MemoryLogger) Slice

func (ml *MemoryLogger) Slice() []string

Slice returns the contents of the current log as a slice.

func (*MemoryLogger) String

func (ml *MemoryLogger) String() string

String returns the current log as a string.

type NullLogger

type NullLogger struct {
}

NullLogger discards log messages.

func NewNullLogger

func NewNullLogger() *NullLogger

NewNullLogger returns a null logger instance.

func (*NullLogger) LogDebug

func (nl *NullLogger) LogDebug(m ...interface{})

LogDebug adds a new debug log message.

func (*NullLogger) LogError

func (nl *NullLogger) LogError(m ...interface{})

LogError adds a new error log message.

func (*NullLogger) LogInfo

func (nl *NullLogger) LogInfo(m ...interface{})

LogInfo adds a new info log message.

type Processor

type Processor interface {
}

Processor models a top level execution instance for ECAL.

type RuntimeError

type RuntimeError struct {
	Source string            // Name of the source which was given to the parser
	Type   error             // Error type (to be used for equal checks)
	Detail string            // Details of this error
	Node   *parser.ASTNode   // AST Node where the error occurred
	Line   int               // Line of the error
	Pos    int               // Position of the error
	Trace  []*parser.ASTNode // Stacktrace
}

RuntimeError is a runtime related error.

func (*RuntimeError) AddTrace added in v1.0.0

func (re *RuntimeError) AddTrace(n *parser.ASTNode)

AddTrace adds a trace step.

func (*RuntimeError) Error

func (re *RuntimeError) Error() string

Error returns a human-readable string representation of this error.

func (*RuntimeError) GetTrace added in v1.0.0

func (re *RuntimeError) GetTrace() []*parser.ASTNode

GetTrace returns the current stacktrace.

func (*RuntimeError) GetTraceString added in v1.0.0

func (re *RuntimeError) GetTraceString() []string

GetTraceString returns the current stacktrace as a string.

func (*RuntimeError) MarshalJSON added in v1.0.0

func (re *RuntimeError) MarshalJSON() ([]byte, error)

MarshalJSON serializes this RuntimeError into a JSON string.

func (*RuntimeError) ToJSONObject added in v1.0.0

func (re *RuntimeError) ToJSONObject() map[string]interface{}

ToJSONObject returns this RuntimeError and all its children as a JSON object.

type RuntimeErrorWithDetail

type RuntimeErrorWithDetail struct {
	*RuntimeError
	Environment parser.Scope
	Data        interface{}
}

RuntimeErrorWithDetail is a runtime error with additional environment information.

func (*RuntimeErrorWithDetail) MarshalJSON added in v1.0.0

func (re *RuntimeErrorWithDetail) MarshalJSON() ([]byte, error)

MarshalJSON serializes this RuntimeErrorWithDetail into a JSON string.

func (*RuntimeErrorWithDetail) ToJSONObject added in v1.0.0

func (re *RuntimeErrorWithDetail) ToJSONObject() map[string]interface{}

ToJSONObject returns this RuntimeErrorWithDetail and all its children as a JSON object.

type StdOutLogger

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

StdOutLogger writes log messages to stdout.

func NewStdOutLogger

func NewStdOutLogger() *StdOutLogger

NewStdOutLogger returns a stdout logger instance.

func (*StdOutLogger) LogDebug

func (sl *StdOutLogger) LogDebug(m ...interface{})

LogDebug adds a new debug log message.

func (*StdOutLogger) LogError

func (sl *StdOutLogger) LogError(m ...interface{})

LogError adds a new error log message.

func (*StdOutLogger) LogInfo

func (sl *StdOutLogger) LogInfo(m ...interface{})

LogInfo adds a new info log message.

type TraceableRuntimeError added in v1.0.0

type TraceableRuntimeError interface {
	error

	/*
		AddTrace adds a trace step.
	*/
	AddTrace(*parser.ASTNode)

	/*
		GetTrace returns the current stacktrace.
	*/
	GetTrace() []*parser.ASTNode

	/*
		GetTrace returns the current stacktrace as a string.
	*/
	GetTraceString() []string
}

TraceableRuntimeError can record and show a stack trace.

Jump to

Keyboard shortcuts

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