expression

package
v0.0.8 Latest Latest
Warning

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

Go to latest
Published: Feb 12, 2024 License: MIT Imports: 8 Imported by: 0

README

Socks embedded expression language

Operators

Arithmetic
  • + Addition
  • - Subtraction
  • * Multiplication
  • / Division
  • % Modulo
  • ** Exponentiation
  • // Floor division
Comparison
  • == Equal
  • != Not equal
  • > Greater than
  • >= Greater than or equal
  • < Less than
  • <= Less than or equal
Logical
  • and Logical and
  • or Logical or
  • not Negation
Sets
  • [...] Array (always constant)
  • a in A Is element a present in A? (a ∈ A)
  • a not in A Is element a not present in A? (a ∉ A)

Documentation

Index

Constants

View Source
const (
	OpConstant = iota
	OpEqual
	OpNotEqual
	OpGreaterThan
	OpGreaterThanOrEqual
	OpLessThan
	OpLessThanOrEqual
	OpAdd
	OpSubtract
	OpMultiply
	OpDivide
	OpExponent
	OpAnd
	OpOr
	OpNot
	OpNegate
	OpGet
	OpCall
	OpBuiltin1
	OpBuiltin2
	OpBuiltin3
	OpArrayAccess
	OpChain
	OpArray
	OpIn
	OpCodeCount
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Array

type Array struct {
	Items []Expression
	Token *tokenizer.Token
}

func (*Array) IsEqual

func (s *Array) IsEqual(node Node) bool

func (*Array) Literal

func (s *Array) Literal() string

func (*Array) String

func (s *Array) String() string

func (*Array) Type

func (s *Array) Type() string

type ArrayAccess

type ArrayAccess struct {
	Accessed Expression
	Index    Expression
	Token    *tokenizer.Token
}

func (*ArrayAccess) IsEqual

func (s *ArrayAccess) IsEqual(node Node) bool

func (*ArrayAccess) Literal

func (s *ArrayAccess) Literal() string

func (*ArrayAccess) String

func (s *ArrayAccess) String() string

func (*ArrayAccess) Type

func (s *ArrayAccess) Type() string

type Boolean

type Boolean struct {
	Value bool
	Token *tokenizer.Token
}

func (*Boolean) IsEqual

func (s *Boolean) IsEqual(node Node) bool

func (*Boolean) Literal

func (s *Boolean) Literal() string

func (*Boolean) String

func (s *Boolean) String() string

func (*Boolean) Type

func (s *Boolean) Type() string

type Builtin

type Builtin struct {
	Name  string
	Token *tokenizer.Token
	Args  []Expression
}

func (*Builtin) IsEqual

func (s *Builtin) IsEqual(node Node) bool

func (*Builtin) Literal

func (s *Builtin) Literal() string

func (*Builtin) String

func (s *Builtin) String() string

func (*Builtin) Type

func (s *Builtin) Type() string

type Chunk

type Chunk struct {
	Instructions []int
	Constants    []any
}

func (*Chunk) String

func (c *Chunk) String() string

type Compiler

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

func NewCompiler

func NewCompiler(expr Expression) *Compiler

func (*Compiler) Compile

func (c *Compiler) Compile() (Chunk, error)

type Expression

type Expression interface {
	Node
	Type() string
}

type FunctionCall

type FunctionCall struct {
	Called Expression
	Args   []Expression
	Token  *tokenizer.Token
}

func (*FunctionCall) IsEqual

func (s *FunctionCall) IsEqual(node Node) bool

func (*FunctionCall) Literal

func (s *FunctionCall) Literal() string

func (*FunctionCall) String

func (s *FunctionCall) String() string

func (*FunctionCall) Type

func (s *FunctionCall) Type() string

type Identifier

type Identifier struct {
	Value string
	Token *tokenizer.Token
}

func (*Identifier) IsEqual

func (s *Identifier) IsEqual(node Node) bool

func (*Identifier) Literal

func (s *Identifier) Literal() string

func (*Identifier) String

func (s *Identifier) String() string

func (*Identifier) Type

func (s *Identifier) Type() string

type InfixExpression

type InfixExpression struct {
	Token *tokenizer.Token
	Op    string

	Left  Expression
	Right Expression
}

func (*InfixExpression) IsEqual

func (s *InfixExpression) IsEqual(node Node) bool

func (*InfixExpression) Literal

func (s *InfixExpression) Literal() string

func (*InfixExpression) String

func (s *InfixExpression) String() string

func (*InfixExpression) Type

func (s *InfixExpression) Type() string

type Integer

type Integer struct {
	Value int
	Token *tokenizer.Token
}

func (*Integer) IsEqual

func (s *Integer) IsEqual(node Node) bool

func (*Integer) Literal

func (s *Integer) Literal() string

func (*Integer) String

func (s *Integer) String() string

func (*Integer) Type

func (s *Integer) Type() string

type Node

type Node interface {
	Literal() string
	IsEqual(Node) bool
	String() string
}

type Numeric

type Numeric struct {
	Value float64
	Token *tokenizer.Token
}

func (*Numeric) IsEqual

func (s *Numeric) IsEqual(node Node) bool

func (*Numeric) Literal

func (s *Numeric) Literal() string

func (*Numeric) String

func (s *Numeric) String() string

func (*Numeric) Type

func (s *Numeric) Type() string

type Precedence

type Precedence int
const (
	PrecLowest Precedence
	PrecOr
	PrecAnd
	PrecEqual
	PrecLessGreater
	PrecInclusion
	PrecSets
	PrecInfix
	PrecMultiply
	PrecPower
	PrecPrefix
	PrecCall
	PrecChain
)

type PrefixExpression

type PrefixExpression struct {
	Token  *tokenizer.Token
	Op     string
	Action string

	Right Expression
}

func (*PrefixExpression) IsEqual

func (s *PrefixExpression) IsEqual(node Node) bool

func (*PrefixExpression) Literal

func (s *PrefixExpression) Literal() string

func (*PrefixExpression) String

func (s *PrefixExpression) String() string

func (*PrefixExpression) Type

func (s *PrefixExpression) Type() string

type Range

type Range struct {
	Start Expression
	End   Expression
	Token *tokenizer.Token
}

func (*Range) IsEqual

func (s *Range) IsEqual(node Node) bool

func (*Range) Literal

func (s *Range) Literal() string

func (*Range) String

func (s *Range) String() string

func (*Range) Type

func (s *Range) Type() string

type Stack

type Stack []any

type StringLiteral

type StringLiteral struct {
	Value string
	Token *tokenizer.Token
}

func (*StringLiteral) IsEqual

func (s *StringLiteral) IsEqual(node Node) bool

func (*StringLiteral) Literal

func (s *StringLiteral) Literal() string

func (*StringLiteral) String

func (s *StringLiteral) String() string

func (*StringLiteral) Type

func (s *StringLiteral) Type() string

type VM

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

func NewVM

func NewVM(chunk Chunk) *VM

func (*VM) Run

func (vm *VM) Run(env map[string]any) (any, error)

type VariableAccess

type VariableAccess struct {
	Token      *tokenizer.Token
	Left       Expression
	IsOptional bool
	Right      Expression
}

func (*VariableAccess) IsEqual

func (s *VariableAccess) IsEqual(node Node) bool

func (*VariableAccess) Literal

func (s *VariableAccess) Literal() string

func (*VariableAccess) String

func (s *VariableAccess) String() string

func (*VariableAccess) Type

func (s *VariableAccess) Type() string

type WrappedExpression added in v0.0.8

type WrappedExpression struct {
	Expr           Expression
	RequiredIdents []string
}

func Parse

func Parse(tokens []tokenizer.Token) (*WrappedExpression, error)

Jump to

Keyboard shortcuts

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