Skip to content

Commit

Permalink
updated criteria
Browse files Browse the repository at this point in the history
  • Loading branch information
adranwit committed May 23, 2024
1 parent a4b32b4 commit 90e74f9
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 3 deletions.
15 changes: 15 additions & 0 deletions model/criteria/evaluator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,21 @@ func Test_EvaluateCriteria(t *testing.T) {
Expected: true,
},

{

Expression: "${httpTrips.Response[0].Body}://auctionwon/",
State: map[string]interface{}{
"httpTrips": map[string]interface{}{
"Response": []interface{}{
map[string]interface{}{
"Body": "http://asdasdasdas/",
},
},
},
},
Expected: false,
},

{
Description: "basic literal expr",
Expression: "on!=on", //
Expand Down
34 changes: 34 additions & 0 deletions model/criteria/matcher/terminator.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package matcher

import (
"github.com/viant/parsly"
)

type Terminator struct {
value byte
inclusive bool
}

func (t *Terminator) Match(cursor *parsly.Cursor) (matched int) {
hasMatch := false
matched++
offset := cursor.Pos + matched
for _, c := range cursor.Input[offset:] {
matched++
if hasMatch = c == t.value; hasMatch {
if !t.inclusive {
matched--
}
break
}
}
if !hasMatch {
return 0
}
return matched
}

// Terminator creates a terminator byte matcher
func NewTerminator(value byte, inclusive bool) *Terminator {
return &Terminator{value: value, inclusive: inclusive}
}
2 changes: 1 addition & 1 deletion model/criteria/parser/criteria.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ func expectOperand(cursor *parsly.Cursor, operands ...*parsly.Token) (ast.Node,
case parsly.EOF:
return nil, nil
case parsly.Invalid:
return nil, cursor.NewError(defaultsOperands...)
return nil, cursor.NewError(operands...)
default:
cursor.Pos = pos
return nil, nil
Expand Down
4 changes: 2 additions & 2 deletions model/criteria/parser/lex.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ var doubleQuotedStringLiteralMatcher = parsly.NewToken(doubleQuotedStringLiteral
var numericLiteralMatcher = parsly.NewToken(numericLiteral, `NUMERIC`, matcher.NewNumber())
var stringLiteralMatcher = parsly.NewToken(stringLiteral, `STRING`, smatcher.NewFragment())
var selectorMatcher = parsly.NewToken(selectorCode, "SELECTOR", smatcher.NewSelector())
var terminatorMatcher = parsly.NewToken(terminatorCode, "/", matcher.NewTerminator('/', false))
var terminatorMatcherInc = parsly.NewToken(terminatorCode, "/", matcher.NewTerminator('/', true))
var terminatorMatcher = parsly.NewToken(terminatorCode, "/", smatcher.NewTerminator('/', false))
var terminatorMatcherInc = parsly.NewToken(terminatorCode, "/", smatcher.NewTerminator('/', true))

var questionMarkMatcher = parsly.NewToken(questionMark, "?", matcher.NewByte('?'))
var colonMatcher = parsly.NewToken(colon, ":", matcher.NewByte(':'))

0 comments on commit 90e74f9

Please sign in to comment.