{"modulePath":"github.com/glincker/stacklit","version":"v0.5.0","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package parser\n\n## Constants\n\n```go\nconst (\n\tFallbackTimeout   = \"timeout\"\n\tFallbackLarge     = \"large\"\n\tFallbackGenerated = \"generated\"\n\tFallbackMinified  = \"minified\"\n)\n```\nFallback reasons recorded on FileInfo.Fallback and in the scan report.\n\n## Functions\n\n```go\nfunc IsDataLanguage(lang string) bool\n```\nIsDataLanguage reports whether lang is config or build data, which should not decide a project's or module's primary language.\n\n```go\nfunc LeafHash(path string, content []byte) []byte\n```\nLeafHash is the hash used both as Merkle leaf and cache key.\n\n## Types\n\n```go\ntype Cache interface {\n\tGet(key string) (*FileInfo, bool)\n\tPut(key string, info *FileInfo)\n}\n```\nCache stores parse results keyed by a content-and-path hash so unchanged files skip parsing on the next run.\n\n```go\ntype FileInfo struct {\n\tPath         string            `json:\"path\"`\n\tLanguage     string            `json:\"language\"`\n\tImports      []string          `json:\"imports,omitempty\"`\n\tExports      []string          `json:\"exports,omitempty\"`\n\tTypeDefs     map[string]string `json:\"type_defs,omitempty\"` // type name -\u003e brief definition\n\tLineCount    int               `json:\"line_count\"`\n\tIsEntrypoint bool              `json:\"is_entrypoint,omitempty\"`\n\tFallback     string            `json:\"fallback,omitempty\"` // why tree-sitter was skipped, see limits.go\n}\n```\nFileInfo holds the result of parsing a source file.\n\n```go\nfunc ParseAll(paths []string) ([]*FileInfo, []error)\n```\nParseAll parses multiple files and returns all results. Errors from individual files are collected and non-fatal.\n\n```go\nfunc ParseContent(path string, content []byte) (info *FileInfo, err error)\n```\nParseContent runs the registered parsers on in-memory content. A panic in any parser is converted into an error so one bad file cannot kill a scan.\n\n```go\nfunc ParseContentWith(path string, content []byte, lim Limits) (info *FileInfo, err error)\n```\nParseContentWith is ParseContent under cost limits.\n\n```go\nfunc ParseFile(path string) (*FileInfo, error)\n```\nParseFile reads a file from disk and dispatches to the appropriate parser.\n\n```go\ntype GenericParser struct{}\n```\nGenericParser is a fallback parser that identifies languages by file extension but does not perform import/export analysis.\n\n```go\nfunc (g *GenericParser) CanParse(_ string) bool\n```\nCanParse always returns true — the generic parser handles any file.\n\n```go\nfunc (g *GenericParser) Parse(path string, content []byte) (*FileInfo, error)\n```\nParse returns path, language (from extension), and line count only.\n\n```go\ntype GoParser struct{}\n```\nGoParser parses Go source files using the stdlib go/parser + go/ast.\n\n```go\nfunc (g *GoParser) CanParse(filename string) bool\n```\nCanParse returns true for .go files that are NOT test files.\n\n```go\nfunc (g *GoParser) Parse(path string, content []byte) (*FileInfo, error)\n```\nParse extracts imports and exported names from a Go source file.\n\n```go\ntype Limits struct {\n\tParseTimeout time.Duration // wall-clock budget per file\n\tMaxBytes     int64         // largest file given to tree-sitter\n\tMaxLineLen   int           // longest line before a file counts as minified or generated\n\tGenerated    bool          // route files marked as generated code to the lightweight path\n}\n```\nLimits bound the cost of structural (tree-sitter) parsing. Files that exceed them are indexed with the lightweight generic parser instead, so one huge or pathological file cannot stall or bloat a whole scan. Zero disables a limit.\n\n```go\ntype PanicError struct {\n\tPath  string\n\tValue any\n\tStack string\n}\n```\nPanicError reports a recovered parser panic.\n\n```go\nfunc (e *PanicError) Error() string\n```\n\n```go\ntype Parser interface {\n\tCanParse(filename string) bool\n\tParse(path string, content []byte) (*FileInfo, error)\n}\n```\nParser extracts structured information from a source file.\n\n```go\ntype PoolOptions struct {\n\tRoot        string // files are read from Root/\u003crel\u003e\n\tWorkers     int    // pool size; values below 1 mean 1\n\tMaxFileSize int64  // content larger than this is rejected (race with growth); 0 disables\n\tCache       Cache  // optional\n\t// Visit sees each file's bytes once, inside the worker, so callers can\n\t// extract extra data without keeping every file in memory. It must be\n\t// safe for concurrent use.\n\tVisit func(rel string, content []byte)\n\t// MemoryBudget caps the estimated working set of concurrent tree-sitter\n\t// parses, in bytes. One file larger than the budget still runs, alone.\n\t// 0 disables the cap.\n\tMemoryBudget int64\n\t// Limits routes expensive files to the lightweight parser.\n\tLimits Limits\n\t// contains filtered or unexported fields\n}\n```\nPoolOptions configures ScanFiles.\n\n```go\ntype Scanned struct {\n\tPath     string\n\tInfo     *FileInfo\n\tLeaf     []byte // sha256(path || content), the Merkle leaf and cache key\n\tErr      error\n\tCached   bool\n\tPanicked bool\n\tDur      time.Duration // parse time, zero for cache hits\n}\n```\nScanned is the per-file outcome of ScanFiles.\n\n```go\nfunc ScanFiles(files []string, o PoolOptions) []Scanned\n```\nScanFiles parses files with a bounded worker pool. At most Workers file bodies are in memory at once. Results are returned in input order, so output does not depend on scheduling.\n\n```go\ntype TreeSitterParser struct{}\n```\nTreeSitterParser 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).\n\n```go\nfunc (p *TreeSitterParser) CanParse(filename string) bool\n```\n\n```go\nfunc (p *TreeSitterParser) Parse(path string, content []byte) (*FileInfo, error)\n```\n\n```go\nfunc (p *TreeSitterParser) ParseWithTimeout(path string, content []byte, timeout time.Duration) (*FileInfo, error)\n```\nParseWithTimeout is Parse with a wall-clock budget. When the budget runs out the partial tree is discarded and the file gets the generic parser's result, marked with FallbackTimeout.\n\n","path":"github.com/glincker/stacklit/internal/parser","name":"parser","synopsis":"","isRedistributable":true}
