golang

package module
v0.2.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 5, 2025 License: GPL-3.0 Imports: 15 Imported by: 0

README

gopher

gopher is a code visible Golang parser

Usage

gopher \
  --project=kubernetes-1.12.0 \
  --directory=. \
  --dump=dist/kubernets.json \
  --module=k8s.io/kubernetes \
  --excludes=vendor,logo,.\*,tests \
  --types=\*.json,\*.yaml,README.md

Language Protocol

code visible protocol definition

LICENSE

GPL-3.0

Documentation

Index

Constants

View Source
const (
	CallTypeBuiltin  = "builtin"
	CallTypeStd      = "std"
	CallTypeInternal = "internal"
	CallTypeExternal = "external"
	CallTypePackage  = "package"
)
View Source
const DEFAULT_EXCLUDE_DIRECTORIES = ".*,testdata,tests,vendors,changelogs,scripts,docs,contrib,hack"
View Source
const DEFAULT_INCLUDE_FILE_TYPES = "README.md,LICENSE,go.mod,go.sum,*.json,*.yaml,*.yml,*.toml,Dockerfile"
View Source
const DEFAULT_SHOULD_PARSE_TEST = false
View Source
const LANG = "Golang"
View Source
const PARSER = "gopher"
View Source
const PARSER_TYPE = "Golang"
View Source
const PARSE_TYPE_MINIFY = "minify"
View Source
const PARSE_TYPE_NORMAL = "normal"
View Source
const VERSION = "v0.2.0-beta"

Variables

View Source
var Builtins = map[string]byte{
	"len":     0,
	"append":  0,
	"delete":  0,
	"make":    0,
	"string":  0,
	"int":     0,
	"uint":    0,
	"uintptr": 0,
	"int8":    0,
	"uint8":   0,
	"int16":   0,
	"uint16":  0,
	"int32":   0,
	"uint32":  0,
	"int64":   0,
	"uint64":  0,
	"float32": 0,
	"float64": 0,
	"new":     0,
	"panic":   0,
	"defer":   0,
	"copy":    0,
	"byte":    0,
	"close":   0,
	"rune":    0,
}
View Source
var Libs = map[string]byte{
	"archive":       0,
	"arena":         0,
	"bufio":         0,
	"builtin":       0,
	"bytes":         0,
	"cmd":           0,
	"cmp":           0,
	"compress":      0,
	"container":     0,
	"context":       0,
	"crypto":        0,
	"database":      0,
	"database/sql":  0,
	"debug":         0,
	"embed":         0,
	"encoding":      0,
	"encoding/hex":  0,
	"errors":        0,
	"expvars":       0,
	"flag":          0,
	"fmt":           0,
	"go":            0,
	"hash":          0,
	"html":          0,
	"image":         0,
	"index":         0,
	"io":            0,
	"log":           0,
	"maps":          0,
	"math":          0,
	"mime":          0,
	"net":           0,
	"net/netip":     0,
	"os":            0,
	"path":          0,
	"path/filepath": 0,
	"plugin":        0,
	"reflect":       0,
	"regexp":        0,
	"runtime":       0,
	"slices":        0,
	"sort":          0,
	"strconv":       0,
	"strings":       0,
	"sync":          0,
	"sync/atomic":   0,
	"syscall":       0,
	"testing":       0,
	"text":          0,
	"time":          0,
	"unicode":       0,
	"unsafe":        0,
	"net/http":      0,
}

common std lib cd /usr/local/go/src/ && ls -d */ | cut -f1 -d'/'

Functions

This section is empty.

Types

type Abstract

type Abstract struct {
	ID      string   `json:"id"`
	Pos     string   `json:"pos"`
	Name    string   `json:"name"`
	File    string   `json:"file"`
	Pkg     string   `json:"pkg"`
	Comment string   `json:"comment"`
	Fields  []string `json:"fields"`
	// contains filtered or unexported fields
}

func NewAbstract

func NewAbstract(ident *ast.Ident, strtTyp *ast.StructType, file *File) *Abstract

func (*Abstract) Complete

func (a *Abstract) Complete()

func (*Abstract) LookupName

func (a *Abstract) LookupName() string

func (*Abstract) SetupID

func (a *Abstract) SetupID()

type Call

type Call struct {
	ID        string `json:"id"`
	Pos       string `json:"pos"`
	Caller    string `json:"caller"`
	Callee    string `json:"callee"`
	File      string `json:"file"`
	Typ       string `json:"typ"`
	Signature string `json:"signature"`
	Dep       string `json:"dep"`
	// contains filtered or unexported fields
}

func NewCall

func NewCall(pos token.Pos, scope string, selector string, typ *parsedtypes.Type, file *File) *Call

func (*Call) Complete

func (c *Call) Complete()

func (*Call) LookupName

func (c *Call) LookupName() string

func (*Call) SetupID

func (c *Call) SetupID()

type Callable

type Callable struct {
	ID         string   `json:"id"`
	Pos        string   `json:"pos"`
	Name       string   `json:"name"`
	Signature  string   `json:"signature"`
	Abstract   string   `json:"abstract"`
	File       string   `json:"file"`
	Pkg        string   `json:"pkg"`
	Comment    string   `json:"comment"`
	Parameters []string `json:"parameters"`
	Results    []string `json:"results"`
	Method     bool     `json:"method"`
	Private    bool     `json:"private"`
	// contains filtered or unexported fields
}

func NewCallable

func NewCallable(decl *ast.FuncDecl, file *File) *Callable

func (*Callable) Complete

func (c *Callable) Complete()

func (*Callable) LookupName

func (c *Callable) LookupName() string

func (*Callable) SetupID

func (c *Callable) SetupID()

func (*Callable) SetupMethod

func (c *Callable) SetupMethod()

type Dep

type Dep struct {
	ID   string `json:"id"`
	Name string `json:"name"`
	Typ  string `json:"type"`
	Ref  string `json:"ref"`
	// contains filtered or unexported fields
}

func NewDep

func NewDep(name string, imp *ast.ImportSpec) *Dep

func NewPkgDep

func NewPkgDep(name string, pkg *Pkg) *Dep

func (*Dep) SetupID

func (d *Dep) SetupID()

func (*Dep) SetupRef

func (d *Dep) SetupRef()

type File

type File struct {
	ID      string   `json:"id"`
	Name    string   `json:"name"`
	Path    string   `json:"path"`
	Pkg     string   `json:"pkg"`
	Deps    []string `json:"deps"`
	Imports []string `json:"imports"`
	// contains filtered or unexported fields
}

func NewSourceFile

func NewSourceFile(path string, name string, sm *SourceMap, sf *SourceFile, pkg *Pkg) *File

func (*File) BuildDeps

func (f *File) BuildDeps()

func (*File) EnumerateDecls

func (f *File) EnumerateDecls()

func (*File) InjectDeps

func (f *File) InjectDeps()

func (*File) LookupAbstract

func (f *File) LookupAbstract(name string) *Abstract

func (*File) LookupCallable

func (f *File) LookupCallable(name string) *Callable

func (*File) LookupDepByScope

func (f *File) LookupDepByScope(scope string) *Dep

func (*File) LookupName

func (f *File) LookupName() string

func (*File) SearchCalls

func (f *File) SearchCalls()

func (*File) SetupID

func (f *File) SetupID()

type Pkg

type Pkg struct {
	ID       string   `json:"id"`
	Name     string   `json:"name"`
	FullName string   `json:"fullName"`
	Path     string   `json:"path"`
	Imports  []string `json:"imports"`
	// contains filtered or unexported fields
}

func NewSourcePkg

func NewSourcePkg(path_ string, name string, sm *SourceMap, sd *SourceDir, p *Project) *Pkg

func (*Pkg) Abstracts

func (p *Pkg) Abstracts() []*Abstract

func (*Pkg) Callables

func (p *Pkg) Callables() []*Callable

func (*Pkg) Calls

func (p *Pkg) Calls() []*Call

func (*Pkg) InjectImports

func (p *Pkg) InjectImports()

func (*Pkg) LookupAbstract

func (p *Pkg) LookupAbstract(name string) *Abstract

func (*Pkg) LookupCallable

func (p *Pkg) LookupCallable(name string) *Callable

func (*Pkg) LookupName

func (p *Pkg) LookupName() string

func (*Pkg) SetupID

func (p *Pkg) SetupID()

type Project

type Project struct {
	Name       string       `json:"name"`
	Lang       string       `json:"lang"`
	Parser     string       `json:"parser"`
	Timestamp  string       `json:"timestamp"`
	Repository string       `json:"repository"`
	Typ        string       `json:"typ"`
	Version    string       `json:"version"`
	Pkgs       []*Pkg       `json:"pkgs"`
	Files      []*File      `json:"files"`
	Abstracts  []*Abstract  `json:"absts"`
	Callables  []*Callable  `json:"fns"`
	Calls      []*Call      `json:"calls"`
	References []*Reference `json:"refs"`
	Deps       []*Dep       `json:"deps"`
	// contains filtered or unexported fields
}

func NewProject

func NewProject(project, directory, excludes, module, types string) *Project

func (*Project) Initialize

func (p *Project) Initialize()

scan the whole project to get the directories and files

func (*Project) Parse

func (p *Project) Parse()

parse all the files to find out the nodes we are interested at

type ProjectMinify

type ProjectMinify struct {
	Name       string  `json:"name"`
	Lang       string  `json:"lang"`
	Parser     string  `json:"parser"`
	Timestamp  string  `json:"timestamp"`
	Repository string  `json:"repository"`
	Version    string  `json:"version"`
	Typ        string  `json:"typ"`
	Abstracts  uint64  `json:"absts"`
	Callables  uint64  `json:"fns"`
	Calls      uint64  `json:"calls"`
	References uint64  `json:"refs"`
	Deps       uint64  `json:"deps"`
	Pkgs       []*Pkg  `json:"pkgs"`
	Files      []*File `json:"files"`
}

type Reference

type Reference struct {
	ID   string `json:"id"`
	Pos  string `json:"pos"`
	File string `json:"file"`
}

type SourceDir

type SourceDir struct {
	Path  string
	Files int
	Pkg   bool
}

type SourceFile

type SourceFile struct {
	Path     string
	Name     string
	Dir      *SourceDir
	AST      *ast.File
	GoSource bool
	Test     bool
	Error    string
}

func (*SourceFile) Parse2AST

func (sf *SourceFile) Parse2AST(fset *token.FileSet)

type SourceMap

type SourceMap struct {
	// contains filtered or unexported fields
}

read-only source map of the project

func NewSourceMap

func NewSourceMap(project, directory, excludes, module, types string) *SourceMap

func (*SourceMap) Dirs

func (sm *SourceMap) Dirs() []*SourceDir

func (*SourceMap) FileSet

func (sm *SourceMap) FileSet() *token.FileSet

func (*SourceMap) Files

func (sm *SourceMap) Files() []*SourceFile

func (*SourceMap) Module

func (sm *SourceMap) Module() string

func (*SourceMap) Path

func (sm *SourceMap) Path() string

func (*SourceMap) Scan

func (sm *SourceMap) Scan()

Directories

Path Synopsis
cmd
graphy command
outline command

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL