Beispiel #1
0
// Pkgs lists all the packages inside this home folder.
func (h *DirHome) Pkgs(prefix string) []string {
	root := filepath.Join(h.path, "src")
	start := filepath.Join(root, prefix)
	var pkgs []string

	walkFunc := func(p string, info os.FileInfo, e error) error {
		if e != nil {
			return e
		}

		if !info.IsDir() {
			return nil
		} else if !lex8.IsPkgName(info.Name()) {
			return filepath.SkipDir
		}

		if root == p {
			return nil
		}

		path, e := filepath.Rel(root, p)
		if e != nil {
			panic(e)
		} else if path == "." {
			return nil
		}

		lang := h.Lang(path)
		if lang == nil {
			panic(path)
		}

		files, e := listSrcFiles(p, lang)
		if e != nil {
			return e
		}

		if len(files) > 0 {
			h.fileList[path] = files // caching
			pkgs = append(pkgs, path)
		}

		return nil
	}

	e := filepath.Walk(start, walkFunc)
	if e != nil && !h.Quiet {
		log.Fatal("error", e)
	}

	sort.Strings(pkgs)
	return pkgs
}
Beispiel #2
0
func isPkgPath(p string) bool {
	if p == "" {
		return false
	}
	subs := strings.Split(p, "/")
	for _, sub := range subs {
		if !lex8.IsPkgName(sub) {
			return false
		}
	}
	return true
}
Beispiel #3
0
func parseSym(p lex8.Logger, t *lex8.Token) (pack, sym string) {
	if t.Type != parse.Operand {
		panic("symbol not an operand")
	}

	sym = t.Lit
	dot := strings.Index(sym, ".")
	if dot >= 0 {
		pack, sym = sym[:dot], sym[dot+1:]
	}

	if dot >= 0 && !lex8.IsPkgName(pack) {
		p.Errorf(t.Pos, "invalid package name: %q", pack)
	} else if !parse.IsIdent(sym) {
		p.Errorf(t.Pos, "invalid symbol: %q", t.Lit)
	}

	return pack, sym
}