parser

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Apr 10, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type FileInfo

type FileInfo struct {
	Path         string            `json:"path"`
	Language     string            `json:"language"`
	Imports      []string          `json:"imports,omitempty"`
	Exports      []string          `json:"exports,omitempty"`
	TypeDefs     map[string]string `json:"type_defs,omitempty"` // type name -> brief definition
	LineCount    int               `json:"line_count"`
	IsEntrypoint bool              `json:"is_entrypoint,omitempty"`
}

FileInfo holds the result of parsing a source file.

func ParseAll

func ParseAll(paths []string) ([]*FileInfo, []error)

ParseAll parses multiple files and returns all results. Errors from individual files are collected and non-fatal.

func ParseFile

func ParseFile(path string) (*FileInfo, error)

ParseFile reads a file from disk and dispatches to the appropriate parser.

type GenericParser

type GenericParser struct{}

GenericParser is a fallback parser that identifies languages by file extension but does not perform import/export analysis.

func (*GenericParser) CanParse

func (g *GenericParser) CanParse(_ string) bool

CanParse always returns true — the generic parser handles any file.

func (*GenericParser) Parse

func (g *GenericParser) Parse(path string, content []byte) (*FileInfo, error)

Parse returns path, language (from extension), and line count only.

type GoParser

type GoParser struct{}

GoParser parses Go source files using the stdlib go/parser + go/ast.

func (*GoParser) CanParse

func (g *GoParser) CanParse(filename string) bool

CanParse returns true for .go files that are NOT test files.

func (*GoParser) Parse

func (g *GoParser) Parse(path string, content []byte) (*FileInfo, error)

Parse extracts imports and exported names from a Go source file.

type Parser

type Parser interface {
	CanParse(filename string) bool
	Parse(path string, content []byte) (*FileInfo, error)
}

Parser extracts structured information from a source file.

type TreeSitterParser added in v0.2.0

type TreeSitterParser struct{}

TreeSitterParser uses tree-sitter ASTs to extract structured info from source files. Handles all languages that have tree-sitter grammars, except Go (which uses stdlib AST).

func (*TreeSitterParser) CanParse added in v0.2.0

func (p *TreeSitterParser) CanParse(filename string) bool

func (*TreeSitterParser) Parse added in v0.2.0

func (p *TreeSitterParser) Parse(path string, content []byte) (*FileInfo, error)

Jump to

Keyboard shortcuts

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