Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 28 additions & 13 deletions src-extra/transformation/Transformation.hs
Original file line number Diff line number Diff line change
Expand Up @@ -68,29 +68,44 @@ addPrefixComments (x :| xs) = x :| map addToCG xs
newComment = InternalComment ("prefix group " <> commentName) False
in AnnotatedVertex (newComment : comments) vertex meta :| cgs

addVertexTreeToForest
:: Map VertexTreeType [AnnotatedVertex]
-> VertexForest
-> VertexForest
-> VertexTreeType
-> Either Text VertexForest
addVertexTreeToForest grouped forest forestAcc t =
case M.lookup t grouped of
Just groupsForT ->
let keepGroupMeta =
isNothing (M.lookup t forest)

groupsForT' =
if keepGroupMeta
then groupsForT
else [g {aMeta = M.delete "group" (aMeta g)} | g <- groupsForT]
in case buildTreeForType forest t groupsForT' of
Just vt ->
let groupsToSort = tAnnotatedVertices vt
groupsSorted = sconcat $ NE.map (sortVertices t) groupsToSort
prefixCommentedGroups =
addPrefixComments $ NE.groupWith1 (dropIndex . vName . aVertex) groupsSorted
vt' = vt {tAnnotatedVertices = prefixCommentedGroups}
in Right $ M.insert t vt' forestAcc
Nothing -> Right forestAcc
Nothing -> Right forestAcc

moveVerticesInVertexForest :: VertexForest -> Either Text VertexForest
moveVerticesInVertexForest vertexTrees = do
let supportTree = M.lookup SupportTree vertexTrees
movableTrees = M.delete SupportTree vertexTrees
allGroups = concatMap (NE.toList . sconcat . tAnnotatedVertices) (M.elems movableTrees)
movableGroups = filter (not . isSupportVertex . aVertex) allGroups
grouped = M.fromListWith (++) [(determineGroup (aVertex g), [g]) | g <- movableGroups]
addVertexTreeToForest f t =
case M.lookup t grouped of
Just groupsForT ->
case buildTreeForType vertexTrees t groupsForT of
Just vt ->
let groupsToSort = tAnnotatedVertices vt
groupsSorted = sconcat $ NE.map (sortVertices t) groupsToSort
prefixCommentedGroups = addPrefixComments $ NE.groupWith1 (dropIndex . vName . aVertex) groupsSorted
vt' = (vt {tAnnotatedVertices = prefixCommentedGroups})
in Right $ M.insert t vt' f
Nothing -> Right f
Nothing -> Right f

newForest <-
foldlM
addVertexTreeToForest
(addVertexTreeToForest grouped vertexTrees)
M.empty
treesOrderNoSupport
Right $ maybe newForest (\st -> M.insert SupportTree st newForest) supportTree
Expand Down
Loading