diff --git a/go.mod b/go.mod index 2ed4b27..a95006f 100644 --- a/go.mod +++ b/go.mod @@ -12,7 +12,7 @@ require ( ) require ( - github.com/dlclark/regexp2 v1.10.0 // indirect + github.com/dlclark/regexp2 v1.11.0 // indirect github.com/inconshreveable/mousetrap v1.1.0 // indirect github.com/spf13/pflag v1.0.5 // indirect golang.org/x/net v0.21.0 // indirect diff --git a/go.sum b/go.sum index 391e83d..c319bb0 100644 --- a/go.sum +++ b/go.sum @@ -5,8 +5,8 @@ github.com/alecthomas/chroma/v2 v2.12.0/go.mod h1:4TQu7gdfuPjSh76j78ietmqh9LiurG github.com/alecthomas/repr v0.2.0 h1:HAzS41CIzNW5syS8Mf9UwXhNH1J9aix/BvDRf1Ml2Yk= github.com/alecthomas/repr v0.2.0/go.mod h1:Fr0507jx4eOXV7AlPV6AVZLYrLIuIeSOWtW57eE/O/4= github.com/cpuguy83/go-md2man/v2 v2.0.3/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= -github.com/dlclark/regexp2 v1.10.0 h1:+/GIL799phkJqYW+3YbOd8LCcbHzT0Pbo8zl70MHsq0= -github.com/dlclark/regexp2 v1.10.0/go.mod h1:DHkYz0B9wPfa6wondMfaivmHpzrQ3v9q8cnmRbL6yW8= +github.com/dlclark/regexp2 v1.11.0 h1:G/nrcoOa7ZXlpoa/91N3X7mM3r8eIlMBBJZvsz/mxKI= +github.com/dlclark/regexp2 v1.11.0/go.mod h1:DHkYz0B9wPfa6wondMfaivmHpzrQ3v9q8cnmRbL6yW8= github.com/hexops/gotextdiff v1.0.3 h1:gitA9+qJrrTCsiCl7+kh75nPqQt1cx4ZkudSTLoUqJM= github.com/hexops/gotextdiff v1.0.3/go.mod h1:pSWU5MAI3yDq+fZBTazCSJysOMbxWL1BSow5/V2vxeg= github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8= diff --git a/vendor/github.com/dlclark/regexp2/regexp.go b/vendor/github.com/dlclark/regexp2/regexp.go index c8f9e6b..a7ddbaf 100644 --- a/vendor/github.com/dlclark/regexp2/regexp.go +++ b/vendor/github.com/dlclark/regexp2/regexp.go @@ -18,8 +18,12 @@ import ( "github.com/dlclark/regexp2/syntax" ) -// Default timeout used when running regexp matches -- "forever" -var DefaultMatchTimeout = time.Duration(math.MaxInt64) +var ( + // DefaultMatchTimeout used when running regexp matches -- "forever" + DefaultMatchTimeout = time.Duration(math.MaxInt64) + // DefaultUnmarshalOptions used when unmarshaling a regex from text + DefaultUnmarshalOptions = None +) // Regexp is the representation of a compiled regular expression. // A Regexp is safe for concurrent use by multiple goroutines. @@ -43,7 +47,7 @@ type Regexp struct { code *syntax.Code // compiled program // cache of machines for running regexp - muRun sync.Mutex + muRun *sync.Mutex runner []*runner } @@ -72,6 +76,7 @@ func Compile(expr string, opt RegexOptions) (*Regexp, error) { capsize: code.Capsize, code: code, MatchTimeout: DefaultMatchTimeout, + muRun: &sync.Mutex{}, }, nil } @@ -371,3 +376,20 @@ func (re *Regexp) GroupNumberFromName(name string) int { return -1 } + +// MarshalText implements [encoding.TextMarshaler]. The output +// matches that of calling the [Regexp.String] method. +func (re *Regexp) MarshalText() ([]byte, error) { + return []byte(re.String()), nil +} + +// UnmarshalText implements [encoding.TextUnmarshaler] by calling +// [Compile] on the encoded value. +func (re *Regexp) UnmarshalText(text []byte) error { + newRE, err := Compile(string(text), DefaultUnmarshalOptions) + if err != nil { + return err + } + *re = *newRE + return nil +} diff --git a/vendor/modules.txt b/vendor/modules.txt index a1e8852..7d36b0b 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -4,7 +4,7 @@ github.com/alecthomas/chroma/v2 github.com/alecthomas/chroma/v2/formatters/html github.com/alecthomas/chroma/v2/lexers github.com/alecthomas/chroma/v2/styles -# github.com/dlclark/regexp2 v1.10.0 +# github.com/dlclark/regexp2 v1.11.0 ## explicit; go 1.13 github.com/dlclark/regexp2 github.com/dlclark/regexp2/syntax