Skip to content

Commit

Permalink
#12 🧹 clean code, code refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
thegodenage committed Mar 21, 2024
1 parent 4de53b6 commit 708fc4d
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 12 deletions.
35 changes: 24 additions & 11 deletions internal/rule/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,31 +28,44 @@ func (e *expressionTreeFactory) CreateExpressionTree(tokens []Token) (expression
nodes []node
tokenMatch []Token
)

for _, token := range tokens {
tokenMatch = append(tokenMatch, token)

for _, m := range matches {
if m.isMatching(tokenMatch) {
if isAdjustableNode(m.node) {
nd, err := e.nodeAdjuster.AdjustNode(m.node, tokenMatch)
if err != nil {
return nil, fmt.Errorf("adjust node %s: %w", reflect.TypeOf(m.node).Name(), err)
}

nodes = append(nodes, nd)

tokenMatch = []Token{}

continue
nd, err := e.adaptNode(m.node, tokenMatch)
if err != nil {
return nil, fmt.Errorf("adapt node: %w", err)
}

nodes = append(nodes, nd)

tokenMatch = []Token{}
}
}
}

for _, nd := range nodes {

Check failure on line 49 in internal/rule/factory.go

View workflow job for this annotation

GitHub Actions / build

nd declared and not used

}

return nil, nil
}

func (e *expressionTreeFactory) adaptNode(base node, tokenMatch []Token) (node, error) {
if !isAdjustableNode(base) {
return base, nil
}

nd, err := e.nodeAdjuster.AdjustNode(base, tokenMatch)
if err != nil {
return nil, fmt.Errorf("adjust node %s: %w", reflect.TypeOf(base).Name(), err)
}

return nd, nil
}

type match struct {
tokens []Token
node node
Expand Down
2 changes: 1 addition & 1 deletion internal/rule/tokenizer.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ func getFunction(match []rune) (string, bool) {
func isVariable(match []rune, variable string) bool {
strMatch := string(match)

return strMatch == fmt.Sprintf("%s", variable)
return strMatch == variable
}

func getSpecialCharacter(match []rune) (string, bool) {
Expand Down

0 comments on commit 708fc4d

Please sign in to comment.