1
0
mirror of https://github.com/golang/go synced 2024-11-16 20:04:52 -07:00

all: replace [0-9] with \d in regexps

This commit is contained in:
TomCao New Macbook Pro 2022-09-09 19:52:38 +08:00
parent 41089704dd
commit 286e1a4619
17 changed files with 23 additions and 23 deletions

View File

@ -262,7 +262,7 @@ func isHexes(s string) bool {
// the standard file:line: prefix,
// but that's not where we are today.
// It might be at the beginning but it might be in the middle of the printed instruction.
var fileLineRE = regexp.MustCompile(`(?:^|\()(testdata[/\\][0-9a-z]+\.s:[0-9]+)(?:$|\)|:)`)
var fileLineRE = regexp.MustCompile(`(?:^|\()(testdata[/\\][\da-z]+\.s:\d+)(?:$|\)|:)`)
// Same as in test/run.go
var (

View File

@ -1282,7 +1282,7 @@ func (p *Package) writeExportHeader(fgcch io.Writer) {
// They aren't useful for people using the header file,
// and they mean that the header files change based on the
// exact location of GOPATH.
re := regexp.MustCompile(`(?m)^(#line\s+[0-9]+\s+")[^"]*[/\\]([^"]*")`)
re := regexp.MustCompile(`(?m)^(#line\s+\d+\s+")[^"]*[/\\]([^"]*")`)
preamble := re.ReplaceAllString(p.Preamble, "$1$2")
fmt.Fprintf(fgcch, "/* Start of preamble from import \"C\" comments. */\n\n")

View File

@ -113,7 +113,7 @@ func clobber(t *testing.T, src string, dst *os.File, opcodes map[string]bool) {
if err := cmd.Start(); err != nil {
t.Fatal(err)
}
re = regexp.MustCompile(`^[^:]*:[-0-9]+\s+0x([0-9a-f]+)\s+([0-9a-f]+)\s+([A-Z]+)`)
re = regexp.MustCompile(`^[^:]*:[-\d]+\s+0x([\da-f]+)\s+([\da-f]+)\s+([A-Z]+)`)
} else {
// TODO: we're depending on platform-native objdump here. Hence the Skipf
// below if it doesn't run for some reason.
@ -129,7 +129,7 @@ func clobber(t *testing.T, src string, dst *os.File, opcodes map[string]bool) {
}
t.Fatal(err)
}
re = regexp.MustCompile(`^\s*([0-9a-f]+):\s*((?:[0-9a-f][0-9a-f] )+)\s*([a-z0-9]+)`)
re = regexp.MustCompile(`^\s*([\da-f]+):\s*((?:[\da-f][\da-f] )+)\s*([a-z\d]+)`)
}
// Find all the instruction addresses we need to edit.

View File

@ -26,14 +26,14 @@ import (
)
// Matches lines in genssa output that are marked "isstmt", and the parenthesized plus-prefixed line number is a submatch
var asmLine *regexp.Regexp = regexp.MustCompile(`^\s[vb][0-9]+\s+[0-9]+\s\(\+([0-9]+)\)`)
var asmLine *regexp.Regexp = regexp.MustCompile(`^\s[vb]\d+\s+\d+\s\(\+(\d+)\)`)
// this matches e.g. ` v123456789 000007 (+9876654310) MOVUPS X15, ""..autotmp_2-32(SP)`
// Matches lines in genssa output that describe an inlined file.
// Note it expects an unadventurous choice of basename.
var sepRE = regexp.QuoteMeta(string(filepath.Separator))
var inlineLine *regexp.Regexp = regexp.MustCompile(`^#\s.*` + sepRE + `[-a-zA-Z0-9_]+\.go:([0-9]+)`)
var inlineLine *regexp.Regexp = regexp.MustCompile(`^#\s.*` + sepRE + `[-\w]+\.go:(\d+)`)
// this matches e.g. # /pa/inline-dumpxxxx.go:6

View File

@ -33,11 +33,11 @@ var (
var (
hexRe = regexp.MustCompile("0x[a-zA-Z0-9]+")
numRe = regexp.MustCompile("-?[0-9]+")
numRe = regexp.MustCompile("-?\\d+")
stringRe = regexp.MustCompile("\"([^\\\"]|(\\.))*\"")
leadingDollarNumberRe = regexp.MustCompile("^[$][0-9]+")
leadingDollarNumberRe = regexp.MustCompile("^[$]\\d+")
optOutGdbRe = regexp.MustCompile("[<]optimized out[>]")
numberColonRe = regexp.MustCompile("^ *[0-9]+:")
numberColonRe = regexp.MustCompile("^ *\\d+:")
)
var gdb = "gdb" // Might be "ggdb" on Darwin, because gdb no longer part of XCode

View File

@ -81,4 +81,4 @@ func currentLang() string {
// goVersionRE is a regular expression that matches the valid
// arguments to the -lang flag.
var goVersionRE = regexp.MustCompile(`^go([1-9][0-9]*)\.(0|[1-9][0-9]*)$`)
var goVersionRE = regexp.MustCompile(`^go([1-9]\d*)\.(0|[1-9]\d*)$`)

View File

@ -1415,7 +1415,7 @@ func (t *tester) hasSwig() bool {
return false
}
re := regexp.MustCompile(`[vV]ersion +([\d]+)([.][\d]+)?([.][\d]+)?`)
re := regexp.MustCompile(`[vV]ersion +(\d+)([.]\d+)?([.]\d+)?`)
matches := re.FindSubmatch(out)
if matches == nil {
// Can't find version number; hope for the best.

View File

@ -3147,7 +3147,7 @@ func (b *Builder) swigDoVersionCheck() error {
if err != nil {
return err
}
re := regexp.MustCompile(`[vV]ersion +([\d]+)([.][\d]+)?([.][\d]+)?`)
re := regexp.MustCompile(`[vV]ersion +(\d+)([.]\d+)?([.]\d+)?`)
matches := re.FindSubmatch(out)
if matches == nil {
// Can't find version number; hope for the best.

View File

@ -238,7 +238,7 @@ func (ts *testScript) setup() {
func goVersion() (string, error) {
tags := build.Default.ReleaseTags
version := tags[len(tags)-1]
if !regexp.MustCompile(`^go([1-9][0-9]*)\.(0|[1-9][0-9]*)$`).MatchString(version) {
if !regexp.MustCompile(`^go([1-9]\d*)\.(0|[1-9]\d*)$`).MatchString(version) {
return "", fmt.Errorf("invalid go version %q", version)
}
return version[2:], nil

View File

@ -34,7 +34,7 @@ func TestStackCheckOutput(t *testing.T) {
t.Logf("linker output:\n%s", out)
// Get expected limit.
limitRe := regexp.MustCompile("nosplit stack over ([0-9]+) byte limit")
limitRe := regexp.MustCompile(`nosplit stack over (\d+) byte limit`)
m := limitRe.FindStringSubmatch(out)
if m == nil {
t.Fatalf("no overflow errors in output")
@ -66,7 +66,7 @@ func TestStackCheckOutput(t *testing.T) {
}
// Parse stanzas
stanza := regexp.MustCompile(`^(.*): nosplit stack over [0-9]+ byte limit\n(.*\n(?: .*\n)*)`)
stanza := regexp.MustCompile(`^(.*): nosplit stack over \d+ byte limit\n(.*\n(?: .*\n)*)`)
// Strip comments from cmd/go
out = regexp.MustCompile(`(?m)^#.*\n`).ReplaceAllString(out, "")
for len(out) > 0 {

View File

@ -520,7 +520,7 @@ func writeProducerSec(ctxt *ld.Link) {
writeSecSize(ctxt, sizeOffset)
}
var nameRegexp = regexp.MustCompile(`[^\w\.]`)
var nameRegexp = regexp.MustCompile(`[^\w.]`)
// writeNameSec writes an optional section that assigns names to the functions declared by the "func" section.
// The names are only used by WebAssembly stack traces, debuggers and decompilers.

View File

@ -337,7 +337,7 @@ var (
errRx = regexp.MustCompile(`// (?:GC_)?ERROR(NEXT)? (.*)`)
errAutoRx = regexp.MustCompile(`// (?:GC_)?ERRORAUTO(NEXT)? (.*)`)
errQuotesRx = regexp.MustCompile(`"([^"]*)"`)
lineRx = regexp.MustCompile(`LINE(([+-])([0-9]+))?`)
lineRx = regexp.MustCompile(`LINE(([+-])(\d+))?`)
)
// wantedErrors parses expected errors from comments in a file.

View File

@ -135,7 +135,7 @@ func TestObjImporter(t *testing.T) {
t.Logf("%s", verout)
t.Fatal(err)
}
vers := regexp.MustCompile(`([0-9]+)\.([0-9]+)`).FindSubmatch(verout)
vers := regexp.MustCompile(`(\d+)\.(\d+)`).FindSubmatch(verout)
if len(vers) == 0 {
t.Fatalf("could not find version number in %s", verout)
}

View File

@ -50,7 +50,7 @@ var (
var fset = token.NewFileSet()
// Positioned errors are of the form filename:line:column: message .
var posMsgRx = regexp.MustCompile(`^(.*:[0-9]+:[0-9]+): *(?s)(.*)`)
var posMsgRx = regexp.MustCompile(`^(.*:\d+:\d+): *(?s)(.*)`)
// splitError splits an error's error message into a position string
// and the actual error message. If there's no position information,

View File

@ -73,7 +73,7 @@ func Unused() { {}; {{ var x int; _ = x }} } // make sure empty block scopes get
// For determinism, we redact addresses.
var buf strings.Builder
pkg.Scope().WriteTo(&buf, 0, true)
rx := regexp.MustCompile(` 0x[a-fA-F0-9]*`)
rx := regexp.MustCompile(` 0x[a-fA-F\d]*`)
fmt.Println(rx.ReplaceAllString(buf.String(), ""))
// Output:

View File

@ -79,4 +79,4 @@ func parseGoVersion(s string) (v version, err error) {
}
// goVersionRx matches a Go version string, e.g. "go1.12".
var goVersionRx = regexp.MustCompile(`^go([1-9][0-9]*)\.(0|[1-9][0-9]*)$`)
var goVersionRx = regexp.MustCompile(`^go([1-9]\d*)\.(0|[1-9]\d*)$`)

View File

@ -1427,7 +1427,7 @@ func (t *test) updateErrors(out, file string) {
}
// Parse new errors.
errors := make(map[int]map[string]bool)
tmpRe := regexp.MustCompile(`autotmp_[0-9]+`)
tmpRe := regexp.MustCompile(`autotmp_\d+`)
for _, errStr := range splitOutput(out, false) {
errFile, rest, ok := strings.Cut(errStr, ":")
if !ok || errFile != file {
@ -1520,7 +1520,7 @@ var (
errRx = regexp.MustCompile(`// (?:GC_)?ERROR (.*)`)
errAutoRx = regexp.MustCompile(`// (?:GC_)?ERRORAUTO (.*)`)
errQuotesRx = regexp.MustCompile(`"([^"]*)"`)
lineRx = regexp.MustCompile(`LINE(([+-])([0-9]+))?`)
lineRx = regexp.MustCompile(`LINE(([+-])(\d+))?`)
)
func (t *test) wantedErrors(file, short string) (errs []wantedError) {