colexpr

package module
v0.0.0-...-4f55e0d Latest Latest
Warning

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

Go to latest
Published: Feb 17, 2022 License: MIT Imports: 3 Imported by: 0

README

colexpr

created by Austin Poor

A Go library for parsing simple expressions to generate column definitions.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNoOpPassed      = errors.New("no operator passed")
	ErrTooManyOps      = errors.New("too many operators passed")
	ErrLeftNotInt      = errors.New("left value is not an int")
	ErrRightNotInt     = errors.New("right value is not an int")
	ErrUnknownOperator = errors.New("unknown operator")
)

Functions

This section is empty.

Types

type Expr

type Expr struct {
	Left  *Value    `parse:"@@"`
	Op    *Operator `parse:"@( \"*\" | \"/\" | \"+\" | \"-\" )"`
	Right *Value    `parse:"@@"`
}

func (*Expr) Evaluate

func (e *Expr) Evaluate() (interface{}, error)

func (*Expr) EvaluateFloat

func (e *Expr) EvaluateFloat() float64

func (*Expr) EvaluateInt

func (e *Expr) EvaluateInt() (int, error)

type Operator

type Operator int
const (
	OpMul Operator = iota
	OpDiv
	OpAdd
	OpSub
)

func (*Operator) Capture

func (o *Operator) Capture(s []string) error

type Parser

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

func NewParser

func NewParser() *Parser

func (*Parser) ParseExpression

func (p *Parser) ParseExpression(s string) (*Expr, error)

type Value

type Value struct {
	Integer *int     `parse:"  @Int"`
	Float   *float64 `parse:"| @Float"`
}

Jump to

Keyboard shortcuts

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