cubix
Safe HaskellNone
LanguageHaskell2010

Cubix.Analysis.NodePairs

Description

Count occurrences of node pairs (parent-child type combinations) in a tree. Node pairs are tracked at the constructor level, not the fragment level. For example, a fragment Stat with constructors Assign and Do will generate pairs like (Assign, Var) and (Do, BlockIsBlock), not (Stat, Var).

Synopsis

Documentation

data NodePair Source #

A node pair represents a parent-child relationship by constructor name. If a node with constructor A has a child with constructor B, that's an (A, B) pair.

Constructors

NodePair 

Instances

Instances details
Show NodePair Source # 
Instance details

Defined in Cubix.Analysis.NodePairs

Eq NodePair Source # 
Instance details

Defined in Cubix.Analysis.NodePairs

Ord NodePair Source # 
Instance details

Defined in Cubix.Analysis.NodePairs

countNodePairs :: forall (fs :: [(Type -> Type) -> Type -> Type]) l. (All HFunctor fs, All HFoldable fs, All ConstrNameHF fs) => Term fs l -> Map NodePair Int Source #

Count all node pairs in a term. Returns a map from each node pair to its count in the tree. Wrapper functors (ListF, MaybeF, PairF, etc.) are treated as pass-through: their children are counted as direct children of the grandparent. Parent names are constructor names (e.g., Assign, Do), not fragment names.

countNodePairsWithPossible :: forall (fs :: [(Type -> Type) -> Type -> Type]) l. (All HFunctor fs, All HFoldable fs, All ConstrNameHF fs) => Set NodePair -> Term fs l -> Map NodePair Int Source #

Like countNodePairs, but starts with all possible pairs mapped to 0. Pairs that occur in the term get their actual counts; pairs that don't occur remain at 0.

countNodePairsInFolder :: forall (fs :: [(Type -> Type) -> Type -> Type]) l. (All HFunctor fs, All HFoldable fs, All ConstrNameHF fs) => Set NodePair -> String -> (FilePath -> IO (Maybe (Term fs l))) -> FilePath -> IO (Map NodePair Int) Source #

Count node pairs across all files in a folder matching a given extension.

Takes: * A set of all possible node pairs (to initialize counts to 0) * A file extension to filter by (e.g., ".lua", ".move") * A parse function that returns Maybe (Term fs l) * A folder path

Returns a map with all possible pairs initialized to 0, then incremented based on actual occurrences in the parsed files.

possibleNodePairs :: Name -> Q Exp Source #

Extract all possible node pairs from a signature type synonym. This uses Template Haskell to statically analyze the type definitions.

Usage: $(possibleNodePairs ''MLuaSig)

The signature type (e.g., MLuaSig) is a promoted type-level list like '[Fragment1, Fragment2, ...], created by makeSumType. This function reifies the type synonym to extract the fragment names.

Returns a Set NodePair containing pairs where:

For example, if Block has a child of type [StatementL], and Statement produces StatementL, then this generates a pair (Block, Statement). Wrapper types (List, Maybe, Either, Pair) are treated as pass-through. Sort labels are fully qualified to avoid collisions between identically-named sorts from different modules (e.g., Lua's BlockL vs parametric BlockL).