@@ -104,14 +104,20 @@ relationAsTable rel@(Relation _ tupleSet) = (header, body)
104 body = L.foldl' tupleFolder [] (asList tupleSet)
104 body = L.foldl' tupleFolder [] (asList tupleSet)
105 tupleFolder acc tuple = acc ++ [map (\attrName -> case atomForAttributeName attrName tuple of
105 tupleFolder acc tuple = acc ++ [map (\attrName -> case atomForAttributeName attrName tuple of
106 Left _ -> "?"
106 Left _ -> "?"
107− Right atom -> showAtom atom
107+ Right atom -> showAtom 0 atom
108 ) oAttrNames]
108 ) oAttrNames]
110+showParens :: Bool -> StringType -> StringType
111+showParens predicate f = if predicate then
112+ "(" `T.append` f `T.append` ")"
110−showAtom :: Atom -> StringType
116+showAtom :: Int -> Atom -> StringType
111−showAtom (Atom atom) = case cast atom of
117+showAtom _ (Atom atom) = case cast atom of
112− Just rel -> renderTable $ relationAsTable rel
118+ Just rel -> renderTable $ relationAsTable rel
113− Nothing -> toText atom
119+ Nothing -> toText atom
114−showAtom (ConstructedAtom dConsName _ atoms) = dConsName `T.append` " " `T.append` T.concat (L.intersperse " " (map showAtom atoms))
120+showAtom level (ConstructedAtom dConsName _ atoms) = showParens (level >= 1 && length atoms >= 1) $ T.concat (L.intersperse " " (dConsName : (map (showAtom 1) atoms)))
116renderTable :: Table -> StringType
122renderTable :: Table -> StringType
117renderTable table = renderHeader table (fst cellLocs) `T.append` renderBody (snd table) cellLocs
123renderTable table = renderHeader table (fst cellLocs) `T.append` renderBody (snd table) cellLocs