MCPcopy
hub / github.com/perkeep/perkeep / ParseDeps

Function ParseDeps

internal/closure/gendeps.go:158–199  ·  view source on GitHub ↗

ParseDeps reads closure namespace dependency lines and returns a map giving the js file provider for each namespace, and a map giving the namespace dependencies for each namespace.

(r io.Reader)

Source from the content-addressed store, hash-verified

156// returns a map giving the js file provider for each namespace,
157// and a map giving the namespace dependencies for each namespace.
158func ParseDeps(r io.Reader) (providedBy map[string]string, requires map[string][]string, err error) {
159 providedBy = make(map[string]string)
160 requires = make(map[string][]string)
161 scanner := bufio.NewScanner(r)
162 for scanner.Scan() {
163 l := scanner.Text()
164 if strings.HasPrefix(l, "//") {
165 continue
166 }
167 if l == "" {
168 continue
169 }
170 m := depsRx.FindStringSubmatch(l)
171 if m == nil {
172 return nil, nil, fmt.Errorf("Invalid line in deps: %q", l)
173 }
174 jsfile := m[1]
175 provides := strings.Split(m[2], ", ")
176 var required []string
177 if m[5] != "" {
178 required = strings.Split(
179 strings.Replace(strings.Replace(m[5], "'", "", -1), `"`, "", -1), ", ")
180 }
181 for _, v := range provides {
182 namespace := strings.Trim(v, `'"`)
183 if otherjs, ok := providedBy[namespace]; ok {
184 return nil, nil, fmt.Errorf("Name %v is provided by both %v and %v", namespace, jsfile, otherjs)
185 }
186 providedBy[namespace] = jsfile
187 if _, ok := requires[namespace]; ok {
188 return nil, nil, fmt.Errorf("Name %v has two sets of dependencies", namespace)
189 }
190 if required != nil {
191 requires[namespace] = required
192 }
193 }
194 }
195 if err := scanner.Err(); err != nil {
196 return nil, nil, err
197 }
198 return providedBy, requires, nil
199}
200
201// DeepParseDeps reads closure namespace dependency lines and
202// returns a map giving all the required js files for each namespace.

Callers 3

fileListFunction · 0.92
DeepParseDepsFunction · 0.85
TestParseDepsFunction · 0.85

Calls 3

HasPrefixMethod · 0.80
TextMethod · 0.65
ErrMethod · 0.45

Tested by 1

TestParseDepsFunction · 0.68