Documentation
¶
Index ¶
- func CountChangesByType(changes []Change) map[ChangeType]int
- func GetAddedNodes(changes []Change) []*node.Node
- func GetModifiedNodes(changes []Change) []*node.Node
- func GetPatternMatchStats() map[string]int64
- func GetPatternMatcher(language string) interface{}
- func GetRemovedNodes(changes []Change) []*node.Node
- func Query(input io.Reader, q string) ([]*node.Node, error)
- func RecordPatternMatch(language, pattern string, matched bool)
- type Change
- type ChangeType
- type DSLNode
- type DSLParser
- type LanguageParser
- type LanguageParserError
- type Loader
- type ParseError
- type Parser
- func (p *Parser) GetEmbeddedMappings() map[string]UASTMap
- func (p *Parser) GetEmbeddedMappingsList() map[string]map[string]interface{}
- func (p *Parser) GetMapping(language string) (*UASTMap, error)
- func (p *Parser) IsSupported(filename string) bool
- func (p *Parser) Parse(filename string, content []byte) (*node.Node, error)
- func (p *Parser) WithUASTMap(maps map[string]UASTMap) *Parser
- type PrecompiledMapping
- type UASTMap
- type UnsupportedLanguageError
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CountChangesByType ¶
func CountChangesByType(changes []Change) map[ChangeType]int
CountChangesByType counts the number of changes for each ChangeType. Returns a map from ChangeType to count.
func GetAddedNodes ¶
GetAddedNodes returns all nodes that were added in the given changes.
func GetModifiedNodes ¶
GetModifiedNodes returns all nodes that were modified in the given changes.
func GetPatternMatchStats ¶
func GetPatternMatcher ¶
func GetPatternMatcher(language string) interface{}
GetPatternMatcher returns a pre-compiled pattern matcher for the given language
func GetRemovedNodes ¶
GetRemovedNodes returns all nodes that were removed in the given changes.
func RecordPatternMatch ¶
Types ¶
type Change ¶
Change represents a structural change between two versions of code
func DetectChanges ¶
DetectChanges detects structural changes between two UAST nodes. It returns a slice of Change objects describing added, removed, and modified nodes. Now uses the final optimized implementation with ultra-fast integer keys.
Example:
changes := uast.DetectChanges(before, after)
for _, c := range changes {
fmt.Println(c.Type)
}
func FilterChangesByNodeType ¶
FilterChangesByNodeType filters the given changes by the type of nodes involved. Returns a slice of changes where either Before or After node matches nodeType.
func FilterChangesByType ¶
func FilterChangesByType(changes []Change, changeType ChangeType) []Change
FilterChangesByType filters the given changes by their ChangeType. Returns a slice of changes matching the specified type.
type ChangeType ¶
type ChangeType int
ChangeType represents the type of change between two nodes
const ( ChangeAdded ChangeType = iota ChangeRemoved ChangeModified )
func (ChangeType) String ¶
func (ct ChangeType) String() string
type DSLNode ¶
type DSLNode struct {
Root sitter.Node
Tree *sitter.Tree
Language string
Source []byte
MappingRules []mapping.MappingRule
PatternMatcher *mapping.PatternMatcher
IncludeUnmapped bool
ParentContext string
}
DSLNode wraps a Tree-sitter node for conversion to UAST using DSL mappings.
func (*DSLNode) Positions ¶
Positions returns the source code positions for this node, using uint fields as per UAST spec.
func (*DSLNode) ToCanonicalNode ¶
ToCanonicalNode converts the DSLNode to a canonical UAST Node.
type DSLParser ¶
type DSLParser struct {
IncludeUnmapped bool
// contains filtered or unexported fields
}
DSLParser implements the UAST LanguageParser interface using DSL-based mappings.
func NewDSLParser ¶
NewDSLParser creates a new DSL-based parser with the given language and mapping rules.
func (*DSLParser) Extensions ¶
func (*DSLParser) GetOriginalDSL ¶
GetOriginalDSL returns the original DSL content that was used to create this parser
type LanguageParser ¶
type LanguageParser interface {
Parse(filename string, content []byte) (*node.Node, error)
Language() string
Extensions() []string
}
Parser is responsible for parsing source code into UAST nodes
type LanguageParserError ¶
func (LanguageParserError) Error ¶
func (e LanguageParserError) Error() string
type Loader ¶
type Loader struct {
// contains filtered or unexported fields
}
Loader loads UAST parsers for different languages.
func (*Loader) GetParsers ¶
func (l *Loader) GetParsers() map[string]LanguageParser
GetParsers returns all loaded parsers.
func (*Loader) LanguageParser ¶
func (l *Loader) LanguageParser(extension string) (LanguageParser, bool)
LanguageParser returns the parser for the given file extension.
func (*Loader) LoadParser ¶
func (l *Loader) LoadParser(reader io.Reader) (LanguageParser, error)
LoadParser loads a parser by reading the uastmap file through the reader
type ParseError ¶
func (ParseError) Error ¶
func (e ParseError) Error() string
type Parser ¶
type Parser struct {
// contains filtered or unexported fields
}
Parser implements LanguageParser using embedded parsers Entry point for UAST parsing Parser is the main entry point for UAST parsing. It manages language parsers and their configurations.
func NewParser ¶
NewParser creates a new Parser with DSL-based language parsers. It loads parser configurations and instantiates parsers for each supported language. Returns a pointer to the Parser or an error if loading parsers fails.
func (*Parser) GetEmbeddedMappings ¶
GetEmbeddedMappings returns all embedded UAST mappings
func (*Parser) GetEmbeddedMappingsList ¶
GetEmbeddedMappingsList returns a lightweight list of embedded UAST mappings (without full content)
func (*Parser) GetMapping ¶
GetMapping returns a specific embedded UAST mapping by name
func (*Parser) IsSupported ¶
IsSupported returns true if the given filename is supported by any parser.
func (*Parser) WithUASTMap ¶
WithUASTMap adds custom UAST mappings to the parser using the option pattern. This method allows passing custom UAST map configurations that will be used in addition to or as a replacement for the embedded mappings.
type PrecompiledMapping ¶
type PrecompiledMapping struct {
Language string `json:"language"`
Extensions []string `json:"extensions"`
Rules []mapping.MappingRule `json:"rules"`
Patterns map[string]interface{} `json:"patterns"`
CompiledAt string `json:"compiled_at"`
}
PrecompiledMapping represents the pre-compiled mapping data
type UnsupportedLanguageError ¶
Error types for better error handling
func (UnsupportedLanguageError) Error ¶
func (e UnsupportedLanguageError) Error() string
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
pkg
|
|
|
node
Package uast provides a universal abstract syntax tree (UAST) representation and utilities for parsing, navigating, querying, and mutating code structure in a language-agnostic way.
|
Package uast provides a universal abstract syntax tree (UAST) representation and utilities for parsing, navigating, querying, and mutating code structure in a language-agnostic way. |