interpreter

package
v0.0.0-...-d79ed59 Latest Latest
Warning

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

Go to latest
Published: Sep 9, 2022 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AST

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

type CompExpr

type CompExpr struct {
	Left  Expr
	Op    Token
	Right Expr
}

CompExpr is an expression like cpu < 23%

func (*CompExpr) Accept

func (c *CompExpr) Accept(a *AST) value

func (*CompExpr) String

func (c *CompExpr) String() string

type EvaluationError

type EvaluationError struct {
	// Source line/column position where the error occurred.
	Expr Expr
	// Error message.
	Message string
}

EvaluationError is the type of error returned by interpreter when evaluating errors.

func (*EvaluationError) Error

func (e *EvaluationError) Error() string

Error returns a formatted version of the error, including the line number.

type Expr

type Expr interface {
	String() string
	Accept(a *AST) value // visitor pattern
}

type GroupExpr

type GroupExpr struct {
	Expr Expr
}

GroupExpr is an expression like ( x == 2 )

func (*GroupExpr) Accept

func (l *GroupExpr) Accept(a *AST) value

func (*GroupExpr) String

func (g *GroupExpr) String() string

type Interpreter

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

func New

func New(expression string) (*Interpreter, error)

func (*Interpreter) Evaluate

func (i *Interpreter) Evaluate(variables map[string]interface{}) (result bool, err error)

evaluate evaluates the expression to bool.

type LiteralExpr

type LiteralExpr struct {
	Name string
}

LiteralExpr is an expression like 'cpu123'

func (*LiteralExpr) Accept

func (l *LiteralExpr) Accept(a *AST) value

Accept looks into AST variables map and return the numberic value of the variable or it panics.

func (*LiteralExpr) String

func (l *LiteralExpr) String() string

type LogicExpr

type LogicExpr struct {
	Left  Expr
	Op    Token
	Right Expr
}

LogicExpr is an expression like x > 0 && y == 1

func (*LogicExpr) Accept

func (l *LogicExpr) Accept(a *AST) value

func (*LogicExpr) String

func (l *LogicExpr) String() string

type NilExpr

type NilExpr struct{}

func (*NilExpr) Accept

func (n *NilExpr) Accept(a *AST) value

func (*NilExpr) String

func (n *NilExpr) String() string

type NumExpr

type NumExpr struct {
	Value float32
}

NumExpr is an expression like 1234.

func (*NumExpr) Accept

func (l *NumExpr) Accept(a *AST) value

func (*NumExpr) String

func (p *NumExpr) String() string

type ParseError

type ParseError struct {
	// Source line/column position where the error occurred.
	Position int
	// Error message.
	Message string
}

ParseError (actually *ParseError) is the type of error returned by parse.

func (*ParseError) Error

func (e *ParseError) Error() string

Error returns a formatted version of the error, including the line number.

type Token

type Token int
const (
	ILLEGAL Token = iota
	EOL

	// single character tokens
	LPAREN
	RPAREN
	PERCENT
	DEC

	// one or two character tokens
	AND
	EQUALS
	NOT_EQUALS
	DIV
	GTE
	GREATER
	LTE
	LESS
	OR

	// literals
	STRING
	NUMBER
	NIL
)

func (Token) String

func (t Token) String() string

type UnaryExpr

type UnaryExpr struct {
	Op    Token
	Right Expr
}

UnaryExpr

func (*UnaryExpr) Accept

func (u *UnaryExpr) Accept(a *AST) value

func (*UnaryExpr) String

func (u *UnaryExpr) String() string

type ValueExpr

type ValueExpr struct {
	Left  Expr
	Right Expr
}

ValueExpr is an expression like 100Gib

func (*ValueExpr) Accept

func (l *ValueExpr) Accept(a *AST) value

func (*ValueExpr) String

func (v *ValueExpr) String() string

Jump to

Keyboard shortcuts

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