mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
all: replace [0-9] with \d in regexps
1. replace [0-9] with \d in regexps
2. replace [a-zA-Z0-9_] with \w in regexps
Change-Id: I9e260538252a0c1071e76aeb1c5f885c6843a431
GitHub-Last-Rev: 286e1a4619
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>
This commit is contained in:
parent
550864e5d2
commit
fac5338a6c
17 changed files with 23 additions and 23 deletions
|
|
@ -261,7 +261,7 @@ func isHexes(s string) bool {
|
||||||
// the standard file:line: prefix,
|
// the standard file:line: prefix,
|
||||||
// but that's not where we are today.
|
// 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.
|
// 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
|
// Same as in test/run.go
|
||||||
var (
|
var (
|
||||||
|
|
|
||||||
|
|
@ -1282,7 +1282,7 @@ func (p *Package) writeExportHeader(fgcch io.Writer) {
|
||||||
// They aren't useful for people using the header file,
|
// They aren't useful for people using the header file,
|
||||||
// and they mean that the header files change based on the
|
// and they mean that the header files change based on the
|
||||||
// exact location of GOPATH.
|
// 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")
|
preamble := re.ReplaceAllString(p.Preamble, "$1$2")
|
||||||
|
|
||||||
fmt.Fprintf(fgcch, "/* Start of preamble from import \"C\" comments. */\n\n")
|
fmt.Fprintf(fgcch, "/* Start of preamble from import \"C\" comments. */\n\n")
|
||||||
|
|
|
||||||
|
|
@ -113,7 +113,7 @@ func clobber(t *testing.T, src string, dst *os.File, opcodes map[string]bool) {
|
||||||
if err := cmd.Start(); err != nil {
|
if err := cmd.Start(); err != nil {
|
||||||
t.Fatal(err)
|
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 {
|
} else {
|
||||||
// TODO: we're depending on platform-native objdump here. Hence the Skipf
|
// TODO: we're depending on platform-native objdump here. Hence the Skipf
|
||||||
// below if it doesn't run for some reason.
|
// 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)
|
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.
|
// Find all the instruction addresses we need to edit.
|
||||||
|
|
|
||||||
|
|
@ -24,14 +24,14 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
// Matches lines in genssa output that are marked "isstmt", and the parenthesized plus-prefixed line number is a submatch
|
// 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)`
|
// this matches e.g. ` v123456789 000007 (+9876654310) MOVUPS X15, ""..autotmp_2-32(SP)`
|
||||||
|
|
||||||
// Matches lines in genssa output that describe an inlined file.
|
// Matches lines in genssa output that describe an inlined file.
|
||||||
// Note it expects an unadventurous choice of basename.
|
// Note it expects an unadventurous choice of basename.
|
||||||
var sepRE = regexp.QuoteMeta(string(filepath.Separator))
|
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
|
// this matches e.g. # /pa/inline-dumpxxxx.go:6
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -32,11 +32,11 @@ var (
|
||||||
|
|
||||||
var (
|
var (
|
||||||
hexRe = regexp.MustCompile("0x[a-zA-Z0-9]+")
|
hexRe = regexp.MustCompile("0x[a-zA-Z0-9]+")
|
||||||
numRe = regexp.MustCompile("-?[0-9]+")
|
numRe = regexp.MustCompile("-?\\d+")
|
||||||
stringRe = regexp.MustCompile("\"([^\\\"]|(\\.))*\"")
|
stringRe = regexp.MustCompile("\"([^\\\"]|(\\.))*\"")
|
||||||
leadingDollarNumberRe = regexp.MustCompile("^[$][0-9]+")
|
leadingDollarNumberRe = regexp.MustCompile("^[$]\\d+")
|
||||||
optOutGdbRe = regexp.MustCompile("[<]optimized out[>]")
|
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
|
var gdb = "gdb" // Might be "ggdb" on Darwin, because gdb no longer part of XCode
|
||||||
|
|
|
||||||
|
|
@ -81,4 +81,4 @@ func currentLang() string {
|
||||||
|
|
||||||
// goVersionRE is a regular expression that matches the valid
|
// goVersionRE is a regular expression that matches the valid
|
||||||
// arguments to the -lang flag.
|
// 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*)$`)
|
||||||
|
|
|
||||||
2
src/cmd/dist/test.go
vendored
2
src/cmd/dist/test.go
vendored
|
|
@ -1414,7 +1414,7 @@ func (t *tester) hasSwig() bool {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
re := regexp.MustCompile(`[vV]ersion +([\d]+)([.][\d]+)?([.][\d]+)?`)
|
re := regexp.MustCompile(`[vV]ersion +(\d+)([.]\d+)?([.]\d+)?`)
|
||||||
matches := re.FindSubmatch(out)
|
matches := re.FindSubmatch(out)
|
||||||
if matches == nil {
|
if matches == nil {
|
||||||
// Can't find version number; hope for the best.
|
// Can't find version number; hope for the best.
|
||||||
|
|
|
||||||
|
|
@ -3147,7 +3147,7 @@ func (b *Builder) swigDoVersionCheck() error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
re := regexp.MustCompile(`[vV]ersion +([\d]+)([.][\d]+)?([.][\d]+)?`)
|
re := regexp.MustCompile(`[vV]ersion +(\d+)([.]\d+)?([.]\d+)?`)
|
||||||
matches := re.FindSubmatch(out)
|
matches := re.FindSubmatch(out)
|
||||||
if matches == nil {
|
if matches == nil {
|
||||||
// Can't find version number; hope for the best.
|
// Can't find version number; hope for the best.
|
||||||
|
|
|
||||||
|
|
@ -238,7 +238,7 @@ func (ts *testScript) setup() {
|
||||||
func goVersion() (string, error) {
|
func goVersion() (string, error) {
|
||||||
tags := build.Default.ReleaseTags
|
tags := build.Default.ReleaseTags
|
||||||
version := tags[len(tags)-1]
|
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 "", fmt.Errorf("invalid go version %q", version)
|
||||||
}
|
}
|
||||||
return version[2:], nil
|
return version[2:], nil
|
||||||
|
|
|
||||||
|
|
@ -34,7 +34,7 @@ func TestStackCheckOutput(t *testing.T) {
|
||||||
t.Logf("linker output:\n%s", out)
|
t.Logf("linker output:\n%s", out)
|
||||||
|
|
||||||
// Get expected limit.
|
// 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)
|
m := limitRe.FindStringSubmatch(out)
|
||||||
if m == nil {
|
if m == nil {
|
||||||
t.Fatalf("no overflow errors in output")
|
t.Fatalf("no overflow errors in output")
|
||||||
|
|
@ -66,7 +66,7 @@ func TestStackCheckOutput(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Parse stanzas
|
// 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
|
// Strip comments from cmd/go
|
||||||
out = regexp.MustCompile(`(?m)^#.*\n`).ReplaceAllString(out, "")
|
out = regexp.MustCompile(`(?m)^#.*\n`).ReplaceAllString(out, "")
|
||||||
for len(out) > 0 {
|
for len(out) > 0 {
|
||||||
|
|
|
||||||
|
|
@ -520,7 +520,7 @@ func writeProducerSec(ctxt *ld.Link) {
|
||||||
writeSecSize(ctxt, sizeOffset)
|
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.
|
// 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.
|
// The names are only used by WebAssembly stack traces, debuggers and decompilers.
|
||||||
|
|
|
||||||
|
|
@ -337,7 +337,7 @@ var (
|
||||||
errRx = regexp.MustCompile(`// (?:GC_)?ERROR(NEXT)? (.*)`)
|
errRx = regexp.MustCompile(`// (?:GC_)?ERROR(NEXT)? (.*)`)
|
||||||
errAutoRx = regexp.MustCompile(`// (?:GC_)?ERRORAUTO(NEXT)? (.*)`)
|
errAutoRx = regexp.MustCompile(`// (?:GC_)?ERRORAUTO(NEXT)? (.*)`)
|
||||||
errQuotesRx = regexp.MustCompile(`"([^"]*)"`)
|
errQuotesRx = regexp.MustCompile(`"([^"]*)"`)
|
||||||
lineRx = regexp.MustCompile(`LINE(([+-])([0-9]+))?`)
|
lineRx = regexp.MustCompile(`LINE(([+-])(\d+))?`)
|
||||||
)
|
)
|
||||||
|
|
||||||
// wantedErrors parses expected errors from comments in a file.
|
// wantedErrors parses expected errors from comments in a file.
|
||||||
|
|
|
||||||
|
|
@ -135,7 +135,7 @@ func TestObjImporter(t *testing.T) {
|
||||||
t.Logf("%s", verout)
|
t.Logf("%s", verout)
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
vers := regexp.MustCompile(`([0-9]+)\.([0-9]+)`).FindSubmatch(verout)
|
vers := regexp.MustCompile(`(\d+)\.(\d+)`).FindSubmatch(verout)
|
||||||
if len(vers) == 0 {
|
if len(vers) == 0 {
|
||||||
t.Fatalf("could not find version number in %s", verout)
|
t.Fatalf("could not find version number in %s", verout)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -50,7 +50,7 @@ var (
|
||||||
var fset = token.NewFileSet()
|
var fset = token.NewFileSet()
|
||||||
|
|
||||||
// Positioned errors are of the form filename:line:column: message .
|
// 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
|
// splitError splits an error's error message into a position string
|
||||||
// and the actual error message. If there's no position information,
|
// and the actual error message. If there's no position information,
|
||||||
|
|
|
||||||
|
|
@ -73,7 +73,7 @@ func Unused() { {}; {{ var x int; _ = x }} } // make sure empty block scopes get
|
||||||
// For determinism, we redact addresses.
|
// For determinism, we redact addresses.
|
||||||
var buf strings.Builder
|
var buf strings.Builder
|
||||||
pkg.Scope().WriteTo(&buf, 0, true)
|
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(), ""))
|
fmt.Println(rx.ReplaceAllString(buf.String(), ""))
|
||||||
|
|
||||||
// Output:
|
// Output:
|
||||||
|
|
|
||||||
|
|
@ -79,4 +79,4 @@ func parseGoVersion(s string) (v version, err error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// goVersionRx matches a Go version string, e.g. "go1.12".
|
// 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*)$`)
|
||||||
|
|
|
||||||
|
|
@ -1427,7 +1427,7 @@ func (t *test) updateErrors(out, file string) {
|
||||||
}
|
}
|
||||||
// Parse new errors.
|
// Parse new errors.
|
||||||
errors := make(map[int]map[string]bool)
|
errors := make(map[int]map[string]bool)
|
||||||
tmpRe := regexp.MustCompile(`autotmp_[0-9]+`)
|
tmpRe := regexp.MustCompile(`autotmp_\d+`)
|
||||||
for _, errStr := range splitOutput(out, false) {
|
for _, errStr := range splitOutput(out, false) {
|
||||||
errFile, rest, ok := strings.Cut(errStr, ":")
|
errFile, rest, ok := strings.Cut(errStr, ":")
|
||||||
if !ok || errFile != file {
|
if !ok || errFile != file {
|
||||||
|
|
@ -1520,7 +1520,7 @@ var (
|
||||||
errRx = regexp.MustCompile(`// (?:GC_)?ERROR (.*)`)
|
errRx = regexp.MustCompile(`// (?:GC_)?ERROR (.*)`)
|
||||||
errAutoRx = regexp.MustCompile(`// (?:GC_)?ERRORAUTO (.*)`)
|
errAutoRx = regexp.MustCompile(`// (?:GC_)?ERRORAUTO (.*)`)
|
||||||
errQuotesRx = regexp.MustCompile(`"([^"]*)"`)
|
errQuotesRx = regexp.MustCompile(`"([^"]*)"`)
|
||||||
lineRx = regexp.MustCompile(`LINE(([+-])([0-9]+))?`)
|
lineRx = regexp.MustCompile(`LINE(([+-])(\d+))?`)
|
||||||
)
|
)
|
||||||
|
|
||||||
func (t *test) wantedErrors(file, short string) (errs []wantedError) {
|
func (t *test) wantedErrors(file, short string) (errs []wantedError) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue