operator

package
v0.0.0-...-9c09587 Latest Latest
Warning

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

Go to latest
Published: Jun 15, 2020 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// AssocLeft is the left associativity
	AssocLeft = 0
	// AssocRight is the right associativity
	AssocRight = 1
)

Variables

This section is empty.

Functions

func IsOperator

func IsOperator(literal string) bool

IsOperator checks if a given literal is associated with a registered operator and returns true is that is the case

Types

type ApplierFunc

type ApplierFunc func(...gjson.Result) gjson.Result

ApplierFunc represents the function that is performed by an operator, taking a variable number of inputs as gjson.Result and returning again a gjson.Result

type OperandTypeError

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

OperandTypeError is an error that indicates a wrong type of input variable given into an operation

This error is caused by the user of the library and shall therefore be passed up to the CLI

type Operator

type Operator struct {
	Identifier    string
	Sign          string
	Associativity int
	Precedence    int
	ArgTypes      []json.Type
	Apply         ApplierFunc
}

Operator is a function with the given name *Identifier*, that is performed on input values whenever *OperatorSign* is between them (infix). The input arguments of that function have to be of the types specified in *ArgTypes*. The precedence of the operator is defined in the corresponding attribute, with 1 being the lowest precedence (usually the select operator). The actual function is included in *Apply*.

The types of input arguments is checked before calling the function thus it can be assumed without further type checking that input arguments to the ApplierFunc are of the necessary types.

func GetOperator

func GetOperator(literal string) *Operator

GetOperator returns the operator for a given literal or nil if there is no registered operator with the given sign

Jump to

Keyboard shortcuts

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