ast

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 6, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package ast provides language-specific AST parsing for context-aware compression.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Comment

type Comment struct {
	Text string
	Line int
	Kind string // line, block, doc
}

Comment represents a code comment.

type Constant

type Constant struct {
	Name  string
	Type  string
	Line  int
	Value string
}

Constant represents a constant declaration.

type Field

type Field struct {
	Name string
	Type string
	Line int
	Tags map[string]string
	Doc  string
}

Field represents a struct field.

type Function

type Function struct {
	Name       string
	Receiver   string // for methods
	Params     []Param
	Returns    []string
	Line       int
	EndLine    int
	Doc        string
	IsExported bool
	BodySize   int // lines of code
}

Function represents a function or method.

type Import

type Import struct {
	Path   string
	Alias  string
	Line   int
	IsUsed bool
}

Import represents an import statement.

type Language

type Language int

Language represents a supported programming language.

const (
	LangUnknown Language = iota
	LangGo
	LangRust
	LangPython
	LangJavaScript
	LangTypeScript
)

func DetectLanguage

func DetectLanguage(filename string) Language

DetectLanguage detects the language from file extension.

type Param

type Param struct {
	Name string
	Type string
}

Param represents a function parameter.

type ParseResult

type ParseResult struct {
	Language  Language
	FilePath  string
	Package   string
	Imports   []Import
	Types     []TypeDef
	Functions []Function
	Variables []Variable
	Constants []Constant
	Comments  []Comment
	RawAST    interface{} // language-specific AST
}

ParseResult contains the parsed AST and extracted information.

func (*ParseResult) GetOutline

func (r *ParseResult) GetOutline() string

GetOutline returns a simplified outline of the file.

func (*ParseResult) GetSymbols

func (r *ParseResult) GetSymbols() []Symbol

GetSymbols returns all symbols for code folding.

type Parser

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

Parser parses source code into AST.

func NewParser

func NewParser(lang Language) *Parser

NewParser creates a new AST parser.

func (*Parser) Parse

func (p *Parser) Parse(filename string, src []byte) (*ParseResult, error)

Parse parses source code and returns the AST result.

type Symbol

type Symbol struct {
	Name     string
	Kind     string
	Line     int
	EndLine  int
	Type     string
	Value    string
	Receiver string
	Detail   string
}

Symbol represents a code symbol.

type TypeDef

type TypeDef struct {
	Name    string
	Kind    string // struct, interface, enum, etc.
	Line    int
	Fields  []Field
	Methods []string
	Doc     string
}

TypeDef represents a type definition.

type Variable

type Variable struct {
	Name  string
	Type  string
	Line  int
	Value string
}

Variable represents a variable declaration.

Jump to

Keyboard shortcuts

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