evaluator

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Oct 15, 2025 License: MIT Imports: 18 Imported by: 0

Documentation

Overview

Package evaluator defines logic to evaluate an AST.

Index

Constants

View Source
const (
	// ErrMsgCouldNotEvaluateForStatement occurs when a for statement cannot be evaluated.
	ErrMsgCouldNotEvaluateForStatement = "could not evaluate for statement: %s"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Constant

type Constant struct {
	Value datavalue.Value
	Type  string
}

Constant defines a constant struct.

func (*Constant) GetType

func (c *Constant) GetType() string

GetType returns the constant's type.

func (*Constant) GetValue

func (c *Constant) GetValue() datavalue.Value

GetValue returns the value of the constant.

func (*Constant) IsConstant

func (c *Constant) IsConstant() bool

IsConstant just returns true.

type Evaluator

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

Evaluator defines the actual evaluator struct.

func NewEvaluator

func NewEvaluator(outFile io.Writer) *Evaluator

NewEvaluator creates a new evaluator.

func (*Evaluator) AddToBuffer added in v0.1.1

func (e *Evaluator) AddToBuffer(format string, args ...any)

AddToBuffer adds data to the buffer.

func (*Evaluator) Evaluate

func (e *Evaluator) Evaluate(
	currentAst ast.ExprNode,
) (*controlflow.EvaluationResult, error)

Evaluate runs the evaluation logic.

func (*Evaluator) Output

func (e *Evaluator) Output() string

Output returns the current output buffer contents.

func (*Evaluator) SetCurrentFilePath added in v0.1.1

func (e *Evaluator) SetCurrentFilePath(filePath string)

SetCurrentFilePath sets the current file path for import resolution.

func (*Evaluator) Terminate added in v0.1.1

func (e *Evaluator) Terminate(code byte)

Terminate stops the evaluator and exits with a given exit code.

type ScopedValue

type ScopedValue interface {
	GetValue() datavalue.Value
	GetType() string
	IsConstant() bool
}

ScopedValue defines an interface for scoped values.

type Variable

type Variable struct {
	Value datavalue.Value
	Type  string
}

Variable defines a variable struct.

func (*Variable) GetType

func (v *Variable) GetType() string

GetType returns the variable's type.

func (*Variable) GetValue

func (v *Variable) GetValue() datavalue.Value

GetValue returns the value of the variable.

func (*Variable) IsConstant

func (v *Variable) IsConstant() bool

IsConstant just returns false.

Jump to

Keyboard shortcuts

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