MCPcopy Create free account
hub / github.com/GuyARoss/orbit / Parse

Method Parse

pkg/jsparse/parser.go:35–64  ·  view source on GitHub ↗
(pageDir string, webDir string)

Source from the content-addressed store, hash-verified

33}
34
35func (p *JSFileParser) Parse(pageDir string, webDir string) (JSDocument, error) {
36 if len(pageDir) >= 2 && pageDir[0:2] != "./" {
37 pageDir = fmt.Sprintf("./%s", pageDir)
38 }
39
40 file, err := os.Open(pageDir)
41 if err != nil {
42 return nil, err
43 }
44 defer file.Close()
45
46 scanner := bufio.NewScanner(file)
47 scanner.Split(bufio.ScanLines)
48
49 page := NewDocument(webDir, pageDir)
50
51 ctx := context.Background()
52 for scanner.Scan() {
53 ctx, err = page.tokenizeLine(ctx, pageDir, scanner.Text())
54 if err != nil {
55 return nil, err
56 }
57 }
58
59 if page.name == "" {
60 page.name = defaultPageName(pageDir)
61 }
62
63 return page, nil
64}
65
66// FunctionDefinition is a light-weight struct to define JS function definition
67type FunctionDefinition struct {

Callers

nothing calls this directly

Calls 4

NewDocumentFunction · 0.85
defaultPageNameFunction · 0.85
tokenizeLineMethod · 0.80
CloseMethod · 0.65

Tested by

no test coverage detected