parse

package
v0.0.0-...-6320ad3 Latest Latest
Warning

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

Go to latest
Published: Feb 8, 2026 License: MIT Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func PrintSyntaxTree

func PrintSyntaxTree(ctx context.Context, tsNode *tree_sitter.Node, content []byte) string

Types

type CSharpVisitor

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

CSharpVisitor handles traversal of C# syntax trees

func NewCSharpVisitor

func NewCSharpVisitor(logger *zap.Logger, ts *TranslateFromSyntaxTree) *CSharpVisitor

NewCSharpVisitor creates a new C# visitor instance

func (*CSharpVisitor) GetName

func (cv *CSharpVisitor) GetName(tsNode *tree_sitter.Node) string

GetName extracts the proper name from a C# node considering special naming conventions

func (*CSharpVisitor) HasSpecialName

func (cv *CSharpVisitor) HasSpecialName(kind string) bool

HasSpecialName returns true for C# node kinds that have special naming conventions

func (*CSharpVisitor) TraverseNode

func (cv *CSharpVisitor) TraverseNode(ctx context.Context, tsNode *tree_sitter.Node, scopeID ast.NodeID) ast.NodeID

TraverseNode traverses a C# syntax tree node and returns the created AST node ID

type FileParser

type FileParser struct {
	CodeGraph *codegraph.CodeGraph

	Config *config.Config
	// contains filtered or unexported fields
}

func NewFileParser

func NewFileParser(logger *zap.Logger, cg *codegraph.CodeGraph, cfg *config.Config) *FileParser

func (*FileParser) CreateTranslator

func (fp *FileParser) CreateTranslator(ctx context.Context, filePath string, fileID int32, langType LanguageType, version int32) (*tree_sitter.Tree, *TranslateFromSyntaxTree, error)

func (*FileParser) CreateTranslatorWithContent

func (fp *FileParser) CreateTranslatorWithContent(ctx context.Context, filePath string, fileID int32, langType LanguageType, version int32, content []byte) (*tree_sitter.Tree, *TranslateFromSyntaxTree, error)

func (*FileParser) DetectLanguage

func (fp *FileParser) DetectLanguage(filePath string) LanguageType

func (*FileParser) GetLanguageParser

func (fp *FileParser) GetLanguageParser(langType LanguageType) (*tree_sitter.Language, error)

func (*FileParser) GetLanguageVisitor

func (fp *FileParser) GetLanguageVisitor(langType LanguageType, ts *TranslateFromSyntaxTree) (SyntaxTreeVisitor, error)

func (*FileParser) ParseAndTraverseWithContent

func (fp *FileParser) ParseAndTraverseWithContent(ctx context.Context, repo *config.Repository, info os.FileInfo, filePath string, fileID int32, version int32, content []byte) error

func (*FileParser) ReadFile

func (fp *FileParser) ReadFile(filePath string) ([]byte, error)

func (*FileParser) ShouldSkipFile

func (fp *FileParser) ShouldSkipFile(ctx context.Context, repo *config.Repository, info os.FileInfo, filePath string) bool

type GoVisitor

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

func NewGoVisitor

func NewGoVisitor(logger *zap.Logger, ts *TranslateFromSyntaxTree) *GoVisitor

func (*GoVisitor) GetName

func (gv *GoVisitor) GetName(tsNode *tree_sitter.Node) string

GetName is not implemented for Go visitor

func (*GoVisitor) HasSpecialName

func (gv *GoVisitor) HasSpecialName(kind string) bool

HasSpecialName returns false for Go - no special naming conventions

func (*GoVisitor) TraverseNode

func (gv *GoVisitor) TraverseNode(ctx context.Context, tsNode *tree_sitter.Node, scopeID ast.NodeID) ast.NodeID

type JavaScriptVisitor

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

func NewJavaScriptVisitor

func NewJavaScriptVisitor(logger *zap.Logger, ts *TranslateFromSyntaxTree) *JavaScriptVisitor

func (*JavaScriptVisitor) GetName

func (jsv *JavaScriptVisitor) GetName(tsNode *tree_sitter.Node) string

GetName is not implemented for JavaScript visitor

func (*JavaScriptVisitor) HasSpecialName

func (jsv *JavaScriptVisitor) HasSpecialName(kind string) bool

HasSpecialName returns false for JavaScript - no special naming conventions

func (*JavaScriptVisitor) TraverseNode

func (jsv *JavaScriptVisitor) TraverseNode(ctx context.Context, tsNode *tree_sitter.Node, scopeID ast.NodeID) ast.NodeID

type JavaVisitor

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

func NewJavaVisitor

func NewJavaVisitor(logger *zap.Logger, ts *TranslateFromSyntaxTree) *JavaVisitor

func (*JavaVisitor) GetName

func (jv *JavaVisitor) GetName(tsNode *tree_sitter.Node) string

GetName is not implemented for Java visitor

func (*JavaVisitor) HasSpecialName

func (jv *JavaVisitor) HasSpecialName(kind string) bool

HasSpecialName returns false for Java - no special naming conventions like C#

func (*JavaVisitor) TraverseNode

func (jv *JavaVisitor) TraverseNode(ctx context.Context, tsNode *tree_sitter.Node, scopeID ast.NodeID) ast.NodeID

type LanguageType

type LanguageType int
const (
	Go LanguageType = iota
	JavaScript
	TypeScript
	Python
	Java
	CSharp
	Unknown
)

func NewLanguageTypeFromString

func NewLanguageTypeFromString(lang string) LanguageType

func (LanguageType) String

func (lt LanguageType) String() string

type PrintVisitor

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

func NewPrintVisitor

func NewPrintVisitor(ts *TranslateFromSyntaxTree) *PrintVisitor

func (*PrintVisitor) GetName

func (pv *PrintVisitor) GetName(tsNode *tree_sitter.Node) string

GetName is not implemented for PrintVisitor

func (*PrintVisitor) HasSpecialName

func (pv *PrintVisitor) HasSpecialName(kind string) bool

HasSpecialName returns false for PrintVisitor - no special naming conventions

func (*PrintVisitor) TraverseNode

func (pv *PrintVisitor) TraverseNode(ctx context.Context, tsNode *tree_sitter.Node, scopeID ast.NodeID) ast.NodeID

func (*PrintVisitor) WriteToFile

func (pv *PrintVisitor) WriteToFile(filePath string, prefix string) error

type PythonVisitor

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

func NewPythonVisitor

func NewPythonVisitor(logger *zap.Logger, ts *TranslateFromSyntaxTree) *PythonVisitor

func (*PythonVisitor) GetName

func (pv *PythonVisitor) GetName(tsNode *tree_sitter.Node) string

GetName is not implemented for Python visitor

func (*PythonVisitor) HasSpecialName

func (pv *PythonVisitor) HasSpecialName(kind string) bool

HasSpecialName returns false for Python - no special naming conventions

func (*PythonVisitor) TraverseNode

func (pv *PythonVisitor) TraverseNode(ctx context.Context, tsNode *tree_sitter.Node, scopeID ast.NodeID) ast.NodeID

type Scope

type Scope struct {
	Parent *Scope
	// contains filtered or unexported fields
}

func NewScope

func NewScope(parent *Scope, isRhs bool) *Scope

func (*Scope) AddNotContainedNode

func (s *Scope) AddNotContainedNode(nodeID ast.NodeID)

func (*Scope) AddRhsVar

func (s *Scope) AddRhsVar(nodeID ast.NodeID)

func (*Scope) AddSymbol

func (s *Scope) AddSymbol(sym *Symbol) error

func (*Scope) GetAllNotContainedNodes

func (s *Scope) GetAllNotContainedNodes() []ast.NodeID

func (*Scope) GetRhsVars

func (s *Scope) GetRhsVars() []ast.NodeID

func (*Scope) GetSymbol

func (s *Scope) GetSymbol(name string) *Symbol

func (*Scope) IsNotContainedNode

func (s *Scope) IsNotContainedNode(nodeID ast.NodeID) bool

func (*Scope) IsRhs

func (s *Scope) IsRhs() bool

func (*Scope) RemoveNotContainedNode

func (s *Scope) RemoveNotContainedNode(nodeID ast.NodeID)

func (*Scope) Resolve

func (s *Scope) Resolve(name string) *Symbol

type Symbol

type Symbol struct {
	Node   *ast.Node
	Fields map[string]*Symbol
}

func NewSymbol

func NewSymbol(node *ast.Node) *Symbol

func (*Symbol) AddField

func (s *Symbol) AddField(field *Symbol) error

func (*Symbol) GetField

func (s *Symbol) GetField(fieldName string) *Symbol

type SyntaxTreeVisitor

type SyntaxTreeVisitor interface {
	TraverseNode(ctx context.Context, tsNode *tree_sitter.Node, scopeID ast.NodeID) ast.NodeID
	HasSpecialName(kind string) bool
	GetName(tsNode *tree_sitter.Node) string
}

type TranslateFromSyntaxTree

type TranslateFromSyntaxTree struct {
	ScopeStack   []*Scope
	CurrentScope *Scope
	FileID       int32
	Version      int32
	NodeIDSeq    uint32
	CodeGraph    *codegraph.CodeGraph
	FileContent  []byte
	Visitor      SyntaxTreeVisitor
	Logger       *zap.Logger
	Nodes        map[ast.NodeID]*ast.Node
	// Batch writing support
	EnableBatchWrites bool
	BatchSize         int
	// contains filtered or unexported fields
}

func NewTranslateFromSyntaxTree

func NewTranslateFromSyntaxTree(fileID int32, version int32, codeGraph *codegraph.CodeGraph,
	fileContent []byte,
	logger *zap.Logger) *TranslateFromSyntaxTree

func (*TranslateFromSyntaxTree) Chindren

func (*TranslateFromSyntaxTree) CreateContainsRelation

func (t *TranslateFromSyntaxTree) CreateContainsRelation(ctx context.Context, parentID ast.NodeID, childID ast.NodeID, fileID int32)

func (*TranslateFromSyntaxTree) CreateContainsRelations

func (t *TranslateFromSyntaxTree) CreateContainsRelations(ctx context.Context, parentID ast.NodeID, childIDs []ast.NodeID)

func (*TranslateFromSyntaxTree) CreateFakeVariable

func (t *TranslateFromSyntaxTree) CreateFakeVariable(ctx context.Context, scopeID ast.NodeID, prefix string, rng base.Range, additionalMetadata map[string]any) ast.NodeID

func (*TranslateFromSyntaxTree) CreateFunction

func (t *TranslateFromSyntaxTree) CreateFunction(ctx context.Context,
	scopeID ast.NodeID,
	fn *tree_sitter.Node,
	fnName string,
	params []*tree_sitter.Node, body *tree_sitter.Node) ast.NodeID

func (*TranslateFromSyntaxTree) CreateFunctionWithMetadata

func (t *TranslateFromSyntaxTree) CreateFunctionWithMetadata(ctx context.Context,
	scopeID ast.NodeID,
	fn *tree_sitter.Node,
	fnName string,
	params []*tree_sitter.Node, body *tree_sitter.Node,
	metadata map[string]any) ast.NodeID

func (*TranslateFromSyntaxTree) GetAstNodeText

func (t *TranslateFromSyntaxTree) GetAstNodeText(node *ast.Node) string

func (*TranslateFromSyntaxTree) GetTreeNodeName

func (t *TranslateFromSyntaxTree) GetTreeNodeName(node *tree_sitter.Node) string

func (*TranslateFromSyntaxTree) HandleAssignment

func (t *TranslateFromSyntaxTree) HandleAssignment(ctx context.Context, assignNode *tree_sitter.Node, lhs *tree_sitter.Node, rhs *tree_sitter.Node, scopeID ast.NodeID) ast.NodeID

func (*TranslateFromSyntaxTree) HandleBlock

func (t *TranslateFromSyntaxTree) HandleBlock(ctx context.Context, tsNode *tree_sitter.Node, scopeID ast.NodeID) ast.NodeID

func (*TranslateFromSyntaxTree) HandleCall

func (t *TranslateFromSyntaxTree) HandleCall(ctx context.Context, nameID ast.NodeID, args []*tree_sitter.Node, scopeID ast.NodeID, rng base.Range) ast.NodeID

func (*TranslateFromSyntaxTree) HandleCallWithMetadata

func (t *TranslateFromSyntaxTree) HandleCallWithMetadata(ctx context.Context, nameID ast.NodeID, args []*tree_sitter.Node, scopeID ast.NodeID, rng base.Range, extraMetadata map[string]any) ast.NodeID

HandleCallWithMetadata creates a function call node with additional metadata. This is useful for annotating special call types like constructor calls.

func (*TranslateFromSyntaxTree) HandleClass

func (t *TranslateFromSyntaxTree) HandleClass(ctx context.Context,
	scopeID ast.NodeID,
	cls *tree_sitter.Node,
	name string,
	methods []*tree_sitter.Node,
	fields []*tree_sitter.Node) ast.NodeID

func (*TranslateFromSyntaxTree) HandleClassWithMetadata

func (t *TranslateFromSyntaxTree) HandleClassWithMetadata(ctx context.Context,
	scopeID ast.NodeID,
	cls *tree_sitter.Node,
	name string,
	methods []*tree_sitter.Node,
	fields []*tree_sitter.Node,
	metadata map[string]any) ast.NodeID

func (*TranslateFromSyntaxTree) HandleConditional

func (t *TranslateFromSyntaxTree) HandleConditional(ctx context.Context, conditionalNode *tree_sitter.Node, conditions []*tree_sitter.Node, branches []*tree_sitter.Node, scopeID ast.NodeID) ast.NodeID

func (*TranslateFromSyntaxTree) HandleIdentifier

func (t *TranslateFromSyntaxTree) HandleIdentifier(ctx context.Context, idNode *tree_sitter.Node, scopeID ast.NodeID) ast.NodeID

func (*TranslateFromSyntaxTree) HandleLoop

func (t *TranslateFromSyntaxTree) HandleLoop(ctx context.Context, loopNode *tree_sitter.Node,
	initID ast.NodeID, conditionID ast.NodeID, body *tree_sitter.Node,
	scopeID ast.NodeID) ast.NodeID

func (*TranslateFromSyntaxTree) HandleReturn

func (t *TranslateFromSyntaxTree) HandleReturn(ctx context.Context, rhs *tree_sitter.Node, scopeID ast.NodeID) ast.NodeID

func (*TranslateFromSyntaxTree) HandleRhs

func (t *TranslateFromSyntaxTree) HandleRhs(ctx context.Context, rhs *tree_sitter.Node, scopeID ast.NodeID) ([]ast.NodeID, ast.NodeID)

func (*TranslateFromSyntaxTree) HandleRhsExprsWithFakeVariable

func (t *TranslateFromSyntaxTree) HandleRhsExprsWithFakeVariable(ctx context.Context, lhsPrefix string, rhsExprs []*tree_sitter.Node, scopeID ast.NodeID, additionalMetadata map[string]any) ast.NodeID

func (*TranslateFromSyntaxTree) HandleRhsWithFakeVariable

func (t *TranslateFromSyntaxTree) HandleRhsWithFakeVariable(ctx context.Context, lhsPrefix string, rhs *tree_sitter.Node, scopeID ast.NodeID, additionalMetadata map[string]any) ast.NodeID

func (*TranslateFromSyntaxTree) HandleVariable

func (t *TranslateFromSyntaxTree) HandleVariable(ctx context.Context, tsNode *tree_sitter.Node, scopeID ast.NodeID) ast.NodeID

func (*TranslateFromSyntaxTree) NamedChildren

func (t *TranslateFromSyntaxTree) NamedChildren(node *tree_sitter.Node) []*tree_sitter.Node

func (*TranslateFromSyntaxTree) NewNode

func (t *TranslateFromSyntaxTree) NewNode(nodeType ast.NodeType, name string, rng base.Range, parentID ast.NodeID) *ast.Node

func (*TranslateFromSyntaxTree) NextNodeID

func (t *TranslateFromSyntaxTree) NextNodeID() ast.NodeID

func (*TranslateFromSyntaxTree) PopScope

func (t *TranslateFromSyntaxTree) PopScope(ctx context.Context, closingScopeId ast.NodeID)

func (*TranslateFromSyntaxTree) PushScope

func (t *TranslateFromSyntaxTree) PushScope(rhs bool)

func (*TranslateFromSyntaxTree) ResolveNameChain

func (t *TranslateFromSyntaxTree) ResolveNameChain(ctx context.Context, nameChain []*tree_sitter.Node, scopeID ast.NodeID) ast.NodeID

func (*TranslateFromSyntaxTree) String

func (*TranslateFromSyntaxTree) SubtreeNodeByKind

func (t *TranslateFromSyntaxTree) SubtreeNodeByKind(node *tree_sitter.Node, kind string) *tree_sitter.Node

func (*TranslateFromSyntaxTree) ToRange

func (*TranslateFromSyntaxTree) TraverseChildren

func (t *TranslateFromSyntaxTree) TraverseChildren(ctx context.Context, tsNode *tree_sitter.Node, scopeID ast.NodeID) []ast.NodeID

func (*TranslateFromSyntaxTree) TreeChildByFieldName

func (t *TranslateFromSyntaxTree) TreeChildByFieldName(node *tree_sitter.Node, fieldName string) *tree_sitter.Node

func (*TranslateFromSyntaxTree) TreeChildByKind

func (t *TranslateFromSyntaxTree) TreeChildByKind(node *tree_sitter.Node, kind string) *tree_sitter.Node

func (*TranslateFromSyntaxTree) TreeChildrenByKind

func (t *TranslateFromSyntaxTree) TreeChildrenByKind(node *tree_sitter.Node, kind string) []*tree_sitter.Node

Jump to

Keyboard shortcuts

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