Skip to content
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
4 changes: 2 additions & 2 deletions ast/ArgumentList.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
package ast

import (
"bytes"
"github.com/hyperjumptech/grule-rule-engine/ast/unique"
"reflect"
"strings"

"github.com/hyperjumptech/grule-rule-engine/pkg"
)
Expand Down Expand Up @@ -103,7 +103,7 @@ func (e *ArgumentList) GetGrlText() string {

// GetSnapshot will create a structure signature or AST graph
func (e *ArgumentList) GetSnapshot() string {
var buff bytes.Buffer
var buff strings.Builder
buff.WriteString(ARGUMENTLIST)
buff.WriteString("(")
for i, v := range e.Arguments {
Expand Down
4 changes: 2 additions & 2 deletions ast/ArrayMapSelector.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
package ast

import (
"bytes"
"fmt"
"github.com/hyperjumptech/grule-rule-engine/ast/unique"
"github.com/hyperjumptech/grule-rule-engine/pkg"
"reflect"
"strings"
)

// NewArrayMapSelector create a new array selector graph
Expand Down Expand Up @@ -106,7 +106,7 @@ func (e *ArrayMapSelector) GetGrlText() string {

// GetSnapshot will create a structure signature or AST graph
func (e *ArrayMapSelector) GetSnapshot() string {
var buff bytes.Buffer
var buff strings.Builder
buff.WriteString(MAPARRAYSELECTOR)
buff.WriteString("(")
if e.Expression != nil {
Expand Down
4 changes: 2 additions & 2 deletions ast/Assignment.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
package ast

import (
"bytes"
"errors"
"github.com/hyperjumptech/grule-rule-engine/ast/unique"
"github.com/hyperjumptech/grule-rule-engine/pkg"
"strings"
)

// NewAssignment will create new instance of Assignment AST Node
Expand Down Expand Up @@ -141,7 +141,7 @@ func (e *Assignment) GetGrlText() string {

// GetSnapshot will create a structure signature or AST graph
func (e *Assignment) GetSnapshot() string {
var buff bytes.Buffer
var buff strings.Builder
buff.WriteString(ASSIGMENT)
buff.WriteString("(")
buff.WriteString(e.Variable.GetSnapshot())
Expand Down
3 changes: 2 additions & 1 deletion ast/Constant.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"github.com/hyperjumptech/grule-rule-engine/ast/unique"
"math"
"reflect"
"strings"

"github.com/hyperjumptech/grule-rule-engine/pkg"
)
Expand Down Expand Up @@ -116,7 +117,7 @@ func (e *Constant) GetGrlText() string {

// GetSnapshot will create a structure signature or AST graph
func (e *Constant) GetSnapshot() string {
var buff bytes.Buffer
var buff strings.Builder
buff.WriteString(CONSTANT)
buff.WriteString("(")
buff.WriteString(e.Value.Kind().String())
Expand Down
4 changes: 2 additions & 2 deletions ast/Expression.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
package ast

import (
"bytes"
"errors"
"fmt"
"github.com/hyperjumptech/grule-rule-engine/ast/unique"
"reflect"
"strings"

"github.com/hyperjumptech/grule-rule-engine/pkg"
)
Expand Down Expand Up @@ -208,7 +208,7 @@ func (e *Expression) GetGrlText() string {

// GetSnapshot will create a structure signature or AST graph
func (e *Expression) GetSnapshot() string {
var buff bytes.Buffer
var buff strings.Builder
buff.WriteString(EXPRESSION)
buff.WriteString("(")
if e.SingleExpression != nil {
Expand Down
4 changes: 2 additions & 2 deletions ast/ExpressionAtom.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@
package ast

import (
"bytes"
"errors"
"fmt"
"github.com/hyperjumptech/grule-rule-engine/ast/unique"
"github.com/hyperjumptech/grule-rule-engine/model"
"reflect"
"strings"

"github.com/hyperjumptech/grule-rule-engine/pkg"
)
Expand Down Expand Up @@ -224,7 +224,7 @@ func (e *ExpressionAtom) GetGrlText() string {

// GetSnapshot will create a structure signature or AST graph
func (e *ExpressionAtom) GetSnapshot() string {
var buff bytes.Buffer
var buff strings.Builder
buff.WriteString(EXPRESSIONATOM)
buff.WriteString("(")
if e.Variable != nil {
Expand Down
4 changes: 2 additions & 2 deletions ast/FunctionCall.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
package ast

import (
"bytes"
"fmt"
"github.com/hyperjumptech/grule-rule-engine/ast/unique"
"github.com/hyperjumptech/grule-rule-engine/pkg"
"reflect"
"strings"
)

// NewFunctionCall creates new instance of FunctionCall
Expand Down Expand Up @@ -99,7 +99,7 @@ func (e *FunctionCall) GetGrlText() string {

// GetSnapshot will create a structure signature or AST graph
func (e *FunctionCall) GetSnapshot() string {
var buff bytes.Buffer
var buff strings.Builder
buff.WriteString(FUNCTIONCALL)
buff.WriteString(fmt.Sprintf("(n:%s", e.FunctionName))
if e.ArgumentList != nil {
Expand Down
11 changes: 5 additions & 6 deletions ast/KnowledgeBase.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
package ast

import (
"bytes"
"fmt"
"io"
"sort"
Expand Down Expand Up @@ -98,12 +97,12 @@ func (lib *KnowledgeLibrary) LoadKnowledgeBaseFromReader(reader io.Reader, overw
return nil, err
}
if overwrite {
lib.Library[GetKnowledgeBaseKey(knowledgeBase.Name,knowledgeBase.Version)] = knowledgeBase
lib.Library[GetKnowledgeBaseKey(knowledgeBase.Name, knowledgeBase.Version)] = knowledgeBase

return knowledgeBase, nil
}
if _, ok := lib.Library[GetKnowledgeBaseKey(knowledgeBase.Name,knowledgeBase.Version)]; !ok {
lib.Library[GetKnowledgeBaseKey(knowledgeBase.Name,knowledgeBase.Version)] = knowledgeBase
if _, ok := lib.Library[GetKnowledgeBaseKey(knowledgeBase.Name, knowledgeBase.Version)]; !ok {
lib.Library[GetKnowledgeBaseKey(knowledgeBase.Name, knowledgeBase.Version)] = knowledgeBase

return knowledgeBase, nil
}
Expand Down Expand Up @@ -194,7 +193,7 @@ func (e *KnowledgeBase) IsIdentical(that *KnowledgeBase) bool {

// GetSnapshot will create this knowledge base signature
func (e *KnowledgeBase) GetSnapshot() string {
var buffer bytes.Buffer
var buffer strings.Builder
buffer.WriteString(fmt.Sprintf("%s:%s[", e.Name, e.Version))
keys := make([]string, 0)
for i := range e.RuleEntries {
Expand Down Expand Up @@ -318,4 +317,4 @@ func (e *KnowledgeBase) Reset() {
// GetKnowledgeBaseKey returns the key corresponding to the knowledgeBase in the KnowledgeLibrary
func GetKnowledgeBaseKey(name, version string) string {
return fmt.Sprintf("%s:%s", name, version)
}
}
4 changes: 2 additions & 2 deletions ast/RuleEntry.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
package ast

import (
"bytes"
"context"
"fmt"
"github.com/hyperjumptech/grule-rule-engine/ast/unique"
"reflect"
"strings"

"github.com/hyperjumptech/grule-rule-engine/pkg"
)
Expand Down Expand Up @@ -148,7 +148,7 @@ func (e *RuleEntry) GetGrlText() string {

// GetSnapshot will create a structure signature or AST graph
func (e *RuleEntry) GetSnapshot() string {
var buff bytes.Buffer
var buff strings.Builder
buff.WriteString(RULEENTRY)
buff.WriteString("(")
buff.WriteString(fmt.Sprintf("N:%s DEC:\"%s\" SAL:%d W:%s T:%s}", e.RuleName, e.RuleDescription, e.Salience, e.WhenScope.GetSnapshot(), e.ThenScope.GetSnapshot()))
Expand Down
4 changes: 2 additions & 2 deletions ast/ThenExpression.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
package ast

import (
"bytes"
"github.com/hyperjumptech/grule-rule-engine/ast/unique"
"github.com/hyperjumptech/grule-rule-engine/pkg"
"strings"
)

// NewThenExpression create new instance of ThenExpression
Expand Down Expand Up @@ -121,7 +121,7 @@ func (e *ThenExpression) GetGrlText() string {

// GetSnapshot will create a structure signature or AST graph
func (e *ThenExpression) GetSnapshot() string {
var buff bytes.Buffer
var buff strings.Builder
buff.WriteString(THENEXPRESSION)
buff.WriteString("(")
if e.Assignment != nil {
Expand Down
4 changes: 2 additions & 2 deletions ast/ThenExpressionList.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
package ast

import (
"bytes"
"github.com/hyperjumptech/grule-rule-engine/ast/unique"
"github.com/hyperjumptech/grule-rule-engine/pkg"
"strings"
)

// NewThenExpressionList creates new instance of ThenExpressionList
Expand Down Expand Up @@ -109,7 +109,7 @@ func (e *ThenExpressionList) GetGrlText() string {

// GetSnapshot will create a structure signature or AST graph
func (e *ThenExpressionList) GetSnapshot() string {
var buff bytes.Buffer
var buff strings.Builder
buff.WriteString(THENEXPRESSIONLIST)
buff.WriteString("(")
if e.ThenExpressions != nil {
Expand Down
4 changes: 2 additions & 2 deletions ast/ThenScope.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
package ast

import (
"bytes"
"github.com/hyperjumptech/grule-rule-engine/ast/unique"
"github.com/hyperjumptech/grule-rule-engine/pkg"
"strings"
)

// NewThenScope will create new instance of ThenScope
Expand Down Expand Up @@ -99,7 +99,7 @@ func (e *ThenScope) GetGrlText() string {

// GetSnapshot will create a structure signature or AST graph
func (e *ThenScope) GetSnapshot() string {
var buff bytes.Buffer
var buff strings.Builder
buff.WriteString(THENSCOPE)
buff.WriteString("(")
if e.ThenExpressionList != nil {
Expand Down
4 changes: 2 additions & 2 deletions ast/Variable.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
package ast

import (
"bytes"
"fmt"
"github.com/hyperjumptech/grule-rule-engine/ast/unique"
"github.com/hyperjumptech/grule-rule-engine/model"
"reflect"
"strings"

"github.com/hyperjumptech/grule-rule-engine/pkg"
)
Expand Down Expand Up @@ -140,7 +140,7 @@ func (e *Variable) GetGrlText() string {

// GetSnapshot will create a structure signature or AST graph
func (e *Variable) GetSnapshot() string {
var buff bytes.Buffer
var buff strings.Builder
buff.WriteString(VARIABLE)
buff.WriteString("(")
if len(e.Name) > 0 && e.Variable == nil {
Expand Down
4 changes: 2 additions & 2 deletions ast/WhenScope.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
package ast

import (
"bytes"
"errors"
"github.com/hyperjumptech/grule-rule-engine/ast/unique"
"reflect"
"strings"

"github.com/hyperjumptech/grule-rule-engine/pkg"
)
Expand Down Expand Up @@ -106,7 +106,7 @@ func (e *WhenScope) GetGrlText() string {

// GetSnapshot will create a structure signature or AST graph
func (e *WhenScope) GetSnapshot() string {
var buff bytes.Buffer
var buff strings.Builder
buff.WriteString(WHENSCOPE)
buff.WriteString("(")
if e.Expression != nil {
Expand Down
Loading