Documentation
¶
Overview ¶
Package parser provides code parsing capabilities for brfit.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DetectLanguage ¶
DetectLanguage returns the language for a given file path.
Example ¶
package main
import (
"fmt"
"github.com/indigo-net/Brf.it/pkg/parser"
)
func main() {
fmt.Println(parser.DetectLanguage("main.go"))
fmt.Println(parser.DetectLanguage("app.tsx"))
fmt.Println(parser.DetectLanguage("script.py"))
fmt.Println(parser.DetectLanguage("unknown.xyz"))
}
Output: go typescript python
func LanguageMapping ¶
LanguageMapping returns a copy of the canonical extension-to-language mapping.
func RegisterParser ¶
RegisterParser registers a parser in the default registry.
Types ¶
type FunctionCall ¶ added in v0.20.0
type FunctionCall struct {
// Caller is the name of the enclosing function (empty if top-level).
Caller string
// Callee is the called function/method name.
Callee string
// Line is the line number where the call occurs (1-indexed).
Line int
}
FunctionCall represents a function/method call reference within a file.
type Node ¶
type Node struct {
// Type is the node type (e.g., "function_declaration", "class_definition").
Type string
// StartRow is the starting row (0-indexed).
StartRow int
// EndRow is the ending row (0-indexed).
EndRow int
// StartColumn is the starting column.
StartColumn int
// EndColumn is the ending column.
EndColumn int
// Text is the source text of the node.
Text string
// Children are child nodes.
Children []Node
}
Node represents a node in the parsed AST.
type Options ¶
type Options struct {
// Language forces a specific language (auto-detected if empty).
Language string
// IncludeAST whether to include the full AST in the result.
IncludeAST bool
// IncludePrivate whether to include non-exported/private signatures.
IncludePrivate bool
// IncludeBody whether to include function/method bodies in the signature text.
// When false (default), only the signature line is extracted.
// When true, the full declaration including the body is extracted.
IncludeBody bool
// IncludeImports whether to include import/export statements in the result.
IncludeImports bool
// IncludeCalls whether to include function call references in the result.
IncludeCalls bool
}
Options configures the parsing behavior.
type ParseResult ¶
type ParseResult struct {
// FilePath is the path to the parsed file.
FilePath string
// Language is the detected language.
Language string
// Signatures is the list of extracted signatures.
Signatures []Signature
// RawImports is the list of raw import/export statement text.
RawImports []string
// Calls is the list of function call references.
Calls []FunctionCall
// AST is the root node of the parsed AST (optional).
AST *Node
// Error is any error that occurred during parsing.
Error error
}
ParseResult contains the result of parsing a single file.
type Parser ¶
type Parser interface {
// Parse parses the given content and returns extracted signatures.
// Content is passed as []byte to avoid unnecessary string conversion
// from os.ReadFile output.
Parse(content []byte, opts *Options) (*ParseResult, error)
// Languages returns the list of supported languages.
Languages() []string
}
Parser defines the interface for code parsers.
type Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
Registry manages available parsers.
func DefaultRegistry ¶
func DefaultRegistry() *Registry
DefaultRegistry returns the global parser registry.
func NewRegistry ¶
func NewRegistry() *Registry
NewRegistry creates a new empty parser registry.
Example ¶
package main
import (
"fmt"
"github.com/indigo-net/Brf.it/pkg/parser"
)
func main() {
reg := parser.NewRegistry()
fmt.Println(len(reg.Languages()))
}
Output: 0
type Signature ¶
type Signature struct {
// Name is the identifier name (e.g., "Scan", "FileScanner").
Name string
// Kind is the type of signature (e.g., "function", "method", "class", "interface").
Kind string
// Text is the full signature text including parameters and return type.
Text string
// Doc is the documentation comment (if any).
Doc string
// Line is the starting line number (1-indexed).
Line int
// EndLine is the ending line number (1-indexed).
EndLine int
// Language is the source language (e.g., "go", "typescript").
Language string
// Exported indicates whether the signature is exported/public.
Exported bool
}
Signature represents an extracted code signature (function, class, method, etc.).
Directories
¶
| Path | Synopsis |
|---|---|
|
Package treesitter provides Tree-sitter based parser implementations.
|
Package treesitter provides Tree-sitter based parser implementations. |
|
grammars/csharp
Package csharp provides the tree-sitter grammar for C#.
|
Package csharp provides the tree-sitter grammar for C#. |
|
grammars/elixir
Package elixir provides the tree-sitter grammar for Elixir.
|
Package elixir provides the tree-sitter grammar for Elixir. |
|
grammars/kotlin
Package kotlin provides the tree-sitter grammar for Kotlin.
|
Package kotlin provides the tree-sitter grammar for Kotlin. |
|
grammars/lua
Package lua provides the tree-sitter grammar for Lua.
|
Package lua provides the tree-sitter grammar for Lua. |
|
grammars/scala
Package scala provides the tree-sitter grammar for Scala.
|
Package scala provides the tree-sitter grammar for Scala. |
|
grammars/sql
Package sql provides the tree-sitter grammar for SQL.
|
Package sql provides the tree-sitter grammar for SQL. |
|
grammars/swift
Package swift provides the tree-sitter grammar for Swift.
|
Package swift provides the tree-sitter grammar for Swift. |
|
grammars/toml
Package toml provides the tree-sitter grammar for TOML.
|
Package toml provides the tree-sitter grammar for TOML. |
|
grammars/yaml
Package yaml provides the tree-sitter grammar for YAML.
|
Package yaml provides the tree-sitter grammar for YAML. |
|
languages
Package languages provides language-specific Tree-sitter queries.
|
Package languages provides language-specific Tree-sitter queries. |