parser

package
v0.7.4 Latest Latest
Warning

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

Go to latest
Published: Mar 1, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DetectLanguage

func DetectLanguage(filename string) string

DetectLanguage returns the language for a file based on its extension. Returns empty string if the language is not supported.

func SupportedExtensions

func SupportedExtensions() []string

SupportedExtensions returns all supported file extensions.

func SupportedLanguages

func SupportedLanguages() []string

SupportedLanguages returns all unique supported language names.

Types

type AdaParser

type AdaParser struct{}

func NewAdaParser

func NewAdaParser() *AdaParser

func (*AdaParser) Language

func (p *AdaParser) Language() string

func (*AdaParser) Parse

func (p *AdaParser) Parse(filename string, content []byte) (*ParsedFile, error)

type BashParser

type BashParser struct{}

BashParser extracts structural information from Bash/shell script files via regex.

func NewBashParser

func NewBashParser() *BashParser

NewBashParser creates a new Bash parser.

func (*BashParser) Language

func (p *BashParser) Language() string

Language returns "bash".

func (*BashParser) Parse

func (p *BashParser) Parse(filename string, content []byte) (*ParsedFile, error)

Parse extracts structural info from Bash content.

type CParser

type CParser struct{}

CParser extracts structural information from C files via regex.

func NewCParser

func NewCParser() *CParser

NewCParser creates a new C parser.

func (*CParser) Language

func (p *CParser) Language() string

Language returns "c".

func (*CParser) Parse

func (p *CParser) Parse(filename string, content []byte) (*ParsedFile, error)

Parse extracts structural info from C content.

type CSharpParser

type CSharpParser struct{}

CSharpParser extracts structural information from C# files via regex.

func NewCSharpParser

func NewCSharpParser() *CSharpParser

NewCSharpParser creates a new C# parser.

func (*CSharpParser) Language

func (p *CSharpParser) Language() string

Language returns "csharp".

func (*CSharpParser) Parse

func (p *CSharpParser) Parse(filename string, content []byte) (*ParsedFile, error)

Parse extracts structural info from C# content.

type ClojureParser

type ClojureParser struct{}

func NewClojureParser

func NewClojureParser() *ClojureParser

func (*ClojureParser) Language

func (p *ClojureParser) Language() string

func (*ClojureParser) Parse

func (p *ClojureParser) Parse(filename string, content []byte) (*ParsedFile, error)

type CobolParser

type CobolParser struct{}

func NewCobolParser

func NewCobolParser() *CobolParser

func (*CobolParser) Language

func (p *CobolParser) Language() string

func (*CobolParser) Parse

func (p *CobolParser) Parse(filename string, content []byte) (*ParsedFile, error)

type CppParser

type CppParser struct{}

CppParser extracts structural information from C++ files via regex.

func NewCppParser

func NewCppParser() *CppParser

NewCppParser creates a new C++ parser.

func (*CppParser) Language

func (p *CppParser) Language() string

Language returns "cpp".

func (*CppParser) Parse

func (p *CppParser) Parse(filename string, content []byte) (*ParsedFile, error)

Parse extracts structural info from C++ content.

type CrystalParser

type CrystalParser struct{}

CrystalParser extracts structural information from Crystal files via regex.

func NewCrystalParser

func NewCrystalParser() *CrystalParser

func (*CrystalParser) Language

func (p *CrystalParser) Language() string

func (*CrystalParser) Parse

func (p *CrystalParser) Parse(filename string, content []byte) (*ParsedFile, error)

type DartParser

type DartParser struct{}

DartParser extracts structural information from Dart files via regex.

func NewDartParser

func NewDartParser() *DartParser

NewDartParser creates a new Dart parser.

func (*DartParser) Language

func (p *DartParser) Language() string

Language returns "dart".

func (*DartParser) Parse

func (p *DartParser) Parse(filename string, content []byte) (*ParsedFile, error)

Parse extracts structural info from Dart content.

type DlangParser

type DlangParser struct{}

DlangParser extracts structural information from D language files via regex.

func NewDlangParser

func NewDlangParser() *DlangParser

func (*DlangParser) Language

func (p *DlangParser) Language() string

func (*DlangParser) Parse

func (p *DlangParser) Parse(filename string, content []byte) (*ParsedFile, error)

type ElixirParser

type ElixirParser struct{}

ElixirParser extracts structural information from Elixir files via regex.

func NewElixirParser

func NewElixirParser() *ElixirParser

NewElixirParser creates a new Elixir parser.

func (*ElixirParser) Language

func (p *ElixirParser) Language() string

Language returns "elixir".

func (*ElixirParser) Parse

func (p *ElixirParser) Parse(filename string, content []byte) (*ParsedFile, error)

Parse extracts structural info from Elixir content.

type ErlangParser

type ErlangParser struct{}

func NewErlangParser

func NewErlangParser() *ErlangParser

func (*ErlangParser) Language

func (p *ErlangParser) Language() string

func (*ErlangParser) Parse

func (p *ErlangParser) Parse(filename string, content []byte) (*ParsedFile, error)

type Export

type Export struct {
	Name string `json:"name"`
	Kind string `json:"kind"` // function, type, variable, class
	Line int    `json:"line"`
}

Export represents an exported declaration.

type FortranParser

type FortranParser struct{}

func NewFortranParser

func NewFortranParser() *FortranParser

func (*FortranParser) Language

func (p *FortranParser) Language() string

func (*FortranParser) Parse

func (p *FortranParser) Parse(filename string, content []byte) (*ParsedFile, error)

type FsharpParser

type FsharpParser struct{}

func NewFsharpParser

func NewFsharpParser() *FsharpParser

func (*FsharpParser) Language

func (p *FsharpParser) Language() string

func (*FsharpParser) Parse

func (p *FsharpParser) Parse(filename string, content []byte) (*ParsedFile, error)

type GoParser

type GoParser struct{}

GoParser extracts structural information from Go source files.

func NewGoParser

func NewGoParser() *GoParser

NewGoParser creates a new Go parser.

func (*GoParser) Language

func (p *GoParser) Language() string

Language returns "go".

func (*GoParser) Parse

func (p *GoParser) Parse(filename string, content []byte) (*ParsedFile, error)

Parse parses a Go source file and extracts imports, exports, and symbols.

type GroovyParser

type GroovyParser struct{}

func NewGroovyParser

func NewGroovyParser() *GroovyParser

func (*GroovyParser) Language

func (p *GroovyParser) Language() string

func (*GroovyParser) Parse

func (p *GroovyParser) Parse(filename string, content []byte) (*ParsedFile, error)

type HaskellParser

type HaskellParser struct{}

HaskellParser extracts structural information from Haskell files via regex.

func NewHaskellParser

func NewHaskellParser() *HaskellParser

func (*HaskellParser) Language

func (p *HaskellParser) Language() string

func (*HaskellParser) Parse

func (p *HaskellParser) Parse(filename string, content []byte) (*ParsedFile, error)

type Import

type Import struct {
	Path   string   `json:"path"`
	Names  []string `json:"names,omitempty"`
	IsType bool     `json:"is_type,omitempty"`
	Line   int      `json:"line"`
}

Import represents a single import statement.

type JavaParser

type JavaParser struct{}

JavaParser extracts structural information from Java files via regex.

func NewJavaParser

func NewJavaParser() *JavaParser

NewJavaParser creates a new Java parser.

func (*JavaParser) Language

func (p *JavaParser) Language() string

Language returns "java".

func (*JavaParser) Parse

func (p *JavaParser) Parse(filename string, content []byte) (*ParsedFile, error)

Parse extracts structural info from Java content.

type JuliaParser

type JuliaParser struct{}

func NewJuliaParser

func NewJuliaParser() *JuliaParser

func (*JuliaParser) Language

func (p *JuliaParser) Language() string

func (*JuliaParser) Parse

func (p *JuliaParser) Parse(filename string, content []byte) (*ParsedFile, error)

type KotlinParser

type KotlinParser struct{}

KotlinParser extracts structural information from Kotlin files via regex.

func NewKotlinParser

func NewKotlinParser() *KotlinParser

NewKotlinParser creates a new Kotlin parser.

func (*KotlinParser) Language

func (p *KotlinParser) Language() string

Language returns "kotlin".

func (*KotlinParser) Parse

func (p *KotlinParser) Parse(filename string, content []byte) (*ParsedFile, error)

Parse extracts structural info from Kotlin content.

type LuaParser

type LuaParser struct{}

LuaParser extracts structural information from Lua files via regex.

func NewLuaParser

func NewLuaParser() *LuaParser

NewLuaParser creates a new Lua parser.

func (*LuaParser) Language

func (p *LuaParser) Language() string

Language returns "lua".

func (*LuaParser) Parse

func (p *LuaParser) Parse(filename string, content []byte) (*ParsedFile, error)

Parse extracts structural info from Lua content.

type NimParser

type NimParser struct{}

NimParser extracts structural information from Nim files via regex.

func NewNimParser

func NewNimParser() *NimParser

func (*NimParser) Language

func (p *NimParser) Language() string

func (*NimParser) Parse

func (p *NimParser) Parse(filename string, content []byte) (*ParsedFile, error)

type ObjCParser

type ObjCParser struct{}

ObjCParser extracts structural information from Objective-C files via regex.

func NewObjCParser

func NewObjCParser() *ObjCParser

NewObjCParser creates a new Objective-C parser.

func (*ObjCParser) Language

func (p *ObjCParser) Language() string

Language returns "objc".

func (*ObjCParser) Parse

func (p *ObjCParser) Parse(filename string, content []byte) (*ParsedFile, error)

Parse extracts structural info from Objective-C content.

type OcamlParser

type OcamlParser struct{}

func NewOcamlParser

func NewOcamlParser() *OcamlParser

func (*OcamlParser) Language

func (p *OcamlParser) Language() string

func (*OcamlParser) Parse

func (p *OcamlParser) Parse(filename string, content []byte) (*ParsedFile, error)

type PHPParser

type PHPParser struct{}

PHPParser extracts structural information from PHP files via regex.

func NewPHPParser

func NewPHPParser() *PHPParser

NewPHPParser creates a new PHP parser.

func (*PHPParser) Language

func (p *PHPParser) Language() string

Language returns "php".

func (*PHPParser) Parse

func (p *PHPParser) Parse(filename string, content []byte) (*ParsedFile, error)

Parse extracts structural info from PHP content.

type ParsedFile

type ParsedFile struct {
	Path     string   `json:"path"`
	Language string   `json:"language"`
	Imports  []Import `json:"imports"`
	Exports  []Export `json:"exports"`
	Symbols  []Symbol `json:"symbols"`
}

ParsedFile holds the structural analysis of a single source file.

type Parser

type Parser interface {
	// Language returns the language this parser handles.
	Language() string
	// Parse extracts structural info from a file's content.
	Parse(filename string, content []byte) (*ParsedFile, error)
}

Parser extracts structural information from source files.

type PascalParser

type PascalParser struct{}

func NewPascalParser

func NewPascalParser() *PascalParser

func (*PascalParser) Language

func (p *PascalParser) Language() string

func (*PascalParser) Parse

func (p *PascalParser) Parse(filename string, content []byte) (*ParsedFile, error)

type PerlParser

type PerlParser struct{}

func NewPerlParser

func NewPerlParser() *PerlParser

func (*PerlParser) Language

func (p *PerlParser) Language() string

func (*PerlParser) Parse

func (p *PerlParser) Parse(filename string, content []byte) (*ParsedFile, error)

type PowershellParser

type PowershellParser struct{}

func NewPowershellParser

func NewPowershellParser() *PowershellParser

func (*PowershellParser) Language

func (p *PowershellParser) Language() string

func (*PowershellParser) Parse

func (p *PowershellParser) Parse(filename string, content []byte) (*ParsedFile, error)

type ProtobufParser

type ProtobufParser struct{}

func NewProtobufParser

func NewProtobufParser() *ProtobufParser

func (*ProtobufParser) Language

func (p *ProtobufParser) Language() string

func (*ProtobufParser) Parse

func (p *ProtobufParser) Parse(filename string, content []byte) (*ParsedFile, error)

type PythonParser

type PythonParser struct{}

PythonParser extracts structural information from Python files via regex.

func NewPythonParser

func NewPythonParser() *PythonParser

NewPythonParser creates a new Python parser.

func (*PythonParser) Language

func (p *PythonParser) Language() string

Language returns "python".

func (*PythonParser) Parse

func (p *PythonParser) Parse(filename string, content []byte) (*ParsedFile, error)

Parse extracts structural info from Python content.

type RParser

type RParser struct{}

RParser extracts structural information from R files via regex.

func NewRParser

func NewRParser() *RParser

NewRParser creates a new R parser.

func (*RParser) Language

func (p *RParser) Language() string

Language returns "r".

func (*RParser) Parse

func (p *RParser) Parse(filename string, content []byte) (*ParsedFile, error)

Parse extracts structural info from R content.

type Registry

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

Registry manages parsers for different languages.

func NewRegistry

func NewRegistry() *Registry

NewRegistry creates an empty parser registry.

func (*Registry) Get

func (r *Registry) Get(language string) (Parser, bool)

Get returns the parser for a language, if registered.

func (*Registry) ParseFile

func (r *Registry) ParseFile(filename string, content []byte) (*ParsedFile, error)

ParseFile detects language and parses a single file. Returns nil, nil if the language is not supported (not an error).

func (*Registry) Register

func (r *Registry) Register(parser Parser)

Register adds a parser for a language.

type RubyParser

type RubyParser struct{}

RubyParser extracts structural information from Ruby files via regex.

func NewRubyParser

func NewRubyParser() *RubyParser

NewRubyParser creates a new Ruby parser.

func (*RubyParser) Language

func (p *RubyParser) Language() string

Language returns "ruby".

func (*RubyParser) Parse

func (p *RubyParser) Parse(filename string, content []byte) (*ParsedFile, error)

Parse extracts structural info from Ruby content.

type RustParser

type RustParser struct{}

RustParser extracts structural information from Rust files via regex.

func NewRustParser

func NewRustParser() *RustParser

NewRustParser creates a new Rust parser.

func (*RustParser) Language

func (p *RustParser) Language() string

Language returns "rust".

func (*RustParser) Parse

func (p *RustParser) Parse(filename string, content []byte) (*ParsedFile, error)

Parse extracts structural info from Rust content.

type SQLParser

type SQLParser struct{}

SQLParser extracts structural information from SQL files via regex.

func NewSQLParser

func NewSQLParser() *SQLParser

NewSQLParser creates a new SQL parser.

func (*SQLParser) Language

func (p *SQLParser) Language() string

Language returns "sql".

func (*SQLParser) Parse

func (p *SQLParser) Parse(filename string, content []byte) (*ParsedFile, error)

Parse extracts structural info from SQL content.

type ScalaParser

type ScalaParser struct{}

ScalaParser extracts structural information from Scala files via regex.

func NewScalaParser

func NewScalaParser() *ScalaParser

NewScalaParser creates a new Scala parser.

func (*ScalaParser) Language

func (p *ScalaParser) Language() string

Language returns "scala".

func (*ScalaParser) Parse

func (p *ScalaParser) Parse(filename string, content []byte) (*ParsedFile, error)

Parse extracts structural info from Scala content.

type SolidityParser

type SolidityParser struct{}

func NewSolidityParser

func NewSolidityParser() *SolidityParser

func (*SolidityParser) Language

func (p *SolidityParser) Language() string

func (*SolidityParser) Parse

func (p *SolidityParser) Parse(filename string, content []byte) (*ParsedFile, error)

type SwiftParser

type SwiftParser struct{}

SwiftParser extracts structural information from Swift files via regex.

func NewSwiftParser

func NewSwiftParser() *SwiftParser

NewSwiftParser creates a new Swift parser.

func (*SwiftParser) Language

func (p *SwiftParser) Language() string

Language returns "swift".

func (*SwiftParser) Parse

func (p *SwiftParser) Parse(filename string, content []byte) (*ParsedFile, error)

Parse extracts structural info from Swift content.

type Symbol

type Symbol struct {
	Name      string `json:"name"`
	Kind      string `json:"kind"` // function, type, variable, method, class
	Exported  bool   `json:"exported"`
	Line      int    `json:"line"`
	EndLine   int    `json:"end_line,omitempty"`
	Signature string `json:"signature,omitempty"`
}

Symbol represents a named declaration in the file.

type TerraformParser

type TerraformParser struct{}

func NewTerraformParser

func NewTerraformParser() *TerraformParser

func (*TerraformParser) Language

func (p *TerraformParser) Language() string

func (*TerraformParser) Parse

func (p *TerraformParser) Parse(filename string, content []byte) (*ParsedFile, error)

type TypeScriptParser

type TypeScriptParser struct{}

TypeScriptParser extracts structural information from TS/JS files via regex.

func NewTypeScriptParser

func NewTypeScriptParser() *TypeScriptParser

NewTypeScriptParser creates a new TypeScript/JavaScript parser.

func (*TypeScriptParser) Language

func (p *TypeScriptParser) Language() string

Language returns "typescript".

func (*TypeScriptParser) Parse

func (p *TypeScriptParser) Parse(filename string, content []byte) (*ParsedFile, error)

Parse extracts structural info from TypeScript/JavaScript content.

type VisualBasicParser

type VisualBasicParser struct{}

func NewVisualBasicParser

func NewVisualBasicParser() *VisualBasicParser

func (*VisualBasicParser) Language

func (p *VisualBasicParser) Language() string

func (*VisualBasicParser) Parse

func (p *VisualBasicParser) Parse(filename string, content []byte) (*ParsedFile, error)

type VlangParser

type VlangParser struct{}

VlangParser extracts structural information from V language files via regex.

func NewVlangParser

func NewVlangParser() *VlangParser

func (*VlangParser) Language

func (p *VlangParser) Language() string

func (*VlangParser) Parse

func (p *VlangParser) Parse(filename string, content []byte) (*ParsedFile, error)

type ZigParser

type ZigParser struct{}

ZigParser extracts structural information from Zig files via regex.

func NewZigParser

func NewZigParser() *ZigParser

NewZigParser creates a new Zig parser.

func (*ZigParser) Language

func (p *ZigParser) Language() string

Language returns "zig".

func (*ZigParser) Parse

func (p *ZigParser) Parse(filename string, content []byte) (*ParsedFile, error)

Parse extracts structural info from Zig content.

Jump to

Keyboard shortcuts

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