Allow a node with 2 or more parents that can embed to be a root node.

This commit is contained in:
Robbie Gleichman 2016-11-21 20:54:46 -08:00
parent 64acccfcd5
commit 9c61368bd2

View File

@ -106,7 +106,7 @@ collapseNodes originalGraph = finalGraph where
-- These nodes are thus each a root of a collapsed node tree.
-- A node is a treeRoot if all of these conditions are true:
-- 1. The SyntaxNode can embed other nodes (i.e. syntaxNodeCanEmbed is true)
-- 2. The node has no parents that can embed it
-- 2. The node has no parents that can embed it, or 2 or more parents that can embed it.
-- TODO These rules should be revised to allow cycles to be embedded.
-- Condition 2. should be revised such that if there is a parent that is a bind, it's a root even if other nodes can embed it.
-- Note: A treeRoot may not actually have any embeddable children, since collapseTree will do nothing in that case.
@ -114,8 +114,9 @@ findTreeRoots :: ING.DynGraph gr => IngSyntaxGraph gr -> [ING.Node]
findTreeRoots graph = filterNodes (isTreeRoot graph) graph
isTreeRoot :: ING.Graph gr => IngSyntaxGraph gr -> ING.Node -> Bool
isTreeRoot graph node = graphNodeCanEmbed graph node && noParentsCanEmbed where
noParentsCanEmbed = null parentsThatCanEmbed
isTreeRoot graph node = graphNodeCanEmbed graph node && rightNumberOfParentsCanEmbed where
rightNumberOfParentsCanEmbed = numParentsThatCanEmbed == 0 || numParentsThatCanEmbed >= 2
numParentsThatCanEmbed = length parentsThatCanEmbed
parentsThatCanEmbed = filter (graphNodeCanEmbed graph) parents
parents = findParents graph node