language

package
v1.1.2 Latest Latest
Warning

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

Go to latest
Published: Mar 4, 2026 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package language provides language-specific AST analyzers.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Base

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

Base provides common analyzer functionality.

func NewBase

func NewBase(language slicing.Language) Base

NewBase creates a new Base analyzer.

func (Base) BuildModulePathFromPath

func (b Base) BuildModulePathFromPath(filePath, extension string) string

BuildModulePathFromPath builds a module path from a file path.

func (Base) BuildQualifiedName

func (b Base) BuildQualifiedName(modulePath, simpleName string) string

BuildQualifiedName builds a qualified name from module path and simple name.

func (Base) ExtractFirstChildComment

func (b Base) ExtractFirstChildComment(node *sitter.Node, source []byte) string

ExtractFirstChildComment extracts the first child comment/string (for Python docstrings).

func (Base) ExtractIdentifier

func (b Base) ExtractIdentifier(node *sitter.Node, source []byte) string

ExtractIdentifier extracts an identifier from a node using the language's name field.

func (Base) ExtractPrecedingComment

func (b Base) ExtractPrecedingComment(node *sitter.Node, source []byte) string

ExtractPrecedingComment extracts comment text from nodes preceding the given node.

func (Base) Language

func (b Base) Language() slicing.Language

Language returns the language configuration.

func (Base) NodeText

func (b Base) NodeText(node *sitter.Node, source []byte) string

NodeText extracts text from a node.

func (Base) Walker

func (b Base) Walker() slicing.Walker

Walker returns the AST walker.

type C

type C struct {
	Base
}

C implements Analyzer for C code.

func NewC

func NewC(language slicing.Language) *C

NewC creates a new C analyzer.

func (*C) Classes

func (c *C) Classes(tree *sitter.Tree, source []byte) []slicing.ClassDefinition

Classes extracts struct/union/enum definitions.

func (*C) Docstring

func (c *C) Docstring(node *sitter.Node, source []byte) string

Docstring extracts comments preceding a function.

func (*C) ExtractParameters

func (c *C) ExtractParameters(node *sitter.Node, source []byte) []string

ExtractParameters extracts function parameters.

func (*C) ExtractReturnType

func (c *C) ExtractReturnType(node *sitter.Node, source []byte) string

ExtractReturnType extracts the return type from a function.

func (*C) FunctionName

func (c *C) FunctionName(node *sitter.Node, source []byte) string

FunctionName extracts the function name from a function_definition node.

func (*C) IsMethod

func (c *C) IsMethod(_ *sitter.Node) bool

IsMethod returns false for C (no methods).

func (*C) IsPublic

func (c *C) IsPublic(_ *sitter.Node, _ string, _ []byte) bool

IsPublic always returns true for C (no visibility modifiers).

func (*C) ModulePath

func (c *C) ModulePath(file slicing.ParsedFile) string

ModulePath builds the module path from file information.

func (*C) Types

func (c *C) Types(tree *sitter.Tree, source []byte) []slicing.TypeDefinition

Types extracts typedef definitions.

type CPP

type CPP struct {
	C
}

CPP implements Analyzer for C++ code.

func NewCPP

func NewCPP(language slicing.Language) *CPP

NewCPP creates a new C++ analyzer.

func (*CPP) Classes

func (c *CPP) Classes(tree *sitter.Tree, source []byte) []slicing.ClassDefinition

Classes extracts class/struct definitions including methods.

func (*CPP) ModulePath

func (c *CPP) ModulePath(file slicing.ParsedFile) string

ModulePath builds the module path from file information.

func (*CPP) Types

func (c *CPP) Types(tree *sitter.Tree, source []byte) []slicing.TypeDefinition

Types extracts type alias declarations.

type CSharp

type CSharp struct {
	Base
}

CSharp implements Analyzer for C# code.

func NewCSharp

func NewCSharp(language slicing.Language) *CSharp

NewCSharp creates a new C# analyzer.

func (*CSharp) Classes

func (cs *CSharp) Classes(tree *sitter.Tree, source []byte) []slicing.ClassDefinition

Classes extracts class, struct, interface, and enum definitions.

func (*CSharp) Docstring

func (cs *CSharp) Docstring(node *sitter.Node, source []byte) string

Docstring extracts XML doc comments (///) preceding a method.

func (*CSharp) FunctionName

func (cs *CSharp) FunctionName(node *sitter.Node, source []byte) string

FunctionName extracts the method name from a method_declaration node.

func (*CSharp) IsMethod

func (cs *CSharp) IsMethod(node *sitter.Node) bool

IsMethod returns true if node is a constructor_declaration.

func (*CSharp) IsPublic

func (cs *CSharp) IsPublic(_ *sitter.Node, _ string, _ []byte) bool

IsPublic always returns true for C# (we index all methods).

func (*CSharp) ModulePath

func (cs *CSharp) ModulePath(file slicing.ParsedFile) string

ModulePath builds the module path from namespace declaration.

func (*CSharp) Types

func (cs *CSharp) Types(_ *sitter.Tree, _ []byte) []slicing.TypeDefinition

Types returns nil for C# (types are classes).

type Factory

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

Factory creates language-specific analyzers.

func NewFactory

func NewFactory(config slicing.LanguageConfig) *Factory

NewFactory creates a new Factory.

func (*Factory) ByExtension

func (f *Factory) ByExtension(ext string) (slicing.Analyzer, bool)

ByExtension returns an analyzer for the specified file extension.

func (*Factory) ByName

func (f *Factory) ByName(name string) (slicing.Analyzer, bool)

ByName returns an analyzer for the specified language name.

type Go

type Go struct {
	Base
}

Go implements Analyzer for Go code.

func NewGo

func NewGo(language slicing.Language) *Go

NewGo creates a new Go analyzer.

func (*Go) Classes

func (g *Go) Classes(_ *sitter.Tree, _ []byte) []slicing.ClassDefinition

Classes returns nil for Go (Go uses type definitions instead).

func (*Go) Docstring

func (g *Go) Docstring(node *sitter.Node, source []byte) string

Docstring extracts the documentation comment preceding a function.

func (*Go) ExtractParameters

func (g *Go) ExtractParameters(node *sitter.Node, source []byte) []string

ExtractParameters extracts function parameters.

func (*Go) ExtractReceiver

func (g *Go) ExtractReceiver(node *sitter.Node, source []byte) string

ExtractReceiver extracts the receiver type from a method declaration.

func (*Go) ExtractReturnType

func (g *Go) ExtractReturnType(node *sitter.Node, source []byte) string

ExtractReturnType extracts the return type from a function.

func (*Go) FunctionName

func (g *Go) FunctionName(node *sitter.Node, source []byte) string

FunctionName extracts the function name from a function or method declaration.

func (*Go) IsMethod

func (g *Go) IsMethod(node *sitter.Node) bool

IsMethod returns true if the node is a method_declaration.

func (*Go) IsPublic

func (g *Go) IsPublic(_ *sitter.Node, name string, _ []byte) bool

IsPublic returns true if the function name starts with an uppercase letter.

func (*Go) ModulePath

func (g *Go) ModulePath(file slicing.ParsedFile) string

ModulePath builds the module path from file information (package name).

func (*Go) Types

func (g *Go) Types(tree *sitter.Tree, source []byte) []slicing.TypeDefinition

Types extracts type definitions from the AST.

type Java

type Java struct {
	Base
}

Java implements Analyzer for Java code.

func NewJava

func NewJava(language slicing.Language) *Java

NewJava creates a new Java analyzer.

func (*Java) Classes

func (j *Java) Classes(tree *sitter.Tree, source []byte) []slicing.ClassDefinition

Classes extracts class definitions from the AST.

func (*Java) Docstring

func (j *Java) Docstring(node *sitter.Node, source []byte) string

Docstring extracts Javadoc comments preceding a method.

func (*Java) FunctionName

func (j *Java) FunctionName(node *sitter.Node, source []byte) string

FunctionName extracts the method name from a method_declaration node.

func (*Java) IsMethod

func (j *Java) IsMethod(_ *sitter.Node) bool

IsMethod returns false for Java (methods are handled within class extraction).

func (*Java) IsPublic

func (j *Java) IsPublic(_ *sitter.Node, _ string, _ []byte) bool

IsPublic always returns true for Java (we treat all methods as public for indexing).

func (*Java) ModulePath

func (j *Java) ModulePath(file slicing.ParsedFile) string

ModulePath builds the module path from package declaration.

func (*Java) Types

func (j *Java) Types(_ *sitter.Tree, _ []byte) []slicing.TypeDefinition

Types returns nil for Java (types are classes).

type JavaScript

type JavaScript struct {
	Base
}

JavaScript implements Analyzer for JavaScript code.

func NewJavaScript

func NewJavaScript(language slicing.Language) *JavaScript

NewJavaScript creates a new JavaScript analyzer.

func (*JavaScript) Classes

func (j *JavaScript) Classes(tree *sitter.Tree, source []byte) []slicing.ClassDefinition

Classes extracts class definitions from the AST.

func (*JavaScript) Docstring

func (j *JavaScript) Docstring(node *sitter.Node, source []byte) string

Docstring extracts JSDoc comments preceding a function.

func (*JavaScript) FunctionName

func (j *JavaScript) FunctionName(node *sitter.Node, source []byte) string

FunctionName extracts the function name from various function nodes.

func (*JavaScript) IsMethod

func (j *JavaScript) IsMethod(node *sitter.Node) bool

IsMethod returns true if the node is a method_definition.

func (*JavaScript) IsPublic

func (j *JavaScript) IsPublic(_ *sitter.Node, _ string, _ []byte) bool

IsPublic always returns true for JavaScript (no private convention in standard JS).

func (*JavaScript) ModulePath

func (j *JavaScript) ModulePath(file slicing.ParsedFile) string

ModulePath builds the module path from file information.

func (*JavaScript) Types

func (j *JavaScript) Types(_ *sitter.Tree, _ []byte) []slicing.TypeDefinition

Types returns nil for JavaScript (no type definitions in vanilla JS).

type Python

type Python struct {
	Base
}

Python implements Analyzer for Python code.

func NewPython

func NewPython(language slicing.Language) *Python

NewPython creates a new Python analyzer.

func (*Python) Classes

func (p *Python) Classes(tree *sitter.Tree, source []byte) []slicing.ClassDefinition

Classes extracts class definitions from the AST.

func (*Python) Docstring

func (p *Python) Docstring(node *sitter.Node, source []byte) string

Docstring extracts the docstring from a function or class.

func (*Python) FunctionName

func (p *Python) FunctionName(node *sitter.Node, source []byte) string

FunctionName extracts the function name from a function_definition node.

func (*Python) IsMethod

func (p *Python) IsMethod(_ *sitter.Node) bool

IsMethod returns false for Python (methods are extracted within class walk).

func (*Python) IsPublic

func (p *Python) IsPublic(_ *sitter.Node, name string, _ []byte) bool

IsPublic returns true if the function name does not start with underscore.

func (*Python) ModulePath

func (p *Python) ModulePath(file slicing.ParsedFile) string

ModulePath builds the module path from file information.

func (*Python) Types

func (p *Python) Types(_ *sitter.Tree, _ []byte) []slicing.TypeDefinition

Types returns nil for Python (no type definitions).

type Rust

type Rust struct {
	Base
}

Rust implements Analyzer for Rust code.

func NewRust

func NewRust(language slicing.Language) *Rust

NewRust creates a new Rust analyzer.

func (*Rust) Classes

func (r *Rust) Classes(tree *sitter.Tree, source []byte) []slicing.ClassDefinition

Classes extracts struct and enum definitions.

func (*Rust) Docstring

func (r *Rust) Docstring(node *sitter.Node, source []byte) string

Docstring extracts doc comments (/// or //!) preceding a function.

func (*Rust) FunctionName

func (r *Rust) FunctionName(node *sitter.Node, source []byte) string

FunctionName extracts the function name from a function_item node.

func (*Rust) IsMethod

func (r *Rust) IsMethod(node *sitter.Node) bool

IsMethod returns true if the node is inside an impl block.

func (*Rust) IsPublic

func (r *Rust) IsPublic(_ *sitter.Node, _ string, _ []byte) bool

IsPublic always returns true for Rust (we index all functions).

func (*Rust) ModulePath

func (r *Rust) ModulePath(file slicing.ParsedFile) string

ModulePath builds the module path from file information.

func (*Rust) Types

func (r *Rust) Types(tree *sitter.Tree, source []byte) []slicing.TypeDefinition

Types extracts type aliases and trait definitions.

type TypeScript

type TypeScript struct {
	JavaScript
	// contains filtered or unexported fields
}

TypeScript implements Analyzer for TypeScript code.

func NewTSX

func NewTSX(language slicing.Language) *TypeScript

NewTSX creates a new TSX analyzer.

func NewTypeScript

func NewTypeScript(language slicing.Language) *TypeScript

NewTypeScript creates a new TypeScript analyzer.

func (*TypeScript) ExtractJSXReturns

func (t *TypeScript) ExtractJSXReturns(node *sitter.Node, source []byte) []string

ExtractJSXReturns extracts JSX return statements (for TSX).

func (*TypeScript) ExtractTypeReferences

func (t *TypeScript) ExtractTypeReferences(node *sitter.Node, source []byte) []string

ExtractTypeReferences extracts type names referenced in a node.

func (*TypeScript) ModulePath

func (t *TypeScript) ModulePath(file slicing.ParsedFile) string

ModulePath builds the module path from file information.

func (*TypeScript) Types

func (t *TypeScript) Types(tree *sitter.Tree, source []byte) []slicing.TypeDefinition

Types extracts type definitions from the AST.

Jump to

Keyboard shortcuts

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