Skip to content

Commit

Permalink
Fix naming
Browse files Browse the repository at this point in the history
  • Loading branch information
antonmedv committed Feb 18, 2024
1 parent 323873a commit 3196510
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
4 changes: 2 additions & 2 deletions expr.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ func AllowUndefinedVariables() Option {
// Operator allows to replace a binary operator with a function.
func Operator(operator string, fn ...string) Option {
return func(c *conf.Config) {
p := &patcher.OperatorOverride{
p := &patcher.OperatorOverloading{
Operator: operator,
Overrides: fn,
Overloads: fn,
Types: c.Types,
Functions: c.Functions,
}
Expand Down
26 changes: 13 additions & 13 deletions patcher/operator_override.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ import (
"github.com/expr-lang/expr/conf"
)

type OperatorOverride struct {
Operator string // Operator token to override.
Overrides []string // List of function names to override operator with.
type OperatorOverloading struct {
Operator string // Operator token to overload.
Overloads []string // List of function names to replace operator with.
Types conf.TypesTable // Env types.
Functions conf.FunctionsTable // Env functions.
applied bool // Flag to indicate if any override was applied.
applied bool // Flag to indicate if any changes were made to the tree.
}

func (p *OperatorOverride) Visit(node *ast.Node) {
func (p *OperatorOverloading) Visit(node *ast.Node) {
binaryNode, ok := (*node).(*ast.BinaryNode)
if !ok {
return
Expand All @@ -42,20 +42,20 @@ func (p *OperatorOverride) Visit(node *ast.Node) {
}
}

func (p *OperatorOverride) ShouldRepeat() bool {
func (p *OperatorOverloading) ShouldRepeat() bool {
return p.applied
}

func (p *OperatorOverride) FindSuitableOperatorOverload(l, r reflect.Type) (reflect.Type, string, bool) {
func (p *OperatorOverloading) FindSuitableOperatorOverload(l, r reflect.Type) (reflect.Type, string, bool) {
t, fn, ok := p.findSuitableOperatorOverloadInFunctions(l, r)
if !ok {
t, fn, ok = p.findSuitableOperatorOverloadInTypes(l, r)
}
return t, fn, ok
}

func (p *OperatorOverride) findSuitableOperatorOverloadInTypes(l, r reflect.Type) (reflect.Type, string, bool) {
for _, fn := range p.Overrides {
func (p *OperatorOverloading) findSuitableOperatorOverloadInTypes(l, r reflect.Type) (reflect.Type, string, bool) {
for _, fn := range p.Overloads {
fnType, ok := p.Types[fn]
if !ok {
continue
Expand All @@ -72,8 +72,8 @@ func (p *OperatorOverride) findSuitableOperatorOverloadInTypes(l, r reflect.Type
return nil, "", false
}

func (p *OperatorOverride) findSuitableOperatorOverloadInFunctions(l, r reflect.Type) (reflect.Type, string, bool) {
for _, fn := range p.Overrides {
func (p *OperatorOverloading) findSuitableOperatorOverloadInFunctions(l, r reflect.Type) (reflect.Type, string, bool) {
for _, fn := range p.Overloads {
fnType, ok := p.Functions[fn]
if !ok {
continue
Expand Down Expand Up @@ -101,8 +101,8 @@ func checkTypeSuits(t reflect.Type, l reflect.Type, r reflect.Type, firstInIndex
return nil, false
}

func (p *OperatorOverride) Check() {
for _, fn := range p.Overrides {
func (p *OperatorOverloading) Check() {
for _, fn := range p.Overloads {
fnType, foundType := p.Types[fn]
fnFunc, foundFunc := p.Functions[fn]
if !foundFunc && (!foundType || fnType.Type.Kind() != reflect.Func) {
Expand Down

0 comments on commit 3196510

Please sign in to comment.