"runtime/trace": {"L0", "context", "fmt"},
"text/tabwriter": {"L2"},
- "testing": {"L2", "flag", "fmt", "internal/race", "os", "runtime/debug", "runtime/pprof", "runtime/trace", "time"},
- "testing/iotest": {"L2", "log"},
- "testing/quick": {"L2", "flag", "fmt", "reflect", "time"},
- "internal/testenv": {"L2", "OS", "flag", "testing", "syscall"},
+ "testing": {"L2", "flag", "fmt", "internal/race", "os", "runtime/debug", "runtime/pprof", "runtime/trace", "time"},
+ "testing/iotest": {"L2", "log"},
+ "testing/quick": {"L2", "flag", "fmt", "reflect", "time"},
+ "internal/testenv": {"L2", "OS", "flag", "testing", "syscall"},
+ "internal/lazyregexp": {"L2", "OS", "regexp"},
// L4 is defined as L3+fmt+log+time, because in general once
// you're using L3 packages, use of fmt, log, or time is not a big deal.
// Go parser.
"go/ast": {"L4", "OS", "go/scanner", "go/token"},
- "go/doc": {"L4", "OS", "go/ast", "go/token", "regexp", "text/template"},
+ "go/doc": {"L4", "OS", "go/ast", "go/token", "regexp", "internal/lazyregexp", "text/template"},
"go/parser": {"L4", "OS", "go/ast", "go/scanner", "go/token"},
"go/printer": {"L4", "OS", "go/ast", "go/scanner", "go/token", "text/tabwriter"},
"go/scanner": {"L4", "OS", "go/token"},
import (
"go/ast"
"go/token"
+ "internal/lazyregexp"
"sort"
"strconv"
)
}
var (
- noteMarker = `([A-Z][A-Z]+)\(([^)]+)\):?` // MARKER(uid), MARKER at least 2 chars, uid at least 1 char
- noteMarkerRx = newLazyRE(`^[ \t]*` + noteMarker) // MARKER(uid) at text start
- noteCommentRx = newLazyRE(`^/[/*][ \t]*` + noteMarker) // MARKER(uid) at comment start
+ noteMarker = `([A-Z][A-Z]+)\(([^)]+)\):?` // MARKER(uid), MARKER at least 2 chars, uid at least 1 char
+ noteMarkerRx = lazyregexp.New(`^[ \t]*` + noteMarker) // MARKER(uid) at text start
+ noteCommentRx = lazyregexp.New(`^/[/*][ \t]*` + noteMarker) // MARKER(uid) at comment start
)
// readNote collects a single note from a sequence of comments.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
-package doc
+package lazyregexp
import (
"os"
"sync"
)
-type lazyRE struct {
+type Regexp struct {
str string
once sync.Once
rx *regexp.Regexp
}
-func (r *lazyRE) re() *regexp.Regexp {
+func (r *Regexp) re() *regexp.Regexp {
r.once.Do(r.build)
return r.rx
}
-func (r *lazyRE) build() {
+func (r *Regexp) build() {
r.rx = regexp.MustCompile(r.str)
r.str = ""
}
-func (r *lazyRE) FindStringSubmatchIndex(s string) []int {
+func (r *Regexp) FindStringSubmatchIndex(s string) []int {
return r.re().FindStringSubmatchIndex(s)
}
-func (r *lazyRE) ReplaceAllString(src, repl string) string {
+func (r *Regexp) ReplaceAllString(src, repl string) string {
return r.re().ReplaceAllString(src, repl)
}
-func (r *lazyRE) MatchString(s string) bool {
+func (r *Regexp) MatchString(s string) bool {
return r.re().MatchString(s)
}
var inTest = len(os.Args) > 0 && strings.HasSuffix(strings.TrimSuffix(os.Args[0], ".exe"), ".test")
-func newLazyRE(str string) *lazyRE {
- lr := &lazyRE{str: str}
+func New(str string) *Regexp {
+ lr := &Regexp{str: str}
if inTest {
// In tests, always compile the regexps early.
lr.re()