summaryrefslogtreecommitdiff
path: root/src/cmd/godoc
diff options
context:
space:
mode:
Diffstat (limited to 'src/cmd/godoc')
-rw-r--r--src/cmd/godoc/doc.go3
-rw-r--r--src/cmd/godoc/godoc.go35
-rw-r--r--src/cmd/godoc/main.go15
-rw-r--r--src/cmd/godoc/spec.go12
4 files changed, 45 insertions, 20 deletions
diff --git a/src/cmd/godoc/doc.go b/src/cmd/godoc/doc.go
index f0006e750..26d436d72 100644
--- a/src/cmd/godoc/doc.go
+++ b/src/cmd/godoc/doc.go
@@ -47,6 +47,9 @@ The flags are:
width of tabs in units of spaces
-timestamps=true
show timestamps with directory listings
+ -index
+ enable identifier and full text search index
+ (no search box is shown if -index is not set)
-maxresults=10000
maximum number of full text search results shown
(no full text index is built if maxresults <= 0)
diff --git a/src/cmd/godoc/godoc.go b/src/cmd/godoc/godoc.go
index b8e9dbc92..f97c764f9 100644
--- a/src/cmd/godoc/godoc.go
+++ b/src/cmd/godoc/godoc.go
@@ -64,9 +64,12 @@ var (
// layout control
tabwidth = flag.Int("tabwidth", 4, "tab width")
showTimestamps = flag.Bool("timestamps", true, "show timestamps with directory listings")
- maxResults = flag.Int("maxresults", 10000, "maximum number of full text search results shown")
templateDir = flag.String("templates", "", "directory containing alternate template files")
+ // search index
+ indexEnabled = flag.Bool("index", false, "enable search index")
+ maxResults = flag.Int("maxresults", 10000, "maximum number of full text search results shown")
+
// file system mapping
fsMap Mapping // user-defined mapping
fsTree RWValue // *Directory tree of packages, updated with each sync
@@ -687,17 +690,19 @@ func readTemplates() {
func servePage(w http.ResponseWriter, title, subtitle, query string, content []byte) {
d := struct {
- Title string
- Subtitle string
- PkgRoots []string
- Query string
- Version string
- Menu []byte
- Content []byte
+ Title string
+ Subtitle string
+ PkgRoots []string
+ SearchBox bool
+ Query string
+ Version string
+ Menu []byte
+ Content []byte
}{
title,
subtitle,
fsMap.PrefixList(),
+ *indexEnabled,
query,
runtime.Version(),
nil,
@@ -1174,11 +1179,15 @@ func lookup(query string) (result SearchResult) {
}
// is the result accurate?
- if _, ts := fsModified.get(); timestamp < ts {
- // The index is older than the latest file system change
- // under godoc's observation. Indexing may be in progress
- // or start shortly (see indexer()).
- result.Alert = "Indexing in progress: result may be inaccurate"
+ if *indexEnabled {
+ if _, ts := fsModified.get(); timestamp < ts {
+ // The index is older than the latest file system change
+ // under godoc's observation. Indexing may be in progress
+ // or start shortly (see indexer()).
+ result.Alert = "Indexing in progress: result may be inaccurate"
+ }
+ } else {
+ result.Alert = "Search index disabled: no results available"
}
return
diff --git a/src/cmd/godoc/main.go b/src/cmd/godoc/main.go
index e426626b3..967ea8727 100644
--- a/src/cmd/godoc/main.go
+++ b/src/cmd/godoc/main.go
@@ -176,7 +176,7 @@ func remoteSearch(query string) (res *http.Response, err os.Error) {
// remote search
for _, addr := range addrs {
url := "http://" + addr + search
- res, _, err = http.Get(url)
+ res, err = http.Get(url)
if err == nil && res.StatusCode == http.StatusOK {
break
}
@@ -246,8 +246,13 @@ func main() {
log.Printf("address = %s", *httpAddr)
log.Printf("goroot = %s", *goroot)
log.Printf("tabwidth = %d", *tabwidth)
- if *maxResults > 0 {
- log.Printf("maxresults = %d (full text index enabled)", *maxResults)
+ switch {
+ case !*indexEnabled:
+ log.Print("search index disabled")
+ case *maxResults > 0:
+ log.Printf("full text index enabled (maxresults = %d)", *maxResults)
+ default:
+ log.Print("identifier search index enabled")
}
if !fsMap.IsEmpty() {
log.Print("user-defined mapping:")
@@ -284,7 +289,9 @@ func main() {
}
// Start indexing goroutine.
- go indexer()
+ if *indexEnabled {
+ go indexer()
+ }
// Start http server.
if err := http.ListenAndServe(*httpAddr, handler); err != nil {
diff --git a/src/cmd/godoc/spec.go b/src/cmd/godoc/spec.go
index f8b95e387..444e36e08 100644
--- a/src/cmd/godoc/spec.go
+++ b/src/cmd/godoc/spec.go
@@ -99,7 +99,8 @@ func (p *ebnfParser) parseTerm() bool {
case token.STRING:
p.next()
- if p.tok == token.ELLIPSIS {
+ const ellipsis = "…" // U+2026, the horizontal ellipsis character
+ if p.tok == token.ILLEGAL && p.lit == ellipsis {
p.next()
p.expect(token.STRING)
}
@@ -128,6 +129,9 @@ func (p *ebnfParser) parseTerm() bool {
func (p *ebnfParser) parseSequence() {
+ if !p.parseTerm() {
+ p.errorExpected(p.pos, "term")
+ }
for p.parseTerm() {
}
}
@@ -147,7 +151,9 @@ func (p *ebnfParser) parseExpression() {
func (p *ebnfParser) parseProduction() {
p.parseIdentifier(true)
p.expect(token.ASSIGN)
- p.parseExpression()
+ if p.tok != token.PERIOD {
+ p.parseExpression()
+ }
p.expect(token.PERIOD)
}
@@ -157,7 +163,7 @@ func (p *ebnfParser) parse(fset *token.FileSet, out io.Writer, src []byte) {
p.out = out
p.src = src
p.file = fset.AddFile("", fset.Base(), len(src))
- p.scanner.Init(p.file, src, p, 0)
+ p.scanner.Init(p.file, src, p, scanner.AllowIllegalChars)
p.next() // initializes pos, tok, lit
// process source