parser

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 9, 2026 License: MIT Imports: 8 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 JavaParser

type JavaParser struct{}

JavaParser parses Java source files using regex.

func (*JavaParser) CanParse

func (j *JavaParser) CanParse(filename string) bool

CanParse returns true for .java files.

func (*JavaParser) Parse

func (j *JavaParser) Parse(path string, content []byte) (*FileInfo, error)

Parse extracts imports, exports, and entrypoint from a Java 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 PythonParser

type PythonParser struct{}

PythonParser parses Python source files using regex.

func (*PythonParser) CanParse

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

CanParse returns true for .py files.

func (*PythonParser) Parse

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

Parse extracts imports, exports (public defs/classes), and entrypoint from a Python file.

type RustParser

type RustParser struct{}

RustParser parses Rust source files using regex.

func (*RustParser) CanParse

func (r *RustParser) CanParse(filename string) bool

CanParse returns true for .rs files.

func (*RustParser) Parse

func (r *RustParser) Parse(path string, content []byte) (*FileInfo, error)

Parse extracts imports, exports, and entrypoint from a Rust file.

type TypeScriptParser

type TypeScriptParser struct{}

TypeScriptParser parses TypeScript and JavaScript files using regex.

func (*TypeScriptParser) CanParse

func (t *TypeScriptParser) CanParse(filename string) bool

CanParse returns true for .ts, .tsx, .js, .jsx, .mjs, .cjs files.

func (*TypeScriptParser) Parse

func (t *TypeScriptParser) Parse(path string, content []byte) (*FileInfo, error)

Parse extracts imports and exports from a TS/JS source file.

Jump to

Keyboard shortcuts

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