Skip to content

Commit

Permalink
#12 Add tokenizer outline
Browse files Browse the repository at this point in the history
  • Loading branch information
thegodenage committed Mar 17, 2024
1 parent 62e2d43 commit 2f43450
Show file tree
Hide file tree
Showing 5 changed files with 150 additions and 37 deletions.
3 changes: 2 additions & 1 deletion .mockery.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ packages:
waffle/internal/rule:
interfaces:
Builder:
node:
Tokenizer:
node:
2 changes: 1 addition & 1 deletion internal/rule/compiler.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func (c *CustomCompiler) Compile(name, value string) (*Predicate, error) {
return nil, fmt.Errorf("validate name and value: %w", err)
}

variable, expression, err := getVariableAndLogicalExpression(strings.TrimSpace(value))
variable, expression, err := getVariableAndLogicalExpression(value)
if err != nil {
return nil, fmt.Errorf("get variable and logical expression for predicate: %w", err)
}
Expand Down
91 changes: 91 additions & 0 deletions internal/rule/mock_Tokenizer.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

35 changes: 0 additions & 35 deletions internal/rule/predicate.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,41 +4,6 @@ import (
"waffle/internal/request"
)

const (
operatorEq = "=="
operatorNotEq = "!="
operatorGt = ">"
operatorLs = "<"

methodLength = "LEN"
methodFormat = "FORMAT"

fieldPayload = "payload"
fieldHeaders = "headers"
)

var (
// operators are compilable operators.
operators = []string{
operatorEq,
operatorNotEq,
operatorGt,
operatorLs,
}

// methods are compilable methods.
methods = []string{
methodLength,
methodFormat,
}

// fields are compilable fields available in the request wrapper.
fields = []string{
fieldPayload,
fieldHeaders,
}
)

type Predicate struct {
Name string
Eval func(r *request.Wrapper) bool
Expand Down
56 changes: 56 additions & 0 deletions internal/rule/tokenizer.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package rule

const (
operatorEq = "=="
operatorNotEq = "!="
operatorGt = ">"
operatorLs = "<"

methodLength = "LEN"
methodFormat = "FORMAT"

fieldPayload = "payload"
fieldHeaders = "headers"
)

var (
// operators are compilable operators.
operators = []string{
operatorEq,
operatorNotEq,
operatorGt,
operatorLs,
}

// methods are compilable methods.
methods = []string{
methodLength,
methodFormat,
}

// fields are compilable fields available in the request wrapper.
fields = []string{
fieldPayload,
fieldHeaders,
}
)

type expressionTree node

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

type customRulesTokenizer struct {
}

var _ Tokenizer = (*customRulesTokenizer)(nil)

func newCustomRulesTokenizer() *customRulesTokenizer {
return &customRulesTokenizer{}
}

func (c *customRulesTokenizer) BuildExpressionTree(variable, expression string) (expressionTree, error) {
//TODO implement me
panic("implement me")
}

0 comments on commit 2f43450

Please sign in to comment.