expr

package
Version: v0.0.0-...-c1c3c3c Latest Latest
Warning

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

Go to latest
Published: Nov 5, 2020 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package expr - ast.go has the following license: Copyright © 2016 Alan A. A. Donovan & Brian W. Kernighan. License: https://creativecommons.org/licenses/by-nc-sa/4.0/ Adapted by Yiping (Allison) Su

Package expr - eval.go has the following license: Copyright © 2016 Alan A. A. Donovan & Brian W. Kernighan. License: https://creativecommons.org/licenses/by-nc-sa/4.0/ Adapted by Yiping (Allison) Su

Package expr - parse.go has the following license: Copyright © 2016 Alan A. A. Donovan & Brian W. Kernighan. License: https://creativecommons.org/licenses/by-nc-sa/4.0/ Adapted by Yiping (Allison) Su

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ParseAndEval

func ParseAndEval(s string, env Env) (string, error)

ParseAndEval will return the evaluation of the string

Types

type Binary

type Binary struct {
	// Op represents a parsable operation (AND, OR)
	Op string

	// X, Y represent the left and right hand side values respectively
	X, Y Expr
}

Binary represents a SQL query expression

func (Binary) Eval

func (b Binary) Eval(env Env) string

Eval (Binary) evaluates binary part queries

e.g. (color = 'red') OR (color = 'green')

type Env

type Env map[string]string

Env represents the info of the query type

type Expr

type Expr interface {
	// Eval returns the evaluation of the expression
	Eval(env Env) string
}

Expr represents SQL expression statments

func Parse

func Parse(input string) (_ Expr, err error)

Parse parses the input string as a query expression.

expr = string                      a literal string, e.g. (hello)
     | '<' expr                    a unary operator (>, <, >=, <=)
     | expr 'AND/OR' expr          a binary operator (AND, OR)

type Literal

type Literal string

Literal represents the parameter string

func (Literal) Eval

func (l Literal) Eval(env Env) string

Eval (Literal) evaluates singular queries

i.e. the string itself

type Unary

type Unary struct {
	// Operator: <, >, <=, or >=
	Op string

	// Expression which evaluates to a literal
	//
	// e.g. 400
	X Expr
}

Unary represents a unary expression

e.g. sell:"< 400"

func (Unary) Eval

func (u Unary) Eval(env Env) string

Eval (Unary) evaluates unary part queries

e.g. sell < 3000

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL