parse

package
v0.0.0-...-f3d8e19 Latest Latest
Warning

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

Go to latest
Published: May 30, 2026 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ApplyAnnotationLine

func ApplyAnnotationLine(ann *model.Annotation, key, value string)

ApplyAnnotationLine applies a parsed //ff: key-value pair to an Annotation.

func BuildImportMap

func BuildImportMap(f *ast.File, modulePath string) map[string]string

BuildImportMap builds a map of alias → package name for project-internal imports.

func CalcBodyHash

func CalcBodyHash(path string) (string, error)

CalcBodyHash calculates the SHA-256 hash (first 8 hex chars) of the main func's signature and body in a Go source file.

func CalcMaxDepth

func CalcMaxDepth(f *ast.File) int

CalcMaxDepth calculates the maximum nesting depth across all functions in a file.

func CallName

func CallName(call *ast.CallExpr, projImports map[string]string, projFuncs map[string]string, callerPkg string) string

CallName extracts the qualified function name (pkg.FuncName) from a CallExpr. projImports: alias → package name. projFuncs: funcName → package name. callerPkg is used for same-package calls. Returns empty string for external or built-in calls.

func CollectFuncDecl

func CollectFuncDecl(gf *model.GoFile, d *ast.FuncDecl)

CollectFuncDecl extracts func/method/init info from a FuncDecl into GoFile.

func CollectGenDecl

func CollectGenDecl(gf *model.GoFile, d *ast.GenDecl)

CollectGenDecl extracts type/var info from a GenDecl into GoFile.

func CollectProjectSymbols

func CollectProjectSymbols(files []model.SourceFile) (funcs map[string]string, types map[string]bool)

CollectProjectSymbols collects all func and type names from parsed SourceFiles. Returns two maps: funcs[name]=pkg, types[name]=true.

func CollectTypeRefs

func CollectTypeRefs(fd *ast.FuncDecl, projImports map[string]string, projTypes map[string]bool, seen map[string]bool)

CollectTypeRefs collects project-internal type references from a FuncDecl.

func CollectVarNames

func CollectVarNames(s *ast.ValueSpec) []string

CollectVarNames extracts variable names from a ValueSpec.

func DetectControl

func DetectControl(path string) string

DetectControl detects the control structure of a func. Returns "selection", "iteration", or "sequence".

func ExtractCalls

func ExtractCalls(path string, modulePath string, projFuncs map[string]string, callerPkg string) ([]string, error)

ExtractCalls extracts project-internal function calls as qualified names (pkg.FuncName).

func ExtractFuncSource

func ExtractFuncSource(path string, src []byte) string

ExtractFuncSource extracts the source text of the main func (excluding init) from a Go source file. Returns empty string if no func found.

func ExtractFuncSourceCSharp

func ExtractFuncSourceCSharp(path string) (string, error)

ExtractFuncSourceCSharp extracts the full source text (signature + body) of the first function-like node in a C# file, using the same node the parse stage hashes so llmc and parse agree. Returns "" if no function is found.

func ExtractFuncSourceJava

func ExtractFuncSourceJava(path string) (string, error)

ExtractFuncSourceJava extracts the full source text (signature + body) of the first function-like node in a Java file, using the same node the parse stage hashes so llmc and parse agree. Returns "" if no function is found.

func ExtractFuncSourcePython

func ExtractFuncSourcePython(path string) (string, error)

ExtractFuncSourcePython extracts the full source of the first def/method from a Python file. Returns empty string if no def found.

func ExtractFuncSourceRust

func ExtractFuncSourceRust(path string) (string, error)

ExtractFuncSourceRust extracts the full source text (signature + body) of the first function_item in a Rust file, using the same node the parse stage hashes so llmc and parse agree. Returns "" if no function is found.

func ExtractFuncSourceTypeScript

func ExtractFuncSourceTypeScript(path string) (string, error)

ExtractFuncSourceTypeScript extracts the full source of the first function/method from a TypeScript file. Returns empty string if no function found.

func ExtractUses

func ExtractUses(path string, modulePath string, projTypes map[string]bool) ([]string, error)

ExtractUses extracts project-internal type usages from a Go source file.

func HasLoopAtDepth1

func HasLoopAtDepth1(path string) bool

HasLoopAtDepth1 returns true if the first non-init func has a loop at depth 1.

func HasSwitchAtDepth1

func HasSwitchAtDepth1(path string) bool

HasSwitchAtDepth1 returns true if the first non-init func has a switch at depth 1.

func IfElseDepth

func IfElseDepth(s *ast.IfStmt, current int) int

IfElseDepth calculates the maximum nesting depth for an if statement, including its else branch.

func IsSkippableLine

func IsSkippableLine(line string) bool

IsSkippableLine returns true if the line should be skipped during annotation parsing (empty lines, regular comments, package declarations).

func IsSkippableLineCSharp

func IsSkippableLineCSharp(line string) bool

IsSkippableLineCSharp returns true if the line should be skipped during C# annotation parsing. Skips empty lines, non-ff comments, and using directives.

func IsSkippableLineJava

func IsSkippableLineJava(line string) bool

IsSkippableLineJava returns true if the line should be skipped during Java annotation parsing. Skips empty lines, non-ff comments, package declarations, and import statements.

func IsSkippableLinePython

func IsSkippableLinePython(line string) bool

IsSkippableLinePython returns true if the line should be skipped during Python annotation parsing. Skips empty lines, shebang, encoding declarations, and non-ff comments.

func IsSkippableLineRust

func IsSkippableLineRust(line string) bool

IsSkippableLineRust returns true if the line should be skipped during Rust annotation parsing. Skips empty lines, doc comments (/// and //!), attributes (#[...] and #![...]), non-ff line comments, and use declarations.

func IsSkippableLineTypeScript

func IsSkippableLineTypeScript(line string) bool

IsSkippableLineTypeScript returns true if the line should be skipped during TypeScript annotation parsing. Skips empty lines and non-ff comments.

func NodeDepth

func NodeDepth(stmt ast.Stmt, current int) int

NodeDepth calculates the nesting depth of a single statement node.

func ParseAnnotation

func ParseAnnotation(path string) (*model.Annotation, error)

ParseAnnotation parses //ff: annotations from the top of a Go source file.

func ParseCSharpAnnotation

func ParseCSharpAnnotation(path string) (*model.Annotation, error)

ParseCSharpAnnotation parses //ff: annotations from the top of a C# source file.

func ParseCSharpFiles

func ParseCSharpFiles(paths []string) ([]*model.CSharpFile, error)

ParseCSharpFiles parses multiple C# files in-process via tree-sitter (no subprocess) and returns the resulting CSharpFile slice.

func ParseCodebook

func ParseCodebook(path string) (*model.Codebook, error)

ParseCodebook loads and parses a codebook.yaml file.

func ParseFuncPairs

func ParseFuncPairs(value string) map[string]string

ParseFuncPairs parses "key1=val1 key2=val2" into a map.

func ParseGoFile

func ParseGoFile(path string) (*model.GoFile, error)

ParseGoFile parses a Go source file and extracts its structure.

func ParseJavaAnnotation

func ParseJavaAnnotation(path string) (*model.Annotation, error)

ParseJavaAnnotation parses //ff: annotations from the top of a Java source file.

func ParseJavaFiles

func ParseJavaFiles(paths []string) ([]*model.JavaFile, error)

ParseJavaFiles parses multiple Java files in-process via tree-sitter (no subprocess) and returns the resulting JavaFile slice.

func ParsePythonAnnotation

func ParsePythonAnnotation(path string) (*model.Annotation, error)

ParsePythonAnnotation parses # ff: annotations from the top of a Python source file.

func ParsePythonFile

func ParsePythonFile(path string) (*model.PythonFile, error)

ParsePythonFile parses a single Python file and returns a PythonFile.

func ParsePythonFiles

func ParsePythonFiles(paths []string) ([]*model.PythonFile, error)

ParsePythonFiles parses multiple Python files in batch mode via py_ast.py.

func ParseRustAnnotation

func ParseRustAnnotation(path string) (*model.Annotation, error)

ParseRustAnnotation parses //ff: annotations from the top of a Rust source file. Doc comments (///, //!) and attributes (#[...], #![...]) above the annotation are skipped.

func ParseRustFiles

func ParseRustFiles(paths []string) ([]*model.RustFile, error)

ParseRustFiles parses multiple Rust files in-process via tree-sitter (no subprocess) and returns the resulting RustFile slice.

func ParseTypeScriptAnnotation

func ParseTypeScriptAnnotation(path string) (*model.Annotation, error)

ParseTypeScriptAnnotation parses //ff: annotations from the top of a TypeScript source file.

func ParseTypeScriptFile

func ParseTypeScriptFile(path string, projectRoot string) (*model.TypeScriptFile, error)

ParseTypeScriptFile parses a single TypeScript file and returns a TypeScriptFile.

func ParseTypeScriptFiles

func ParseTypeScriptFiles(paths []string, projectRoot string) ([]*model.TypeScriptFile, error)

ParseTypeScriptFiles parses multiple TypeScript files in batch mode via ts_ast.js.

func ReadModulePath

func ReadModulePath(goModPath string) (string, error)

ReadModulePath reads the module path from a go.mod file.

func ReceiverTypeName

func ReceiverTypeName(recv *ast.FieldList) string

ReceiverTypeName extracts the type name from a method receiver field list.

func SortedKeys

func SortedKeys(m map[string]bool) []string

SortedKeys returns the keys of a map[string]bool as a sorted slice.

func SplitTrim

func SplitTrim(s string) []string

SplitTrim splits a comma-separated string and trims whitespace from each item.

func StmtDepth

func StmtDepth(stmts []ast.Stmt, current int) int

StmtDepth calculates the maximum nesting depth in a list of statements.

Types

type CSharpResult

type CSharpResult struct {
	Path              string
	Module            string
	Funcs             []string
	Classes           []string
	Interfaces        []string
	Methods           []string
	Constructors      []string
	Vars              []string
	Lines             int
	MaxDepth          int
	Control           string
	HasLoopAtDepth1   bool
	HasSwitchAtDepth1 bool
	FuncLines         map[string]int
	Calls             []string
	Imports           []string
	BodyHash          string
}

CSharpResult is the intermediate extraction result produced by tree-sitter for a single C# source file, before conversion to model.CSharpFile.

type JavaResult

type JavaResult struct {
	Path              string
	Module            string
	Funcs             []string
	Classes           []string
	Interfaces        []string
	Methods           []string
	Constructors      []string
	Vars              []string
	Lines             int
	MaxDepth          int
	Control           string
	HasLoopAtDepth1   bool
	HasSwitchAtDepth1 bool
	FuncLines         map[string]int
	Calls             []string
	Imports           []string
	BodyHash          string
}

JavaResult is the intermediate extraction result produced by tree-sitter for a single Java source file, before conversion to model.JavaFile.

type PyAstResult

type PyAstResult struct {
	Path            string         `json:"path"`
	Functions       []string       `json:"functions"`
	Classes         []string       `json:"classes"`
	Methods         []string       `json:"methods"`
	HasInitMethod   bool           `json:"has_init_method"`
	Vars            []string       `json:"vars"`
	Lines           int            `json:"lines"`
	MaxDepth        int            `json:"max_depth"`
	Control         string         `json:"control"`
	HasLoopAtDepth1 bool           `json:"has_loop_at_depth1"`
	HasMatchAtD1    bool           `json:"has_match_at_depth1"`
	FuncLines       map[string]int `json:"func_lines"`
	Q4Results       []PyQ4JSON     `json:"q4_results"`
	Calls           []string       `json:"calls"`
	Imports         []PyImportJSON `json:"imports"`
	ModuleImports   []PyImportJSON `json:"module_imports"`
	BodyHash        string         `json:"body_hash"`
	Error           string         `json:"error,omitempty"`
}

PyAstResult is the JSON structure output by scripts/py_ast.py.

type PyImportJSON

type PyImportJSON struct {
	Module string   `json:"module"`
	Names  []string `json:"names"`
}

PyImportJSON is the JSON representation of an import from py_ast.py.

type PyQ4JSON

type PyQ4JSON struct {
	FuncName  string `json:"func_name"`
	StmtType  string `json:"stmt_type"`
	PureLines int    `json:"pure_lines"`
	Line      int    `json:"line"`
}

PyQ4JSON is the JSON representation of a Q4 result from py_ast.py.

type RustResult

type RustResult struct {
	Path              string
	Module            string
	Funcs             []string
	Types             []string
	Methods           []string
	Vars              []string
	Lines             int
	MaxDepth          int
	Control           string
	HasLoopAtDepth1   bool
	HasSwitchAtDepth1 bool
	FuncLines         map[string]int
	Calls             []string
	Imports           []string
	IsTest            bool
	BodyHash          string
}

RustResult is the intermediate extraction result produced by tree-sitter for a single Rust source file, before conversion to model.RustFile.

type TsAstResult

type TsAstResult struct {
	Path            string         `json:"path"`
	Functions       []string       `json:"functions"`
	Classes         []string       `json:"classes"`
	Interfaces      []string       `json:"interfaces"`
	TypeAliases     []string       `json:"type_aliases"`
	Methods         []string       `json:"methods"`
	HasConstructor  bool           `json:"has_constructor"`
	Vars            []string       `json:"vars"`
	Lines           int            `json:"lines"`
	MaxDepth        int            `json:"max_depth"`
	Control         string         `json:"control"`
	HasLoopAtDepth1 bool           `json:"has_loop_at_depth1"`
	HasSwitchAtD1   bool           `json:"has_switch_at_depth1"`
	FuncLines       map[string]int `json:"func_lines"`
	Q4Results       []TsQ4JSON     `json:"q4_results"`
	Calls           []string       `json:"calls"`
	Imports         []TsImportJSON `json:"imports"`
	BodyHash        string         `json:"body_hash"`
	Error           string         `json:"error,omitempty"`
}

TsAstResult is the JSON structure output by scripts/ts_ast.js.

type TsImportJSON

type TsImportJSON struct {
	Module string   `json:"module"`
	Names  []string `json:"names"`
}

TsImportJSON is the JSON representation of an import from ts_ast.js.

type TsQ4JSON

type TsQ4JSON struct {
	FuncName  string `json:"func_name"`
	StmtType  string `json:"stmt_type"`
	PureLines int    `json:"pure_lines"`
	Line      int    `json:"line"`
}

TsQ4JSON is the JSON representation of a Q4 result from ts_ast.js.

Source Files

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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