MCPcopy Create free account
hub / github.com/php/frankenphp / parse

Method parse

internal/extgen/nsparser.go:16–44  ·  view source on GitHub ↗
(filename string)

Source from the content-addressed store, hash-verified

14var namespaceRegex = regexp.MustCompile(`//\s*export_php:namespace\s+(.+)`)
15
16func (np *NamespaceParser) parse(filename string) (foundNamespace string, err error) {
17 file, err := os.Open(filename)
18 if err != nil {
19 return "", err
20 }
21
22 defer func() {
23 err = errors.Join(err, file.Close())
24 }()
25
26 var lineNumber, foundLineNumber int
27
28 scanner := bufio.NewScanner(file)
29 for scanner.Scan() {
30 lineNumber++
31 line := strings.TrimSpace(scanner.Text())
32 if matches := namespaceRegex.FindStringSubmatch(line); matches != nil {
33 namespace := strings.TrimSpace(matches[1])
34 if foundNamespace != "" {
35 return "", fmt.Errorf("multiple namespace declarations found: first at line %d, second at line %d", foundLineNumber, lineNumber)
36 }
37
38 foundNamespace = namespace
39 foundLineNumber = lineNumber
40 }
41 }
42
43 return foundNamespace, scanner.Err()
44}

Callers 2

ParseNamespaceMethod · 0.95
TestNamespaceParserFunction · 0.95

Calls 1

CloseMethod · 0.80

Tested by 1

TestNamespaceParserFunction · 0.76