Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ go 1.23.0

require (
github.com/Knetic/govaluate v3.0.0+incompatible
github.com/davecgh/go-spew v1.1.1
github.com/sourcegraph/go-lsp v0.0.0-20240223163137-f80c5dd31dfd
github.com/sourcegraph/jsonrpc2 v0.2.0
github.com/stretchr/testify v1.10.0
Expand All @@ -13,6 +12,7 @@ require (
)

require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
golang.org/x/sync v0.13.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
Expand Down
89 changes: 0 additions & 89 deletions lang/golang/parser/go_ast.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,100 +15,11 @@
package parser

import (
"bytes"
"encoding/json"
"flag"
"fmt"
"os"
"strings"

. "github.com/cloudwego/abcoder/lang/uniast"
)

var (
referCodeDepth int
collectComment bool
excludes string
)

func init() {
// init args with flags
flag.Usage = func() {
fmt.Fprintf(os.Stderr, "Usage: %s [options] <RepoDir> [id]\n", os.Args[0])
flag.PrintDefaults()
}
flag.BoolVar(&collectComment, "collect_comment", false, "collect comments for each node")
flag.IntVar(&referCodeDepth, "refer_code_depth", 0, "the depth to referenced codes, 0 means only return its identity")
flag.StringVar(&excludes, "excludes", "", "exclude paths, seperated by comma")
}

func Main() {
var err error
defer func() {
if err != nil {
fmt.Fprintln(os.Stderr, err.Error())
}
}()
flag.Parse()
as := flag.Args()
if len(as) < 1 {
flag.Usage()
os.Exit(1)
}

homeDir := as[0]
id := ""
if len(as) >= 2 {
id = as[1]
}

var exs []string
if excludes != "" {
exs = strings.Split(excludes, ",")
}
// p := NewParser(homeDir, homeDir, WithReferCodeDepth(referCodeDepth), WithExcludes(exs), WithCollectComment(collectComment))
p := NewParser(homeDir, homeDir, Options{
ReferCodeDepth: referCodeDepth,
Excludes: exs,
CollectComment: collectComment,
})

var out interface{}

if id == "" {
// parse whole repo
if out, err = p.ParseRepo(); err != nil {
return
}
} else {
// SPEC: seperate the packagepath and entity name by #
ids := strings.Split(id, "#")

if len(ids) == 1 {
// parse pacakge
pkgPath := ids[0]
if out, err = p.ParsePackage(pkgPath); err != nil {
return
}
} else if len(ids) == 2 {
if out, err = p.ParseNode(ids[0], ids[1]); err != nil {
return
}
}
}

buf := bytes.NewBuffer(nil)
encoder := json.NewEncoder(buf)
encoder.SetEscapeHTML(false)
err = encoder.Encode(out)
if err != nil {
fmt.Fprintln(os.Stderr, "Error marshalling functions to JSON:", err)
os.Exit(1)
}

fmt.Println(buf.String())
}

func loadNode(p *GoParser, pkgPath string, name string, out *Repository) error {
mod, _ := p.getModuleFromPkg(pkgPath)
np, err := p.getNode(NewIdentity(mod, PkgPath(pkgPath), name))
Expand Down