ast

package
v1.0.9 Latest Latest
Warning

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

Go to latest
Published: Aug 10, 2025 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Match

type Match struct {
	Line    int
	Column  int
	Context string
	Node    *sitter.Node
}

Match represents a tree-sitter query match

type Node

type Node struct {
	Type     string
	Content  string
	StartPos Position
	EndPos   Position
	Children []*Node
}

Node represents an AST node

func FindNodesByType

func FindNodesByType(root *Node, nodeType string) []*Node

FindNodesByType finds all nodes of a specific type

func GetNodeAtPosition

func GetNodeAtPosition(root *Node, line, column int) *Node

GetNodeAtPosition finds the node at the given position

func GetNodePath

func GetNodePath(root, target *Node) []*Node

GetNodePath returns the path from root to the given node

func Parse

func Parse(sourceCode string, language *sitter.Language) (*Node, error)

Parse parses source code using tree-sitter

func (*Node) String

func (n *Node) String() string

String returns a string representation of the node

type Position

type Position struct {
	Line   int
	Column int
}

Position represents a location in the source code

type TreeSitter

type TreeSitter struct {
}

TreeSitter provides AST parsing capabilities using tree-sitter

func NewTreeSitter

func NewTreeSitter() *TreeSitter

NewTreeSitter creates a new TreeSitter instance

func (*TreeSitter) Cleanup

func (ts *TreeSitter) Cleanup()

Cleanup cleans up resources - no longer needed since we don't store parsers

func (*TreeSitter) FindFunctionCalls

func (ts *TreeSitter) FindFunctionCalls(tree *sitter.Tree, functionNames []string, sourceCode []byte) []Match

FindFunctionCalls finds function calls in the AST

func (*TreeSitter) FindImports

func (ts *TreeSitter) FindImports(tree *sitter.Tree, importPatterns []string, sourceCode []byte) []Match

FindImports finds import statements in the AST

func (*TreeSitter) GetNodeInfo

func (ts *TreeSitter) GetNodeInfo(node *sitter.Node, sourceCode []byte) map[string]interface{}

GetNodeInfo returns detailed information about a node

func (*TreeSitter) GetSupportedLanguages

func (ts *TreeSitter) GetSupportedLanguages() []string

GetSupportedLanguages returns a list of supported languages

func (*TreeSitter) ParseToTree

func (ts *TreeSitter) ParseToTree(sourceCode string, language string) (*sitter.Tree, error)

ParseToTree parses source code and returns a tree-sitter Tree for querying Creates a new parser instance for each call to ensure thread safety

func (*TreeSitter) Query

func (ts *TreeSitter) Query(tree *sitter.Tree, pattern string, sourceCode []byte) []Match

Query executes a tree-sitter query on the AST

func (*TreeSitter) SupportsLanguage

func (ts *TreeSitter) SupportsLanguage(language string) bool

SupportsLanguage checks if a language is supported

Jump to

Keyboard shortcuts

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