]> Cypherpunks repositories - gostls13.git/commitdiff
all: replace [0-9] with \d in regexps
authorTomCao New Macbook Pro <jiepengthegreat@126.com>
Tue, 27 Sep 2022 04:18:15 +0000 (04:18 +0000)
committerGopher Robot <gobot@golang.org>
Tue, 27 Sep 2022 14:14:42 +0000 (14:14 +0000)
1. replace [0-9] with \d in regexps
2. replace [a-zA-Z0-9_] with \w in regexps

Change-Id: I9e260538252a0c1071e76aeb1c5f885c6843a431
GitHub-Last-Rev: 286e1a4619c4bdda7f461afbd6d30b9f312c0486
GitHub-Pull-Request: golang/go#54874
Reviewed-on: https://go-review.googlesource.com/c/go/+/428435
Reviewed-by: Ian Lance Taylor <iant@google.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Auto-Submit: Dmitri Shuralyov <dmitshur@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
Run-TryBot: Ian Lance Taylor <iant@google.com>

17 files changed:
src/cmd/asm/internal/asm/endtoend_test.go
src/cmd/cgo/out.go
src/cmd/compile/internal/amd64/versions_test.go
src/cmd/compile/internal/ssa/debug_lines_test.go
src/cmd/compile/internal/ssa/debug_test.go
src/cmd/compile/internal/types/goversion.go
src/cmd/dist/test.go
src/cmd/go/internal/work/exec.go
src/cmd/go/script_test.go
src/cmd/link/internal/ld/stackcheck_test.go
src/cmd/link/internal/wasm/asm.go
src/cmd/vet/vet_test.go
src/go/internal/gccgoimporter/importer_test.go
src/go/types/check_test.go
src/go/types/example_test.go
src/go/types/version.go
test/run.go

index a234b2f1fe991641c816b0977fdc3986ad3ca019..8af4db6ee4f241d7c3ea7991c6c0ed7e75767cc3 100644 (file)
@@ -261,7 +261,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 (
index 95223588252b2806590992dd603bc33e464af048..e2e2e0b8c5d5fd655ef68531771217135773d013 100644 (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")
index 647bcdc2f0728030d2d72f87528187123a8bc69c..28cd073e6f637d6f1558ff22929c58be4c5a13b0 100644 (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.
index cde1015b4bb3bf1e323e329b473276a825b122a9..b5607d7efc2856590132d2568b5f1fa219c3b866 100644 (file)
@@ -24,14 +24,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
 
index f96c5b131cd9942f9fdf568717ec0551b6318ae0..af32ba7047a8cf3a4fd545a74f5838079d561082 100644 (file)
@@ -32,11 +32,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
index ceb2ed366edae03481029d3025d80d2995989114..3ece95bf0ac81510af0d684152d48b16e7b716bc 100644 (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*)$`)
index 5bc9c9ca895962860ae9d39cb6c7e5cfbbc65c61..e0224fa834a5c28852634a114b192a0188063129 100644 (file)
@@ -1414,7 +1414,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.
index e0b9472fa1c5baa121090426cdedd8f4459b0bc4..6885e3ecad20d9e3d5311305847ea93f9407d3d7 100644 (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.
index b2f68b67f9eb2bbde1ab23cf5caed95d15987c09..006c4346c7e9f96addcae7649730b41972880489 100644 (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
index 2089badbe91a71b3d32909ecdb67d66949beee5f..d93540174012336d75753c098a15c2912bd907d7 100644 (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 {
index 45cb209e974482cd04f9e46d9725bb4a508f8b96..041b4e27802106ea89809ac27031cdb50f482f8e 100644 (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.
index cfe58a07c8e3724a66af579eb203192522c7e4d2..1b74fa3fd5677467084387c581b7b36112ec298f 100644 (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.
index 8a7ee1aa4ffa9ba2b4b265d5bf669dbb6549fd4f..55e2feb9fa6b7fcbb17ca8af34830234d4fc9b54 100644 (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)
        }
index a743d9d41d99d99549e8e15c45a7b8e100fd119d..21e1856683d1e3b388fe8c6feab4e5a4a9f72a5b 100644 (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,
index e752a77881454e0c843ae74bae00da48c4d180be..75233e6dd52bcfac59a045c17c668d8a089352d0 100644 (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:
index 71093c6818ce095582cd5bf41a0d1ae9d8e956cf..a3118296727c181455649c4a928b56e2c91f7fb2 100644 (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*)$`)
index f4d24c597b59fe12a1ee5efae79a075ba972f97f..5bd174e96760c37b74915a9b5c5eea145c96b472 100644 (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) {