Skip to content

Commit 6e87b3e

Browse files
committed
chore: drop our regexp2 fork
Signed-off-by: Joseph Kato <joseph@jdkato.io>
1 parent f7d2f10 commit 6e87b3e

17 files changed

Lines changed: 304 additions & 87 deletions

go.mod

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ require (
99
github.com/adrg/xdg v0.5.3
1010
github.com/bmatcuk/doublestar/v4 v4.7.1
1111
github.com/d5/tengo/v2 v2.17.0
12+
github.com/dlclark/regexp2/v2 v2.5.2
1213
github.com/errata-ai/ini v1.63.0
13-
github.com/errata-ai/regexp2 v1.7.0
1414
github.com/expr-lang/expr v1.17.7
1515
github.com/gobwas/glob v0.2.3
1616
github.com/jdkato/go-tree-sitter-julia v0.1.0
@@ -44,7 +44,6 @@ require (
4444
github.com/cespare/xxhash/v2 v2.3.0 // indirect
4545
github.com/clipperhouse/displaywidth v0.10.0 // indirect
4646
github.com/clipperhouse/uax29/v2 v2.6.0 // indirect
47-
github.com/dlclark/regexp2/v2 v2.5.2 // indirect
4847
github.com/fatih/color v1.18.0 // indirect
4948
github.com/google/uuid v1.6.0 // indirect
5049
github.com/gookit/color v1.5.4 // indirect

go.sum

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,6 @@ github.com/dlclark/regexp2/v2 v2.5.2 h1:HAsucWRhsqcDzl6Ua9aR8JwYOTzrZyPrF0/FNxJV
4141
github.com/dlclark/regexp2/v2 v2.5.2/go.mod h1:avUrQvPaLz2DrFNHJF0taWAFFX2C1GMSSoeiqFjcBmU=
4242
github.com/errata-ai/ini v1.63.0 h1:XRFKXTn7FvF8mnC9RPOlYaL4Ud7dP0i35LnLcbIhWYU=
4343
github.com/errata-ai/ini v1.63.0/go.mod h1:PhjYff6ijif0unCnaJtXxnVsmlY95CSiNJDLXQYXdX8=
44-
github.com/errata-ai/regexp2 v1.7.0 h1:N+weOlhwTd5iyDTcTCAMljXnfzkftcOZrdXno6G+QPM=
45-
github.com/errata-ai/regexp2 v1.7.0/go.mod h1:59rO+jaxayJPF1WKI5m9R5F3Y3zR2Wn0DHnQbxtPm4A=
4644
github.com/expr-lang/expr v1.17.7 h1:Q0xY/e/2aCIp8g9s/LGvMDCC5PxYlvHgDZRQ4y16JX8=
4745
github.com/expr-lang/expr v1.17.7/go.mod h1:8/vRC7+7HBzESEqt5kKpYXxrxkr31SaO8r40VO/1IT4=
4846
github.com/fatih/color v1.18.0 h1:S8gINlzdQ840/4pfAwic/ZE0djQEH3wM94VfqLTZcOM=

internal/check/capitalization.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package check
22

33
import (
4-
"github.com/errata-ai/regexp2"
4+
rx "github.com/errata-ai/vale/v3/internal/regex"
55
"github.com/jdkato/prose/v3/strcase"
66

77
"github.com/errata-ai/vale/v3/internal/core"
@@ -13,7 +13,7 @@ type Capitalization struct {
1313
Definition `mapstructure:",squash"`
1414
// `match` (`string`): $title, $sentence, $lower, $upper, or a pattern.
1515
Match string
16-
Check func(s string, re *regexp2.Regexp) (string, bool)
16+
Check func(s string, re *rx.Regexp) (string, bool)
1717
// `style` (`string`): AP or Chicago; only applies when match is set to
1818
// $title.
1919
Style string
@@ -32,7 +32,7 @@ type Capitalization struct {
3232
// capitalization.
3333
Prefix string
3434

35-
exceptRe *regexp2.Regexp
35+
exceptRe *rx.Regexp
3636
}
3737

3838
// NewCapitalization creates a new `capitalization`-based rule.
@@ -84,7 +84,7 @@ func NewCapitalization(cfg *core.Config, generic baseCheck, path string) (Capita
8484
strcase.UsingPrefix(rule.Prefix),
8585
)
8686
}
87-
rule.Check = func(s string, re *regexp2.Regexp) (string, bool) {
87+
rule.Check = func(s string, re *rx.Regexp) (string, bool) {
8888
return title(s, re, tc, rule.Threshold)
8989
}
9090
} else if rule.Match == "$sentence" {
@@ -93,17 +93,17 @@ func NewCapitalization(cfg *core.Config, generic baseCheck, path string) (Capita
9393
strcase.UsingPrefix(rule.Prefix),
9494
strcase.UsingIndicator(wasIndicator(rule.Indicators)),
9595
)
96-
rule.Check = func(s string, re *regexp2.Regexp) (string, bool) {
96+
rule.Check = func(s string, re *rx.Regexp) (string, bool) {
9797
return sentence(s, re, sc, rule.Threshold)
9898
}
9999
} else if f, ok := varToFunc[rule.Match]; ok {
100100
rule.Check = f
101101
} else {
102-
re2, errc := regexp2.CompileStd(rule.Match)
102+
re2, errc := rx.Compile(rule.Match)
103103
if errc != nil {
104104
return rule, core.NewE201FromPosition(errc.Error(), path, 1)
105105
}
106-
rule.Check = func(s string, r *regexp2.Regexp) (string, bool) {
106+
rule.Check = func(s string, r *rx.Regexp) (string, bool) {
107107
return re2.String(), re2.MatchStringStd(s) || isMatch(r, s)
108108
}
109109
}

internal/check/conditional.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package check
33
import (
44
"strings"
55

6-
"github.com/errata-ai/regexp2"
6+
rx "github.com/errata-ai/vale/v3/internal/regex"
77

88
"github.com/errata-ai/vale/v3/internal/core"
99
"github.com/errata-ai/vale/v3/internal/nlp"
@@ -13,11 +13,11 @@ import (
1313
type Conditional struct {
1414
Definition `mapstructure:",squash"`
1515
Exceptions []string
16-
patterns []*regexp2.Regexp
16+
patterns []*rx.Regexp
1717
First string
1818
Second string
19-
exceptRe *regexp2.Regexp
20-
phraseRe *regexp2.Regexp
19+
exceptRe *rx.Regexp
20+
phraseRe *rx.Regexp
2121
Ignorecase bool
2222
Vocab bool
2323

@@ -39,7 +39,7 @@ func hasCaptureGroup(pattern string) bool {
3939

4040
// NewConditional creates a new `conditional`-based rule.
4141
func NewConditional(cfg *core.Config, generic baseCheck, path string) (Conditional, error) {
42-
var expression []*regexp2.Regexp
42+
var expression []*rx.Regexp
4343
rule := Conditional{Vocab: true}
4444

4545
err := decodeRule(generic, &rule)
@@ -59,14 +59,14 @@ func NewConditional(cfg *core.Config, generic baseCheck, path string) (Condition
5959
rule.exceptRe = re
6060
rule.phraseRe = buildPhraseRe(rule.Exceptions, cfg.AcceptedTokens, rule.Vocab)
6161

62-
re, err = regexp2.CompileStd(rule.Second)
62+
re, err = rx.Compile(rule.Second)
6363
if err != nil {
6464
return rule, core.NewE201FromPosition(err.Error(), path, 1)
6565
}
6666
expression = append(expression, re)
6767
rule.secondHasGroup = hasCaptureGroup(rule.Second)
6868

69-
re, err = regexp2.CompileStd(rule.First)
69+
re, err = rx.Compile(rule.First)
7070
if err != nil {
7171
return rule, core.NewE201FromPosition(err.Error(), path, 1)
7272
}

internal/check/consistency.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@ import (
44
"fmt"
55
"strings"
66

7-
"github.com/errata-ai/regexp2"
7+
rx "github.com/errata-ai/vale/v3/internal/regex"
88
"github.com/mitchellh/mapstructure"
99

1010
"github.com/errata-ai/vale/v3/internal/core"
1111
"github.com/errata-ai/vale/v3/internal/nlp"
1212
)
1313

1414
type step struct {
15-
pattern *regexp2.Regexp
15+
pattern *rx.Regexp
1616
subs []string
1717
}
1818

@@ -64,7 +64,7 @@ func NewConsistency(cfg *core.Config, generic baseCheck, path string) (Consisten
6464
chkRE = fmt.Sprintf("(?P<%s>%s)|(?P<%s>%s)", subs[0], v1, subs[1], v2)
6565
chkRE = fmt.Sprintf(regex, chkRE)
6666

67-
re, errc := regexp2.CompileStd(chkRE)
67+
re, errc := rx.Compile(chkRE)
6868
if errc != nil {
6969
return rule, core.NewE201FromPosition(errc.Error(), path, 1)
7070
}

internal/check/definition.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77
"strconv"
88
"strings"
99

10-
"github.com/errata-ai/regexp2"
10+
rx "github.com/errata-ai/vale/v3/internal/regex"
1111
"github.com/mitchellh/mapstructure"
1212
"gopkg.in/yaml.v3"
1313

@@ -334,14 +334,14 @@ func matchToken(expected, observed string, ignorecase bool) bool {
334334
p = ignoreCase + p
335335
}
336336

337-
r, err := regexp2.CompileStd(fmt.Sprintf(tokenTemplate, p))
337+
r, err := rx.Compile(fmt.Sprintf(tokenTemplate, p))
338338
if core.IsPhrase(expected) || err != nil {
339339
return expected == observed
340340
}
341341
return r.MatchStringStd(observed)
342342
}
343343

344-
func updateExceptions(previous []string, current []string, vocab bool) (*regexp2.Regexp, error) {
344+
func updateExceptions(previous []string, current []string, vocab bool) (*rx.Regexp, error) {
345345
if vocab {
346346
previous = append(previous, current...)
347347
}
@@ -369,10 +369,10 @@ func updateExceptions(previous []string, current []string, vocab bool) (*regexp2
369369

370370
regex = fmt.Sprintf(regex, strings.Join(previous, "|"))
371371
if len(previous) > 0 {
372-
return regexp2.CompileStd(regex)
372+
return rx.Compile(regex)
373373
}
374374

375-
return &regexp2.Regexp{}, nil
375+
return &rx.Regexp{}, nil
376376
}
377377

378378
// buildPhraseRe compiles a regex matching the multi-word entries among the
@@ -383,7 +383,7 @@ func updateExceptions(previous []string, current []string, vocab bool) (*regexp2
383383
//
384384
// Returns nil when there are no multi-word terms (or one fails to compile, in
385385
// which case `updateExceptions` surfaces the error).
386-
func buildPhraseRe(previous, current []string, vocab bool) *regexp2.Regexp {
386+
func buildPhraseRe(previous, current []string, vocab bool) *rx.Regexp {
387387
terms := append([]string{}, previous...)
388388
if vocab {
389389
terms = append(terms, current...)
@@ -400,7 +400,7 @@ func buildPhraseRe(previous, current []string, vocab bool) *regexp2.Regexp {
400400
return nil
401401
}
402402

403-
re, err := regexp2.CompileStd(ignoreCase + `\b(?:` + strings.Join(phrases, "|") + `)\b`)
403+
re, err := rx.Compile(ignoreCase + `\b(?:` + strings.Join(phrases, "|") + `)\b`)
404404
if err != nil {
405405
return nil
406406
}
@@ -410,7 +410,7 @@ func buildPhraseRe(previous, current []string, vocab bool) *regexp2.Regexp {
410410
// withinPhrase reports whether the span `loc` falls entirely within a match of
411411
// `phraseRe` (an accepted multi-word phrase) in `txt`. Both `loc` and the
412412
// phrase spans are rune offsets, as returned by regexp2's FindAllStringIndex.
413-
func withinPhrase(phraseRe *regexp2.Regexp, txt string, loc []int) bool {
413+
func withinPhrase(phraseRe *rx.Regexp, txt string, loc []int) bool {
414414
if phraseRe == nil {
415415
return false
416416
}

internal/check/existence.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import (
44
"fmt"
55
"strings"
66

7-
"github.com/errata-ai/regexp2"
7+
rx "github.com/errata-ai/vale/v3/internal/regex"
88

99
"github.com/errata-ai/vale/v3/internal/core"
1010
"github.com/errata-ai/vale/v3/internal/nlp"
@@ -17,9 +17,9 @@ type Existence struct {
1717
Tokens []string
1818
// `exceptions` (`array`): An array of strings to be ignored.
1919
Exceptions []string
20-
exceptRe *regexp2.Regexp
21-
phraseRe *regexp2.Regexp
22-
pattern *regexp2.Regexp
20+
exceptRe *rx.Regexp
21+
phraseRe *rx.Regexp
22+
pattern *rx.Regexp
2323
Append bool
2424
IgnoreCase bool
2525
Nonword bool
@@ -68,7 +68,7 @@ func NewExistence(cfg *core.Config, generic baseCheck, path string) (Existence,
6868
}
6969
regex = fmt.Sprintf(regex, strings.Join(parsed, "|"))
7070

71-
re, err = regexp2.CompileStd(regex)
71+
re, err = rx.Compile(regex)
7272
if err != nil {
7373
return rule, core.NewE201FromPosition(err.Error(), path, 1)
7474
}

internal/check/occurrence.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package check
33
import (
44
"strings"
55

6-
"github.com/errata-ai/regexp2"
6+
rx "github.com/errata-ai/vale/v3/internal/regex"
77

88
"github.com/errata-ai/vale/v3/internal/core"
99
"github.com/errata-ai/vale/v3/internal/nlp"
@@ -15,7 +15,7 @@ type Occurrence struct {
1515
Token string
1616
Max int
1717
Min int
18-
pattern *regexp2.Regexp
18+
pattern *rx.Regexp
1919
Ignorecase bool
2020
}
2121

@@ -39,7 +39,7 @@ func NewOccurrence(_ *core.Config, generic baseCheck, path string) (Occurrence,
3939
}
4040

4141
regex += `(?:` + rule.Token + `)`
42-
re, err := regexp2.CompileStd(regex)
42+
re, err := rx.Compile(regex)
4343
if err != nil {
4444
return rule, core.NewE201FromPosition(err.Error(), path, 1)
4545
}

internal/check/repetition.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package check
33
import (
44
"strings"
55

6-
"github.com/errata-ai/regexp2"
6+
rx "github.com/errata-ai/vale/v3/internal/regex"
77

88
"github.com/errata-ai/vale/v3/internal/core"
99
"github.com/errata-ai/vale/v3/internal/nlp"
@@ -19,9 +19,9 @@ type Repetition struct {
1919
Vocab bool
2020
Exceptions []string
2121

22-
exceptRe *regexp2.Regexp
23-
phraseRe *regexp2.Regexp
24-
pattern *regexp2.Regexp
22+
exceptRe *rx.Regexp
23+
phraseRe *rx.Regexp
24+
pattern *rx.Regexp
2525
}
2626

2727
// NewRepetition creates a new `repetition`-based rule.
@@ -51,7 +51,7 @@ func NewRepetition(cfg *core.Config, generic baseCheck, path string) (Repetition
5151
}
5252
regex += `(` + strings.Join(rule.Tokens, "|") + `)`
5353

54-
made, err := regexp2.CompileStd(regex)
54+
made, err := rx.Compile(regex)
5555
if err != nil {
5656
return rule, core.NewE201FromPosition(err.Error(), path, 1)
5757
}

internal/check/sequence.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import (
44
"fmt"
55
"strings"
66

7-
"github.com/errata-ai/regexp2"
7+
rx "github.com/errata-ai/vale/v3/internal/regex"
88
"github.com/jdkato/prose/v3/tag"
99
"github.com/mitchellh/mapstructure"
1010

@@ -17,7 +17,7 @@ type NLPToken struct {
1717
Pattern string
1818
Tag string
1919
Skip int
20-
re *regexp2.Regexp
20+
re *rx.Regexp
2121
Negate bool
2222
optional bool
2323
start bool
@@ -65,7 +65,7 @@ func NewSequence(cfg *core.Config, generic baseCheck, path string) (Sequence, er
6565
false)
6666
regex = fmt.Sprintf(regex, token.Pattern)
6767

68-
re, errc := regexp2.CompileStd(regex)
68+
re, errc := rx.Compile(regex)
6969
if errc != nil {
7070
return rule, core.NewE201FromPosition(errc.Error(), path, 1)
7171
}
@@ -115,7 +115,7 @@ func makeTokens(s *Sequence, generic baseCheck) error {
115115
}
116116

117117
func tokensMatch(token NLPToken, word tag.Token) bool {
118-
failedTag, err := regexp2.MatchString(token.Tag, word.Tag)
118+
failedTag, err := rx.MatchString(token.Tag, word.Tag)
119119
if err != nil {
120120
// FIXME: return the error instead ...
121121
panic(err)

0 commit comments

Comments
 (0)