engine

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Jul 31, 2026 License: MIT Imports: 8 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AncestorNameSimilarity

func AncestorNameSimilarity(t1, t2 *treesitter.ASTNode) int

AncestorNameSimilarity calculates the number of matching identifier labels among the ancestors of t1 and t2. This helps break ties in top-down matching by preferring pairs located in similarly named functions or classes.

func BottomUp

func BottomUp(
	t1Root, t2Root *treesitter.ASTNode,
	m *Mapping,
	minDice float64,
)

BottomUp pairs unmatched container nodes in post-order when they share matched children, running recovery on newly matched blocks.

func ChawatheSimilarity

func ChawatheSimilarity(t1, t2 *treesitter.ASTNode, m map[*treesitter.ASTNode]*treesitter.ASTNode) float64

ChawatheSimilarity computes the Chawathe similarity coefficient between two subtrees given the current mapping set m (maps T1 nodes -> T2 nodes).

chawathe(t1, t2, m) = |{t ∈ s(t1) | (t, t2') ∈ m for some t2'}| / max(|s(t1)|, |s(t2)|)

func Descendants

func Descendants(n *treesitter.ASTNode) []*treesitter.ASTNode

Descendants returns all nodes in the subtree rooted at n, excluding n itself.

func Dice

Dice computes the Dice similarity coefficient between two subtrees given the current mapping set m (maps T1 nodes -> T2 nodes).

dice(t1, t2, m) = 2 × |{t ∈ s(t1) | (t, t2') ∈ m for some t2'}| / (|s(t1)| + |s(t2)|)

func FprintMappings

func FprintMappings(w io.Writer, r *MatchResult) error

func Height

func Height(n *treesitter.ASTNode) int

Height returns the height of a subtree rooted at n. A leaf has height 1.

func IsTrivialLeaf added in v0.3.0

func IsTrivialLeaf(n *treesitter.ASTNode) bool

IsTrivialLeaf reports whether a leaf node contains only punctuation (no alphanumeric chars or underscores).

func Isomorphic

func Isomorphic(a, b *treesitter.ASTNode) bool

TODO: replace the O(n) algorithm with O(1) hash comparison from M. Chilowicz, E. Duris, and G. Roussel. Syntax tree fingerprinting for source code similarity detection.

Isomorphic returns true when two subtrees are structurally and label-wise identical.

func LCSLabel

func LCSLabel(seq1, seq2 []*treesitter.ASTNode) [][2]*treesitter.ASTNode

LCSLabel matches node sequences by type, label, and structure.

func LCSStructure

func LCSStructure(seq1, seq2 []*treesitter.ASTNode) [][2]*treesitter.ASTNode

LCSStructure matches node sequences by type and shape (ignoring leaf labels), using child position and label similarity to resolve ambiguous matches.

func MatchUnmatchedLeaves

func MatchUnmatchedLeaves(t1Root, t2Root *treesitter.ASTNode, m *Mapping)

MatchUnmatchedLeaves pairs unmatched leaf nodes of the same type and label using parent Dice similarity and positional scores to break ties. Leaves under unmatched parents are skipped since they belong to deleted or inserted blocks.

func NearestMatchedAncestor

func NearestMatchedAncestor(n *treesitter.ASTNode, m *Mapping, isDst bool) *treesitter.ASTNode

NearestMatchedAncestor finds the closest ancestor of n that is present in the mapping. If isDst is true, it checks m.HasDst; otherwise it checks m.Has.

func PostOrder

func PostOrder(n *treesitter.ASTNode) []*treesitter.ASTNode

PostOrder returns all nodes in the subtree rooted at n in post-order (children before parent).

func PreOrder

func PreOrder(n *treesitter.ASTNode) []*treesitter.ASTNode

PreOrder returns all nodes in the subtree rooted at n in pre-order (parent before children). Used for deterministic mapping output.

func SimpleRecovery

func SimpleRecovery(t1, t2 *treesitter.ASTNode, m *Mapping)

SimpleRecovery maps unmatched children inside container pair (t1, t2) using label LCS, structural LCS, and unique-type matching.

func StructureIsomorphic

func StructureIsomorphic(a, b *treesitter.ASTNode) bool

StructureIsomorphic returns true when two subtrees are structurally identical (same Type, same shape) but ignores leaf labels.

Types

type Mapping

type Mapping struct {
	Pairs []MappingPair
	// contains filtered or unexported fields
}

Mapping is a 1-1 node mapping between T1 nodes and T2 nodes. Pairs preserves insertion order for deterministic iteration.

func NewMapping

func NewMapping() *Mapping

func TopDown

func TopDown(
	t1Root, t2Root *treesitter.ASTNode,
	minHeight int,
) *Mapping

TopDown matches largest isomorphic subtrees top-down by height.

func (*Mapping) Add

func (m *Mapping) Add(t1, t2 *treesitter.ASTNode)

func (*Mapping) DiceSrc

func (m *Mapping) DiceSrc(t1, t2 *treesitter.ASTNode) float64

DiceSrc computes dice(t1, t2) using the internal src mapping.

func (*Mapping) Dst

func (m *Mapping) Dst() map[*treesitter.ASTNode]*treesitter.ASTNode

Dst exposes the T2->T1 map.

func (*Mapping) Has

func (m *Mapping) Has(t1 *treesitter.ASTNode) bool

func (*Mapping) HasDst

func (m *Mapping) HasDst(t2 *treesitter.ASTNode) bool

func (*Mapping) Remove

func (m *Mapping) Remove(t1 *treesitter.ASTNode)

func (*Mapping) Src

func (m *Mapping) Src() map[*treesitter.ASTNode]*treesitter.ASTNode

Src exposes the T1->T2 map for use in Dice calculations.

type MappingPair

type MappingPair struct {
	Src *treesitter.ASTNode
	Dst *treesitter.ASTNode
}

MappingPair is a single src→dst node mapping, kept for deterministic ordering.

type MatchResult

type MatchResult struct {
	Mappings *Mapping
}

func Match

func Match(t1, t2 *treesitter.ASTNode) *MatchResult

Jump to

Keyboard shortcuts

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