{.section Decls}
<h2>Package-level declarations</h2>
{.repeated section @}
- <h3>package {Pak.Name|html}</h3>
+ <h3>package <a href="{Pak.Path|path}" class="noline">{Pak.Name|html}</a></h3>
{.repeated section Files}
{.repeated section Groups}
{.repeated section Infos}
{.section Others}
<h2>Local declarations and uses</h2>
{.repeated section @}
- <h3>package {Pak.Name|html}</h3>
+ <h3>package <a href="{Pak.Path|path}" class="noline">{Pak.Name|html}</a></h3>
{.repeated section Files}
<a href="{File.Path|html}?h={Query|html}" class="noline">{File.Path|html}</a>
<table class="layout">
{.end}
{.end}
{.end}
-{.or}
+{.end}
+{.section Illegal}
+ <p>
+ <span class="alert" style="font-size:120%">Illegal query syntax</span>
+ </p>
<p>
A legal query is a single identifier (such as <a href="search?q=ToLower">ToLower</a>)
or a qualified identifier (such as <a href="search?q=math.Sin">math.Sin</a>).
"go/ast";
"go/parser";
"go/token";
+ "go/scanner";
"os";
pathutil "path";
"sort";
// ----------------------------------------------------------------------------
// Indexer
+// Adjust these flags as seems best.
+const excludeMainPackages = false
+const excludeTestFiles = false
+
+
type IndexResult struct {
Decls RunList; // package-level declarations (with snippets)
Others RunList; // all other occurences
return;
}
+ if excludeTestFiles && (!isPkgFile(d) || strings.HasPrefix(path, "test/")) {
+ return;
+ }
+
+ if excludeMainPackages && pkgName(path) == "main" {
+ return;
+ }
+
file, err := parser.ParseFile(path, nil, parser.ParseComments);
if err != nil {
return; // ignore files with (parse) errors
}
-// For a given string s, which is either a single identifier or a qualified
+func isIdentifier(s string) bool {
+ var S scanner.Scanner;
+ S.Init("", strings.Bytes(s), nil, 0);
+ if _, tok, _ := S.Scan(); tok == token.IDENT {
+ _, tok, _ := S.Scan();
+ return tok == token.EOF;
+ }
+ return false;
+}
+
+
+// For a given query, which is either a single identifier or a qualified
// identifier, Lookup returns a LookupResult, and a list of alternative
-// spellings, if any.
-func (x *Index) Lookup(s string) (match *LookupResult, alt *AltWords) {
- ss := strings.Split(s, ".", 0);
+// spellings, if any. If the query syntax is wrong, illegal is set.
+func (x *Index) Lookup(query string) (match *LookupResult, alt *AltWords, illegal bool) {
+ ss := strings.Split(query, ".", 0);
+
+ // check query syntax
+ for _, s := range ss {
+ if !isIdentifier(s) {
+ illegal = true;
+ return;
+ }
+ }
switch len(ss) {
case 1:
others := match.Others.filter(pakname);
match = &LookupResult{decls, others};
}
- if alt != nil {
- // alternative spellings found - add package name
- // TODO(gri): At the moment this is not very smart
- // and likely will produce suggestions that have
- // no match. Should filter incorrect alternatives.
- canon := pakname + "." + alt.Canon; // for completeness (currently not used)
- alts := make([]string, len(alt.Alts));
- for i, a := range alt.Alts {
- alts[i] = pakname+"."+a;
- }
- alt = &AltWords{canon, alts};
- }
+
+ default:
+ illegal = true;
}
return;