- data Location = Location Int Int
- data Region = Region Location Location
-
- data Tree = Tree String [Tree] Region
- instance Show Tree
- where
- show t@(Tree _ _ _) = show $ prettyPrintTree $ t
-
- coalesceFlatHeadlessNodes t@(Tree s children r)
- | s==[], flat t = Tree (concat $ map (\(Tree s _ _) -> s) children) [] r
- | otherwise = Tree s (map coalesceFlatHeadlessNodes children) r
- where
- flat (Tree _ children _) = not (any id $ map notFlatComponent children)
- notFlatComponent (Tree _ [] _) = False
- notFlatComponent (Tree _ _ _) = True
-
- prettyPrintTree (Tree "" [] _) = empty
- prettyPrintTree (Tree s [] _) = text s
- prettyPrintTree t@(Tree s children _)
- | s==[] = (text "{") <+> ((prettyPrintTreeList children) <+> (text "}"))
- | otherwise = ((text s) <> (text ":")) <+> prettyPrintTreeList children
- where
- prettyPrintTreeList children = (vcat $ map prettyPrintTree children)
-
- nullRegion = (Region (Location 0 0) (Location 0 0))
-