core

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Dec 15, 2022 License: Apache-2.0 Imports: 11 Imported by: 7

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Log = NewLogger()
View Source
var SupportedLangs = []LangType{
	LangJava,
	LangGo,
	LangPython,
}

Functions

func NewLogger

func NewLogger() *zap.SugaredLogger

Types

type FileUnit

type FileUnit struct {
	Path     string   `json:"path"`
	Language LangType `json:"language"`
	Units    []*Unit  `json:"units"`
}

type KindRepr

type KindRepr = string

type LangType

type LangType string
const (
	LangJava    LangType = "JAVA"
	LangGo      LangType = "GOLANG"
	LangPython  LangType = "PYTHON"
	LangUnknown LangType = "UNKNOWN"
)

func LangTypeValueOf

func LangTypeValueOf(raw string) LangType

func (LangType) GetFileSuffix

func (langType LangType) GetFileSuffix() string

func (LangType) GetLanguage

func (langType LangType) GetLanguage() *sitter.Language

func (LangType) GetValue

func (langType LangType) GetValue() string

func (LangType) IsSupported

func (langType LangType) IsSupported() bool

func (LangType) MatchName

func (langType LangType) MatchName(name string) bool

type Parser

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

Parser

- get almost all the nodes - convert them to units

func NewParser

func NewParser(lang LangType) *Parser

func (*Parser) Parse

func (p *Parser) Parse(data []byte) ([]*Unit, error)

func (*Parser) ParseCtx

func (p *Parser) ParseCtx(data []byte, context context.Context) ([]*Unit, error)

func (*Parser) ParseString

func (p *Parser) ParseString(data string) ([]*Unit, error)

func (*Parser) ParseStringCtx

func (p *Parser) ParseStringCtx(data string, context context.Context) ([]*Unit, error)

type Point

type Point struct {
	// NOTICE: INDEX, NOT REAL LINE NUMBER
	Row    uint32 `json:"row"`
	Column uint32 `json:"column"`
}

type Query

type Query struct {
	IsDfs        bool
	IsTop2Bottom bool
	Kinds        []string
	FieldNames   []string
	// contains filtered or unexported fields
}

func NewQuery

func NewQuery(target *Unit) *Query

func (*Query) All

func (q *Query) All() []*Unit

func (*Query) Bfs

func (q *Query) Bfs() *Query

func (*Query) Bottom2Top

func (q *Query) Bottom2Top() *Query

func (*Query) Dfs

func (q *Query) Dfs() *Query

func (*Query) First

func (q *Query) First() *Unit

func (*Query) MatchField

func (q *Query) MatchField(fieldName string) *Query

func (*Query) MatchKind

func (q *Query) MatchKind(kind string) *Query

func (*Query) Top2Bottom

func (q *Query) Top2Bottom() *Query

type Runner

type Runner struct {
}

Runner

binding to file system

func (*Runner) File2Units

func (r *Runner) File2Units(path string, lang LangType, fileFilter func(string) bool) ([]*FileUnit, error)

func (*Runner) GuessLangFromDir

func (r *Runner) GuessLangFromDir(dir string, fileFilter func(string) bool) (LangType, error)

type Span

type Span struct {
	Start Point `json:"start"`
	End   Point `json:"end"`
}

func (*Span) ContainAnyLine

func (s *Span) ContainAnyLine(lineNums ...int) bool

func (*Span) ContainLine

func (s *Span) ContainLine(lineNum int) bool

func (*Span) HasInteraction

func (s *Span) HasInteraction(another *Span) bool

func (*Span) Lines

func (s *Span) Lines() []int

func (*Span) MatchAny

func (s *Span) MatchAny(target *Span) bool

func (*Span) String

func (s *Span) String() string

type Unit

type Unit struct {
	Kind      KindRepr `json:"kind"`
	Span      Span     `json:"span"`
	FieldName string   `json:"fieldName"`
	Content   string   `json:"content"`

	// double linked
	ParentUnit *Unit
	SubUnits   []*Unit
}

Unit

almost a node, but with enough data for analyzer. no need to access raw byte data again

func DebugDfs

func DebugDfs(unit *Unit, layer int) *Unit

func FindAll

func FindAll(unit *Unit) []*Unit

func FindAllByKindInParent

func FindAllByKindInParent(unit *Unit, kind KindRepr) []*Unit

func FindAllByKindInSubs

func FindAllByKindInSubs(unit *Unit, kind string) []*Unit

func FindAllByKindInSubsWithBfs

func FindAllByKindInSubsWithBfs(unit *Unit, kind KindRepr) []*Unit

func FindAllByKindInSubsWithDfs

func FindAllByKindInSubsWithDfs(unit *Unit, kind KindRepr) []*Unit

func FindAllByKindsInSubs

func FindAllByKindsInSubs(unit *Unit, kinds ...string) []*Unit

func FindAllByOneOfKindInParent

func FindAllByOneOfKindInParent(unit *Unit, kinds ...KindRepr) []*Unit

func FindFirstByFieldInSubs

func FindFirstByFieldInSubs(unit *Unit, fieldName string) *Unit

func FindFirstByFieldInSubsWithBfs

func FindFirstByFieldInSubsWithBfs(unit *Unit, fieldName string) *Unit

func FindFirstByFieldInSubsWithDfs

func FindFirstByFieldInSubsWithDfs(unit *Unit, fieldName string) *Unit

func FindFirstByKindInParent

func FindFirstByKindInParent(unit *Unit, kind KindRepr) *Unit

func FindFirstByKindInSubsWithBfs

func FindFirstByKindInSubsWithBfs(unit *Unit, kind KindRepr) *Unit

func FindFirstByKindInSubsWithDfs

func FindFirstByKindInSubsWithDfs(unit *Unit, kind KindRepr) *Unit

func FindFirstByOneOfKindInParent

func FindFirstByOneOfKindInParent(unit *Unit, kinds ...KindRepr) *Unit

Jump to

Keyboard shortcuts

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