mirror of
https://github.com/dstotijn/hetty.git
synced 2025-07-01 18:47:29 -04:00
Add intercept module
This commit is contained in:
@ -3,6 +3,7 @@ package search
|
||||
import (
|
||||
"encoding/gob"
|
||||
"regexp"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
@ -50,13 +51,17 @@ type StringLiteral struct {
|
||||
}
|
||||
|
||||
func (sl StringLiteral) String() string {
|
||||
return sl.Value
|
||||
return strconv.Quote(sl.Value)
|
||||
}
|
||||
|
||||
type RegexpLiteral struct {
|
||||
*regexp.Regexp
|
||||
}
|
||||
|
||||
func (rl RegexpLiteral) String() string {
|
||||
return strconv.Quote(rl.Regexp.String())
|
||||
}
|
||||
|
||||
func (rl RegexpLiteral) MarshalBinary() ([]byte, error) {
|
||||
return []byte(rl.Regexp.String()), nil
|
||||
}
|
||||
|
@ -208,7 +208,7 @@ func parseInfixExpression(p *Parser, left Expression) (Expression, error) {
|
||||
return nil, fmt.Errorf("could not compile regular expression %q: %w", rightStr.Value, err)
|
||||
}
|
||||
|
||||
right = re
|
||||
right = RegexpLiteral{re}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -94,7 +94,7 @@ func TestParseQuery(t *testing.T) {
|
||||
expectedExpression: InfixExpression{
|
||||
Operator: TokOpRe,
|
||||
Left: StringLiteral{Value: "foo"},
|
||||
Right: regexp.MustCompile("bar"),
|
||||
Right: RegexpLiteral{regexp.MustCompile("bar")},
|
||||
},
|
||||
expectedError: nil,
|
||||
},
|
||||
@ -104,7 +104,7 @@ func TestParseQuery(t *testing.T) {
|
||||
expectedExpression: InfixExpression{
|
||||
Operator: TokOpNotRe,
|
||||
Left: StringLiteral{Value: "foo"},
|
||||
Right: regexp.MustCompile("bar"),
|
||||
Right: RegexpLiteral{regexp.MustCompile("bar")},
|
||||
},
|
||||
expectedError: nil,
|
||||
},
|
||||
@ -197,7 +197,7 @@ func TestParseQuery(t *testing.T) {
|
||||
Right: InfixExpression{
|
||||
Operator: TokOpRe,
|
||||
Left: StringLiteral{Value: "baz"},
|
||||
Right: regexp.MustCompile("yolo"),
|
||||
Right: RegexpLiteral{regexp.MustCompile("yolo")},
|
||||
},
|
||||
},
|
||||
expectedError: nil,
|
||||
|
Reference in New Issue
Block a user