Skip to content

Commit

Permalink
#12 Add changes to code tokenizer and expression tree code
Browse files Browse the repository at this point in the history
  • Loading branch information
thegodenage committed Mar 18, 2024
1 parent 2f43450 commit c6a83b4
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 102 deletions.
30 changes: 30 additions & 0 deletions internal/rule/expression_tree.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package rule

import "fmt"

type expressionTree node

type ExpressionTreeBuilder interface {
BuildExpressionTree(variable, expression string) (expressionTree, error)
}

type expressionTreeBuilder struct {
tokenizer Tokenizer
}

var _ ExpressionTreeBuilder = (*expressionTreeBuilder)(nil)

func newCustomRulesTokenizer() *expressionTreeBuilder {
return &expressionTreeBuilder{
tokenizer: &tokenizer{},
}
}

func (c *expressionTreeBuilder) BuildExpressionTree(variable, expression string) (expressionTree, error) {
tokens, err := c.tokenizer.BuildTokens(variable, expression)

Check failure on line 24 in internal/rule/expression_tree.go

View workflow job for this annotation

GitHub Actions / build

tokens declared and not used
if err != nil {
return nil, fmt.Errorf("build tokens: %w", err)
}

return nil, nil
}
91 changes: 0 additions & 91 deletions internal/rule/mock_Tokenizer.go

This file was deleted.

24 changes: 13 additions & 11 deletions internal/rule/tokenizer.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,15 @@ const (
operatorNotEq = "!="
operatorGt = ">"
operatorLs = "<"
operatorArrow = "=>"

methodLength = "LEN"
methodFormat = "FORMAT"

fieldPayload = "payload"
fieldHeaders = "headers"

tokenVariable = "variable"
)

var (
Expand All @@ -20,6 +23,7 @@ var (
operatorNotEq,
operatorGt,
operatorLs,
operatorArrow,
}

// methods are compilable methods.
Expand All @@ -35,22 +39,20 @@ var (
}
)

type expressionTree node

type Tokenizer interface {
BuildExpressionTree(variable, expression string) (expressionTree, error)
BuildTokens(variable, expression string) ([]Token, error)
}

type customRulesTokenizer struct {
type Token struct {
Name string
Value string
}

var _ Tokenizer = (*customRulesTokenizer)(nil)

func newCustomRulesTokenizer() *customRulesTokenizer {
return &customRulesTokenizer{}
type tokenizer struct {
}

func (c *customRulesTokenizer) BuildExpressionTree(variable, expression string) (expressionTree, error) {
//TODO implement me
panic("implement me")
func (t *tokenizer) BuildTokens(variable, expression string) ([]Token, error) {
for _, r := range []rune(expression) {

Check failure on line 55 in internal/rule/tokenizer.go

View workflow job for this annotation

GitHub Actions / build

r declared and not used

}
}

Check failure on line 58 in internal/rule/tokenizer.go

View workflow job for this annotation

GitHub Actions / build

missing return

0 comments on commit c6a83b4

Please sign in to comment.