parser

package
v0.3.2 Latest Latest
Warning

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

Go to latest
Published: Apr 12, 2026 License: MIT Imports: 9 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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