Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apply formatting (go fmt) #92

Merged
merged 1 commit into from
Feb 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 16 additions & 15 deletions evaluable.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ type Selector interface {
// Evaluable evaluates given parameter
type Evaluable func(c context.Context, parameter interface{}) (interface{}, error)

//EvalInt evaluates given parameter to an int
// EvalInt evaluates given parameter to an int
func (e Evaluable) EvalInt(c context.Context, parameter interface{}) (int, error) {
v, err := e(c, parameter)
if err != nil {
Expand All @@ -33,7 +33,7 @@ func (e Evaluable) EvalInt(c context.Context, parameter interface{}) (int, error
return int(f), nil
}

//EvalFloat64 evaluates given parameter to a float64
// EvalFloat64 evaluates given parameter to a float64
func (e Evaluable) EvalFloat64(c context.Context, parameter interface{}) (float64, error) {
v, err := e(c, parameter)
if err != nil {
Expand All @@ -47,7 +47,7 @@ func (e Evaluable) EvalFloat64(c context.Context, parameter interface{}) (float6
return f, nil
}

//EvalBool evaluates given parameter to a bool
// EvalBool evaluates given parameter to a bool
func (e Evaluable) EvalBool(c context.Context, parameter interface{}) (bool, error) {
v, err := e(c, parameter)
if err != nil {
Expand All @@ -61,7 +61,7 @@ func (e Evaluable) EvalBool(c context.Context, parameter interface{}) (bool, err
return b, nil
}

//EvalString evaluates given parameter to a string
// EvalString evaluates given parameter to a string
func (e Evaluable) EvalString(c context.Context, parameter interface{}) (string, error) {
o, err := e(c, parameter)
if err != nil {
Expand All @@ -70,7 +70,7 @@ func (e Evaluable) EvalString(c context.Context, parameter interface{}) (string,
return fmt.Sprintf("%v", o), nil
}

//Const Evaluable represents given constant
// Const Evaluable represents given constant
func (*Parser) Const(value interface{}) Evaluable {
return constant(value)
}
Expand All @@ -82,15 +82,16 @@ func constant(value interface{}) Evaluable {
}
}

//Var Evaluable represents value at given path.
//It supports with default language VariableSelector:
// map[interface{}]interface{},
// map[string]interface{} and
// []interface{} and via reflect
// struct fields,
// struct methods,
// slices and
// map with int or string key.
// Var Evaluable represents value at given path.
// It supports with default language VariableSelector:
//
// map[interface{}]interface{},
// map[string]interface{} and
// []interface{} and via reflect
// struct fields,
// struct methods,
// slices and
// map with int or string key.
func (p *Parser) Var(path ...Evaluable) Evaluable {
if p.selector == nil {
return variable(path)
Expand Down Expand Up @@ -276,7 +277,7 @@ func (*Parser) callEvaluable(fullname string, fun Evaluable, args ...Evaluable)
}
}

//IsConst returns if the Evaluable is a Parser.Const() value
// IsConst returns if the Evaluable is a Parser.Const() value
func (e Evaluable) IsConst() bool {
pc := reflect.ValueOf(constant(nil)).Pointer()
pe := reflect.ValueOf(e).Pointer()
Expand Down
13 changes: 7 additions & 6 deletions gval.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ import (
"github.com/shopspring/decimal"
)

//Evaluate given parameter with given expression in gval full language
// Evaluate given parameter with given expression in gval full language
func Evaluate(expression string, parameter interface{}, opts ...Language) (interface{}, error) {
return EvaluateWithContext(context.Background(), expression, parameter, opts...)
}

//Evaluate given parameter with given expression in gval full language using a context
// Evaluate given parameter with given expression in gval full language using a context
func EvaluateWithContext(c context.Context, expression string, parameter interface{}, opts ...Language) (interface{}, error) {
l := full
if len(opts) > 0 {
Expand All @@ -31,9 +31,10 @@ func EvaluateWithContext(c context.Context, expression string, parameter interfa
}

// Full is the union of Arithmetic, Bitmask, Text, PropositionalLogic, and Json
// Operator in: a in b is true iff value a is an element of array b
// Operator ??: a ?? b returns a if a is not false or nil, otherwise n
// Operator ?: a ? b : c returns b if bool a is true, otherwise b
//
// Operator in: a in b is true iff value a is an element of array b
// Operator ??: a ?? b returns a if a is not false or nil, otherwise n
// Operator ?: a ? b : c returns b if bool a is true, otherwise b
//
// Function Date: Date(a) parses string a. a must match RFC3339, ISO8601, ruby date, or unix date
func Full(extensions ...Language) Language {
Expand Down Expand Up @@ -106,7 +107,7 @@ func Ident() Language {
}

// Base contains equal (==) and not equal (!=), perentheses and general support for variables, constants and functions
// It contains true, false, (floating point) number, string ("" or ``) and char ('') constants
// It contains true, false, (floating point) number, string ("" or ) and char () constants
func Base() Language {
return base
}
Expand Down
2 changes: 1 addition & 1 deletion gval_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func testEvaluate(tests []evaluationTest, t *testing.T) {
}
}

//dummyParameter used to test "parameter calls".
// dummyParameter used to test "parameter calls".
type dummyParameter struct {
String string
Int int
Expand Down
2 changes: 1 addition & 1 deletion language.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ func PrefixMetaPrefix(r rune, ext func(context.Context, *Parser) (call string, a
return l
}

//PrefixOperator returns a Language with given prefix
// PrefixOperator returns a Language with given prefix
func PrefixOperator(name string, e Evaluable) Language {
l := newLanguage()
l.prefixes[l.makePrefixKey(name)] = func(c context.Context, p *Parser) (Evaluable, error) {
Expand Down
4 changes: 2 additions & 2 deletions parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"github.com/shopspring/decimal"
)

//ParseExpression scans an expression into an Evaluable.
// ParseExpression scans an expression into an Evaluable.
func (p *Parser) ParseExpression(c context.Context) (eval Evaluable, err error) {
stack := stageStack{}
for {
Expand All @@ -31,7 +31,7 @@ func (p *Parser) ParseExpression(c context.Context) (eval Evaluable, err error)
}
}

//ParseNextExpression scans the expression ignoring following operators
// ParseNextExpression scans the expression ignoring following operators
func (p *Parser) ParseNextExpression(c context.Context) (eval Evaluable, err error) {
scan := p.Scan()
ex, ok := p.prefixes[scan]
Expand Down
4 changes: 2 additions & 2 deletions parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"unicode"
)

//Parser parses expressions in a Language into an Evaluable
// Parser parses expressions in a Language into an Evaluable
type Parser struct {
scanner scanner.Scanner
Language
Expand Down Expand Up @@ -113,7 +113,7 @@ func (p *Parser) TokenText() string {
return p.scanner.TokenText()
}

//Expected returns an error signaling an unexpected Scan() result
// Expected returns an error signaling an unexpected Scan() result
func (p *Parser) Expected(unit string, expected ...rune) error {
return unexpectedRune{unit, expected, p.lastScan}
}
Expand Down