Skip to content

Commit

Permalink
Refactor parser map -> parser factory
Browse files Browse the repository at this point in the history
  • Loading branch information
jtibshirani committed Nov 21, 2023
1 parent a6e015f commit 6863a52
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
10 changes: 5 additions & 5 deletions build/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,8 +249,8 @@ type Builder struct {
docChecker zoekt.DocChecker
size int

parserMap ctags.ParserMap
building sync.WaitGroup
parserFactory ctags.ParserFactory
building sync.WaitGroup

errMu sync.Mutex
buildError error
Expand Down Expand Up @@ -563,7 +563,7 @@ func NewBuilder(opts Options) (*Builder, error) {
finishedShards: map[string]string{},
}

parserMap, err := ctags.NewParserMap(
parserFactory, err := ctags.NewParserFactory(
ctags.ParserBinMap{
ctags.UniversalCTags: b.opts.CTagsPath,
ctags.ScipCTags: b.opts.ScipCTagsPath,
Expand All @@ -576,7 +576,7 @@ func NewBuilder(opts Options) (*Builder, error) {
return nil, err
}

b.parserMap = parserMap
b.parserFactory = parserFactory

b.shardLogger = &lumberjack.Logger{
Filename: filepath.Join(opts.IndexDir, "zoekt-builder-shard-log.tsv"),
Expand Down Expand Up @@ -1021,7 +1021,7 @@ func sortDocuments(todo []*zoekt.Document) {

func (b *Builder) buildShard(todo []*zoekt.Document, nextShardNum int) (*finishedShard, error) {
if !b.opts.DisableCTags && (b.opts.CTagsPath != "" || b.opts.ScipCTagsPath != "") {
err := ctagsAddSymbolsParserMap(todo, b.opts.LanguageMap, b.parserMap)
err := parseSymbols(todo, b.opts.LanguageMap, b.parserFactory)
if b.opts.CTagsMustSucceed && err != nil {
return nil, err
}
Expand Down
4 changes: 2 additions & 2 deletions build/ctags.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func normalizeLanguage(filetype string) string {
return normalized
}

func ctagsAddSymbolsParserMap(todo []*zoekt.Document, languageMap ctags.LanguageMap, parserMap ctags.ParserMap) error {
func parseSymbols(todo []*zoekt.Document, languageMap ctags.LanguageMap, parserFactory ctags.ParserFactory) error {
monitor := newMonitor()
defer monitor.Stop()

Expand All @@ -65,7 +65,7 @@ func ctagsAddSymbolsParserMap(todo []*zoekt.Document, languageMap ctags.Language
parserKind = ctags.UniversalCTags
}

parser := parserMap[parserKind]
parser := parserFactory[parserKind]
if parser == nil {
// this happens if CTagsMustSucceed is false and we didn't find the binary
continue
Expand Down
8 changes: 4 additions & 4 deletions ctags/parser_map.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,11 @@ func StringToParser(str string) CTagsParserType {
}
}

type ParserMap map[CTagsParserType]Parser
type ParserFactory map[CTagsParserType]Parser
type ParserBinMap map[CTagsParserType]string

func NewParserMap(bins ParserBinMap, languageMap LanguageMap, cTagsMustSucceed bool) (ParserMap, error) {
parsers := make(ParserMap)
func NewParserFactory(bins ParserBinMap, languageMap LanguageMap, cTagsMustSucceed bool) (ParserFactory, error) {
parsers := make(ParserFactory)

requiredTypes := []CTagsParserType{UniversalCTags}
for _, parserType := range languageMap {
Expand All @@ -81,7 +81,7 @@ func NewParserMap(bins ParserBinMap, languageMap LanguageMap, cTagsMustSucceed b
}

if err := checkBinary(parserType, bin); err != nil && cTagsMustSucceed {
return nil, fmt.Errorf("ctags.NewParserMap: %v", err)
return nil, fmt.Errorf("ctags.NewParserFactory: %v", err)
}

parsers[parserType] = NewParser(bin)
Expand Down

0 comments on commit 6863a52

Please sign in to comment.