summaryrefslogtreecommitdiff
path: root/src/cmd
diff options
context:
space:
mode:
authorRobert Griesemer <gri@golang.org>2011-01-13 17:20:26 -0800
committerRobert Griesemer <gri@golang.org>2011-01-13 17:20:26 -0800
commit41e32ec48809ac12d205575b935f397bb35fb91d (patch)
tree4161b369b8a694442f97bb72ca57383d00e8f8a2 /src/cmd
parenta9c6c8d5435ecbea5616f5913cd9988a9c71262c (diff)
downloadgo-41e32ec48809ac12d205575b935f397bb35fb91d.tar.gz
go/scanner: Make Init take a *token.File instead of a *token.FileSet.
Until now, each scan of a file added a new file to the file set. With this change, a file can be re-scanned using the same *token.File w/o changing the file set. Eventually this will enable the re-use of cached source code in godoc (for the fulltext index). At the moment, source files are read over and over again from disk. This is the first step in that direction. R=r, rsc, r2 CC=golang-dev http://codereview.appspot.com/4001041 Committer: Robert Griesemer <gri@golang.org>
Diffstat (limited to 'src/cmd')
-rw-r--r--src/cmd/godoc/format.go4
-rw-r--r--src/cmd/godoc/index.go3
-rw-r--r--src/cmd/godoc/spec.go3
3 files changed, 7 insertions, 3 deletions
diff --git a/src/cmd/godoc/format.go b/src/cmd/godoc/format.go
index c6fd90eeb..d789ed55b 100644
--- a/src/cmd/godoc/format.go
+++ b/src/cmd/godoc/format.go
@@ -239,7 +239,9 @@ func lineSelection(text []byte) Selection {
//
func commentSelection(src []byte) Selection {
var s scanner.Scanner
- file := s.Init(token.NewFileSet(), "", src, nil, scanner.ScanComments+scanner.InsertSemis)
+ fset := token.NewFileSet()
+ file := fset.AddFile("", fset.Base(), len(src))
+ s.Init(file, src, nil, scanner.ScanComments+scanner.InsertSemis)
return func() (seg []int) {
for {
pos, tok, lit := s.Scan()
diff --git a/src/cmd/godoc/index.go b/src/cmd/godoc/index.go
index ba6fe9acd..0fe8c73b4 100644
--- a/src/cmd/godoc/index.go
+++ b/src/cmd/godoc/index.go
@@ -817,7 +817,8 @@ func (x *Index) LookupWord(w string) (match *LookupResult, alt *AltWords) {
func isIdentifier(s string) bool {
var S scanner.Scanner
- S.Init(token.NewFileSet(), "", []byte(s), nil, 0)
+ fset := token.NewFileSet()
+ S.Init(fset.AddFile("", fset.Base(), len(s)), []byte(s), nil, 0)
if _, tok, _ := S.Scan(); tok == token.IDENT {
_, tok, _ := S.Scan()
return tok == token.EOF
diff --git a/src/cmd/godoc/spec.go b/src/cmd/godoc/spec.go
index b1c1a883f..a533c1e0a 100644
--- a/src/cmd/godoc/spec.go
+++ b/src/cmd/godoc/spec.go
@@ -156,7 +156,8 @@ func (p *ebnfParser) parse(fset *token.FileSet, out io.Writer, src []byte) {
// initialize ebnfParser
p.out = out
p.src = src
- p.file = p.scanner.Init(fset, "", src, p, 0)
+ p.file = fset.AddFile("", fset.Base(), len(src))
+ p.scanner.Init(p.file, src, p, 0)
p.next() // initializes pos, tok, lit
// process source