parser

package
v0.0.0-...-938b0e3 Latest Latest
Warning

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

Go to latest
Published: Mar 4, 2026 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var FileExtensions = map[Language][]string{
	LangGo:         {".go"},
	LangPython:     {".py", ".pyi"},
	LangTypeScript: {".ts", ".tsx"},
	LangJavaScript: {".js", ".jsx", ".mjs", ".cjs"},
	LangJava:       {".java"},
	LangHTML:       {".html", ".htm", ".jinja2", ".j2", ".tmpl", ".gohtml", ".vue", ".svelte"},
	LangMarkdown:   {".md", ".mdx"},
	LangMakefile:   {".mk"},
	LangShell:      {".sh", ".bash"},
	LangTerraform:  {".tf", ".tfvars"},
	LangYAML:       {".yml", ".yaml"},
	LangManifest:   {".toml"},
	LangRust:       {".rs"},
	LangCSharp:     {".cs"},
	LangRuby:       {".rb", ".rake"},
}

FileExtensions maps each language to its recognized file extensions.

Functions

This section is empty.

Types

type Classifier

type Classifier struct{}

Classifier performs post-parse classification of nodes, enriching them with architectural roles, design patterns, and layer tags based on heuristics (annotations, decorators, naming conventions, base classes, package paths).

func NewClassifier

func NewClassifier() *Classifier

NewClassifier creates a new Classifier instance.

func (*Classifier) Classify

func (c *Classifier) Classify(result *ParseResult) *ParseResult

Classify iterates all nodes in a ParseResult and enriches them with architectural metadata. It may reclassify node types (e.g., Class -> DBModel) and adds PropArchRole, PropDesignPattern, and PropLayerTag properties.

func (*Classifier) ClassifyNode

func (c *Classifier) ClassifyNode(node *graph.Node) *graph.Node

ClassifyNode classifies a single node, modifying it in place.

type FilenameParser

type FilenameParser interface {
	Parser
	// Filenames returns the exact filenames this parser can handle.
	Filenames() []string
}

FilenameParser extends Parser for languages where files are identified by exact filenames rather than extensions (e.g., "Makefile", "Dockerfile").

type Language

type Language string

Language represents a supported programming language.

const (
	LangGo         Language = "go"
	LangPython     Language = "python"
	LangTypeScript Language = "typescript"
	LangJavaScript Language = "javascript"
	LangJava       Language = "java"
	LangHTML       Language = "html"
	LangMarkdown   Language = "markdown"
	LangMakefile   Language = "makefile"
	LangShell      Language = "shell"
	LangTerraform  Language = "terraform"
	LangYAML       Language = "yaml"
	LangManifest   Language = "manifest"
	LangRust       Language = "rust"
	LangCSharp     Language = "csharp"
	LangRuby       Language = "ruby"
)

type ParseResult

type ParseResult struct {
	Nodes    []*graph.Node
	Edges    []*graph.Edge
	FilePath string
	Language Language
}

ParseResult holds the extracted nodes and edges from parsing a file.

type Parser

type Parser interface {
	// Language returns which language this parser handles.
	Language() Language

	// Extensions returns the file extensions this parser can handle.
	Extensions() []string

	// ParseFile parses the given file content and returns extracted nodes and edges.
	ParseFile(filePath string, content []byte) (*ParseResult, error)
}

Parser defines the interface for language-specific source code parsers.

type Registry

type Registry struct {
	// contains filtered or unexported fields
}

Registry manages a collection of language parsers.

func NewRegistry

func NewRegistry() *Registry

NewRegistry creates a new parser registry.

func (*Registry) All

func (r *Registry) All() []Parser

All returns all registered parsers in registration order.

func (*Registry) ExcludeExtensions

func (r *Registry) ExcludeExtensions() []string

ExcludeExtensions returns the list of extensions excluded from fallback processing.

func (*Registry) Fallback

func (r *Registry) Fallback() Parser

Fallback returns the fallback parser, or nil if not set.

func (*Registry) Get

func (r *Registry) Get(lang Language) (Parser, bool)

Get retrieves a parser by language.

func (*Registry) GetByExtension

func (r *Registry) GetByExtension(ext string) (Parser, bool)

GetByExtension retrieves a parser by file extension (e.g. ".go", ".py").

func (*Registry) ParserForFile

func (r *Registry) ParserForFile(filePath string) (Parser, bool)

ParserForFile resolves the appropriate parser for a given file path. It first tries extension-based lookup, then filename-based lookup, then falls back to the generic fallback parser (if set).

func (*Registry) Register

func (r *Registry) Register(p Parser)

Register adds a parser to the registry, indexing it by language and file extensions. If the parser implements FilenameParser, it is also indexed by exact filenames.

func (*Registry) SetExcludeExtensions

func (r *Registry) SetExcludeExtensions(exts []string)

SetExcludeExtensions sets extensions to exclude from fallback processing.

func (*Registry) SetFallback

func (r *Registry) SetFallback(p Parser)

SetFallback sets a fallback parser used when no language parser matches.

func (*Registry) SupportedExtensions

func (r *Registry) SupportedExtensions() []string

SupportedExtensions returns all file extensions that have a registered parser.

func (*Registry) SupportedFilenames

func (r *Registry) SupportedFilenames() []string

SupportedFilenames returns all filenames that have a registered parser.

Directories

Path Synopsis
Package generic provides a fallback parser for non-code files (text, images).
Package generic provides a fallback parser for non-code files (text, images).

Jump to

Keyboard shortcuts

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