{- |
   Module      : Data.GraphViz.Types.Canonical
   Description : The canonical representation of Dot graphs.
   Copyright   : (c) Matthew Sackman, Ivan Lazar Miljenovic
   License     : 3-Clause BSD-style
   Maintainer  : Ivan.Miljenovic@gmail.com

   A canonical Dot graph requires that within each graph/sub-graph,
   the statements are in the following order:

   * global attributes

   * sub-graphs/clusters

   * nodes

   * edges

   This Dot graph representation is ideally suited for converting
   other data structures to Dot form (especially with the help of
   @graphElemsToDot@ from "Data.GraphViz").

   If you require arbitrary ordering of statements, then use
   "Data.GraphViz.Types.Generalised".

   The sample graph could be implemented (this is actually the result
   of calling @canonicalise@ from "Data.GraphViz.Algorithms" on the
   generalised one) as:

   > DotGraph { strictGraph = False
   >          , directedGraph = True
   >          , graphID = Just (Str "G")
   >          , graphStatements = DotStmts { attrStmts = []
   >                                       , subGraphs = [ DotSG { isCluster = True
   >                                                             , subGraphID = Just (Num (Int 0))
   >                                                             , subGraphStmts = DotStmts { attrStmts = [ GraphAttrs [ style filled
   >                                                                                                                   , color LightGray
   >                                                                                                                   , textLabel "process #1"]
   >                                                                                                      , NodeAttrs [style filled, color White]]
   >                                                                                        , subGraphs = []
   >                                                                                        , nodeStmts = [ DotNode "a0" []
   >                                                                                                      , DotNode "a1" []
   >                                                                                                      , DotNode "a2" []
   >                                                                                                      , DotNode "a3" []]
   >                                                                                        , edgeStmts = [ DotEdge "a0" "a1" []
   >                                                                                                      , DotEdge "a1" "a2" []
   >                                                                                                      , DotEdge "a2" "a3" []
   >                                                                                                      , DotEdge "a3" "a0" []]}}
   >                                                     , DotSG { isCluster = True
   >                                                             , subGraphID = Just (Num (Int 1))
   >                                                             , subGraphStmts = DotStmts { attrStmts = [ GraphAttrs [textLabel "process #2", color Blue]
   >                                                                                                      , NodeAttrs [style filled]]
   >                                                                                        , subGraphs = []
   >                                                                                        , nodeStmts = [ DotNode "b0" []
   >                                                                                                      , DotNode "b1" []
   >                                                                                                      , DotNode "b2" []
   >                                                                                                      , DotNode "b3" []]
   >                                                                                        , edgeStmts = [ DotEdge "b0" "b1" []
   >                                                                                                      , DotEdge "b1" "b2" []
   >                                                                                                      , DotEdge "b2" "b3" []]}}]
   >                                       , nodeStmts = [ DotNode "end" [shape MSquare]
   >                                                     , DotNode "start" [shape MDiamond]]
   >                                       , edgeStmts = [ DotEdge "start" "a0" []
   >                                                     , DotEdge "start" "b0" []
   >                                                     , DotEdge "a1" "b3" []
   >                                                     , DotEdge "b2" "a3" []
   >                                                     , DotEdge "a3" "end" []
   >                                                     , DotEdge "b3" "end" []]}}

   Note that whilst the above graph represents the same Dot graph as
   specified in "Data.GraphViz.Types.Generalised", etc., it /may/ be
   drawn slightly differently by the various Graphviz tools.

 -}
module Data.GraphViz.Types.Canonical
       ( DotGraph(..)
         -- * Sub-components of a @DotGraph@.
       , DotStatements(..)
       , DotSubGraph(..)
         -- * Re-exported from @Data.GraphViz.Types@
       , GraphID(..)
       , GlobalAttributes(..)
       , DotNode(..)
       , DotEdge(..)
       ) where

import Data.GraphViz.Internal.State        (AttributeType (..))
import Data.GraphViz.Internal.Util         (bool)
import Data.GraphViz.Parsing
import Data.GraphViz.Printing
import Data.GraphViz.Types.Internal.Common

import Control.Arrow ((&&&))

-- -----------------------------------------------------------------------------

-- | A Dot graph in canonical form.
data DotGraph n = DotGraph { forall n. DotGraph n -> Bool
strictGraph     :: Bool  -- ^ If 'True', no multiple edges are drawn.
                           , forall n. DotGraph n -> Bool
directedGraph   :: Bool
                           , forall n. DotGraph n -> Maybe GraphID
graphID         :: Maybe GraphID
                           , forall n. DotGraph n -> DotStatements n
graphStatements :: DotStatements n
                           }
                deriving (DotGraph n -> DotGraph n -> Bool
forall n. Eq n => DotGraph n -> DotGraph n -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: DotGraph n -> DotGraph n -> Bool
$c/= :: forall n. Eq n => DotGraph n -> DotGraph n -> Bool
== :: DotGraph n -> DotGraph n -> Bool
$c== :: forall n. Eq n => DotGraph n -> DotGraph n -> Bool
Eq, DotGraph n -> DotGraph n -> Bool
DotGraph n -> DotGraph n -> Ordering
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
forall {n}. Ord n => Eq (DotGraph n)
forall n. Ord n => DotGraph n -> DotGraph n -> Bool
forall n. Ord n => DotGraph n -> DotGraph n -> Ordering
forall n. Ord n => DotGraph n -> DotGraph n -> DotGraph n
min :: DotGraph n -> DotGraph n -> DotGraph n
$cmin :: forall n. Ord n => DotGraph n -> DotGraph n -> DotGraph n
max :: DotGraph n -> DotGraph n -> DotGraph n
$cmax :: forall n. Ord n => DotGraph n -> DotGraph n -> DotGraph n
>= :: DotGraph n -> DotGraph n -> Bool
$c>= :: forall n. Ord n => DotGraph n -> DotGraph n -> Bool
> :: DotGraph n -> DotGraph n -> Bool
$c> :: forall n. Ord n => DotGraph n -> DotGraph n -> Bool
<= :: DotGraph n -> DotGraph n -> Bool
$c<= :: forall n. Ord n => DotGraph n -> DotGraph n -> Bool
< :: DotGraph n -> DotGraph n -> Bool
$c< :: forall n. Ord n => DotGraph n -> DotGraph n -> Bool
compare :: DotGraph n -> DotGraph n -> Ordering
$ccompare :: forall n. Ord n => DotGraph n -> DotGraph n -> Ordering
Ord, Int -> DotGraph n -> ShowS
forall n. Show n => Int -> DotGraph n -> ShowS
forall n. Show n => [DotGraph n] -> ShowS
forall n. Show n => DotGraph n -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [DotGraph n] -> ShowS
$cshowList :: forall n. Show n => [DotGraph n] -> ShowS
show :: DotGraph n -> String
$cshow :: forall n. Show n => DotGraph n -> String
showsPrec :: Int -> DotGraph n -> ShowS
$cshowsPrec :: forall n. Show n => Int -> DotGraph n -> ShowS
Show, ReadPrec [DotGraph n]
ReadPrec (DotGraph n)
ReadS [DotGraph n]
forall n. Read n => ReadPrec [DotGraph n]
forall n. Read n => ReadPrec (DotGraph n)
forall n. Read n => Int -> ReadS (DotGraph n)
forall n. Read n => ReadS [DotGraph n]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [DotGraph n]
$creadListPrec :: forall n. Read n => ReadPrec [DotGraph n]
readPrec :: ReadPrec (DotGraph n)
$creadPrec :: forall n. Read n => ReadPrec (DotGraph n)
readList :: ReadS [DotGraph n]
$creadList :: forall n. Read n => ReadS [DotGraph n]
readsPrec :: Int -> ReadS (DotGraph n)
$creadsPrec :: forall n. Read n => Int -> ReadS (DotGraph n)
Read)

instance (PrintDot n) => PrintDot (DotGraph n) where
  unqtDot :: DotGraph n -> DotCode
unqtDot = forall a stmts.
(a -> DotCode)
-> (a -> AttributeType)
-> (a -> stmts)
-> (stmts -> DotCode)
-> a
-> DotCode
printStmtBased forall {n}. DotGraph n -> DotCode
printGraphID' (forall a b. a -> b -> a
const AttributeType
GraphAttribute)
                           forall n. DotGraph n -> DotStatements n
graphStatements forall a. PrintDot a => a -> DotCode
toDot
    where
      printGraphID' :: DotGraph n -> DotCode
printGraphID' = forall a.
(a -> Bool) -> (a -> Bool) -> (a -> Maybe GraphID) -> a -> DotCode
printGraphID forall n. DotGraph n -> Bool
strictGraph forall n. DotGraph n -> Bool
directedGraph forall n. DotGraph n -> Maybe GraphID
graphID

instance (ParseDot n) => ParseDot (DotGraph n) where
  parseUnqt :: Parse (DotGraph n)
parseUnqt = forall a. (Bool -> Bool -> Maybe GraphID -> a) -> Parse a
parseGraphID forall n.
Bool -> Bool -> Maybe GraphID -> DotStatements n -> DotGraph n
DotGraph
              forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall a. AttributeType -> Parse a -> Parse a
parseBracesBased AttributeType
GraphAttribute forall a. ParseDot a => Parse a
parseUnqt

  parse :: Parse (DotGraph n)
parse = forall a. ParseDot a => Parse a
parseUnqt -- Don't want the option of quoting

-- | Assumed to be an injective mapping function.
instance Functor DotGraph where
  fmap :: forall a b. (a -> b) -> DotGraph a -> DotGraph b
fmap a -> b
f DotGraph a
g = DotGraph a
g { graphStatements :: DotStatements b
graphStatements = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap a -> b
f forall a b. (a -> b) -> a -> b
$ forall n. DotGraph n -> DotStatements n
graphStatements DotGraph a
g }

-- -----------------------------------------------------------------------------

data DotStatements n = DotStmts { forall n. DotStatements n -> [GlobalAttributes]
attrStmts :: [GlobalAttributes]
                                , forall n. DotStatements n -> [DotSubGraph n]
subGraphs :: [DotSubGraph n]
                                , forall n. DotStatements n -> [DotNode n]
nodeStmts :: [DotNode n]
                                , forall n. DotStatements n -> [DotEdge n]
edgeStmts :: [DotEdge n]
                                }
                     deriving (DotStatements n -> DotStatements n -> Bool
forall n. Eq n => DotStatements n -> DotStatements n -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: DotStatements n -> DotStatements n -> Bool
$c/= :: forall n. Eq n => DotStatements n -> DotStatements n -> Bool
== :: DotStatements n -> DotStatements n -> Bool
$c== :: forall n. Eq n => DotStatements n -> DotStatements n -> Bool
Eq, DotStatements n -> DotStatements n -> Bool
DotStatements n -> DotStatements n -> Ordering
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
forall {n}. Ord n => Eq (DotStatements n)
forall n. Ord n => DotStatements n -> DotStatements n -> Bool
forall n. Ord n => DotStatements n -> DotStatements n -> Ordering
forall n.
Ord n =>
DotStatements n -> DotStatements n -> DotStatements n
min :: DotStatements n -> DotStatements n -> DotStatements n
$cmin :: forall n.
Ord n =>
DotStatements n -> DotStatements n -> DotStatements n
max :: DotStatements n -> DotStatements n -> DotStatements n
$cmax :: forall n.
Ord n =>
DotStatements n -> DotStatements n -> DotStatements n
>= :: DotStatements n -> DotStatements n -> Bool
$c>= :: forall n. Ord n => DotStatements n -> DotStatements n -> Bool
> :: DotStatements n -> DotStatements n -> Bool
$c> :: forall n. Ord n => DotStatements n -> DotStatements n -> Bool
<= :: DotStatements n -> DotStatements n -> Bool
$c<= :: forall n. Ord n => DotStatements n -> DotStatements n -> Bool
< :: DotStatements n -> DotStatements n -> Bool
$c< :: forall n. Ord n => DotStatements n -> DotStatements n -> Bool
compare :: DotStatements n -> DotStatements n -> Ordering
$ccompare :: forall n. Ord n => DotStatements n -> DotStatements n -> Ordering
Ord, Int -> DotStatements n -> ShowS
forall n. Show n => Int -> DotStatements n -> ShowS
forall n. Show n => [DotStatements n] -> ShowS
forall n. Show n => DotStatements n -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [DotStatements n] -> ShowS
$cshowList :: forall n. Show n => [DotStatements n] -> ShowS
show :: DotStatements n -> String
$cshow :: forall n. Show n => DotStatements n -> String
showsPrec :: Int -> DotStatements n -> ShowS
$cshowsPrec :: forall n. Show n => Int -> DotStatements n -> ShowS
Show, ReadPrec [DotStatements n]
ReadPrec (DotStatements n)
ReadS [DotStatements n]
forall n. Read n => ReadPrec [DotStatements n]
forall n. Read n => ReadPrec (DotStatements n)
forall n. Read n => Int -> ReadS (DotStatements n)
forall n. Read n => ReadS [DotStatements n]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [DotStatements n]
$creadListPrec :: forall n. Read n => ReadPrec [DotStatements n]
readPrec :: ReadPrec (DotStatements n)
$creadPrec :: forall n. Read n => ReadPrec (DotStatements n)
readList :: ReadS [DotStatements n]
$creadList :: forall n. Read n => ReadS [DotStatements n]
readsPrec :: Int -> ReadS (DotStatements n)
$creadsPrec :: forall n. Read n => Int -> ReadS (DotStatements n)
Read)

instance (PrintDot n) => PrintDot (DotStatements n) where
  unqtDot :: DotStatements n -> DotCode
unqtDot DotStatements n
stmts = forall (m :: * -> *). Functor m => m [Doc] -> m Doc
vcat forall a b. (a -> b) -> a -> b
$ forall (t :: * -> *) (m :: * -> *) a.
(Traversable t, Monad m) =>
t (m a) -> m (t a)
sequence [ forall a. PrintDot a => a -> DotCode
unqtDot forall a b. (a -> b) -> a -> b
$ forall n. DotStatements n -> [GlobalAttributes]
attrStmts DotStatements n
stmts
                                  , forall a. PrintDot a => a -> DotCode
unqtDot forall a b. (a -> b) -> a -> b
$ forall n. DotStatements n -> [DotSubGraph n]
subGraphs DotStatements n
stmts
                                  , forall a. PrintDot a => a -> DotCode
unqtDot forall a b. (a -> b) -> a -> b
$ forall n. DotStatements n -> [DotNode n]
nodeStmts DotStatements n
stmts
                                  , forall a. PrintDot a => a -> DotCode
unqtDot forall a b. (a -> b) -> a -> b
$ forall n. DotStatements n -> [DotEdge n]
edgeStmts DotStatements n
stmts
                                  ]

instance (ParseDot n) => ParseDot (DotStatements n) where
  parseUnqt :: Parse (DotStatements n)
parseUnqt = do [GlobalAttributes]
atts <- forall a. ParseDot a => Parse [a]
tryParseList
                 Parse ()
newline'
                 [DotSubGraph n]
sGraphs <- forall a. ParseDot a => Parse [a]
tryParseList
                 Parse ()
newline'
                 [DotNode n]
nodes <- forall a. ParseDot a => Parse [a]
tryParseList
                 Parse ()
newline'
                 [DotEdge n]
edges <- forall a. ParseDot a => Parse [a]
tryParseList
                 forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall n.
[GlobalAttributes]
-> [DotSubGraph n] -> [DotNode n] -> [DotEdge n] -> DotStatements n
DotStmts [GlobalAttributes]
atts [DotSubGraph n]
sGraphs [DotNode n]
nodes [DotEdge n]
edges

  parse :: Parse (DotStatements n)
parse = forall a. ParseDot a => Parse a
parseUnqt -- Don't want the option of quoting
          forall (p :: * -> *) a. Commitment p => p a -> ShowS -> p a
`adjustErr`
          (String
"Not a valid set of statements\n\t"forall a. [a] -> [a] -> [a]
++)

instance Functor DotStatements where
  fmap :: forall a b. (a -> b) -> DotStatements a -> DotStatements b
fmap a -> b
f DotStatements a
stmts = DotStatements a
stmts { subGraphs :: [DotSubGraph b]
subGraphs = forall a b. (a -> b) -> [a] -> [b]
map (forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap a -> b
f) forall a b. (a -> b) -> a -> b
$ forall n. DotStatements n -> [DotSubGraph n]
subGraphs DotStatements a
stmts
                       , nodeStmts :: [DotNode b]
nodeStmts = forall a b. (a -> b) -> [a] -> [b]
map (forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap a -> b
f) forall a b. (a -> b) -> a -> b
$ forall n. DotStatements n -> [DotNode n]
nodeStmts DotStatements a
stmts
                       , edgeStmts :: [DotEdge b]
edgeStmts = forall a b. (a -> b) -> [a] -> [b]
map (forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap a -> b
f) forall a b. (a -> b) -> a -> b
$ forall n. DotStatements n -> [DotEdge n]
edgeStmts DotStatements a
stmts
                       }

-- -----------------------------------------------------------------------------

data DotSubGraph n = DotSG { forall n. DotSubGraph n -> Bool
isCluster     :: Bool
                           , forall n. DotSubGraph n -> Maybe GraphID
subGraphID    :: Maybe GraphID
                           , forall n. DotSubGraph n -> DotStatements n
subGraphStmts :: DotStatements n
                           }
                   deriving (DotSubGraph n -> DotSubGraph n -> Bool
forall n. Eq n => DotSubGraph n -> DotSubGraph n -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: DotSubGraph n -> DotSubGraph n -> Bool
$c/= :: forall n. Eq n => DotSubGraph n -> DotSubGraph n -> Bool
== :: DotSubGraph n -> DotSubGraph n -> Bool
$c== :: forall n. Eq n => DotSubGraph n -> DotSubGraph n -> Bool
Eq, DotSubGraph n -> DotSubGraph n -> Bool
DotSubGraph n -> DotSubGraph n -> Ordering
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
forall {n}. Ord n => Eq (DotSubGraph n)
forall n. Ord n => DotSubGraph n -> DotSubGraph n -> Bool
forall n. Ord n => DotSubGraph n -> DotSubGraph n -> Ordering
forall n. Ord n => DotSubGraph n -> DotSubGraph n -> DotSubGraph n
min :: DotSubGraph n -> DotSubGraph n -> DotSubGraph n
$cmin :: forall n. Ord n => DotSubGraph n -> DotSubGraph n -> DotSubGraph n
max :: DotSubGraph n -> DotSubGraph n -> DotSubGraph n
$cmax :: forall n. Ord n => DotSubGraph n -> DotSubGraph n -> DotSubGraph n
>= :: DotSubGraph n -> DotSubGraph n -> Bool
$c>= :: forall n. Ord n => DotSubGraph n -> DotSubGraph n -> Bool
> :: DotSubGraph n -> DotSubGraph n -> Bool
$c> :: forall n. Ord n => DotSubGraph n -> DotSubGraph n -> Bool
<= :: DotSubGraph n -> DotSubGraph n -> Bool
$c<= :: forall n. Ord n => DotSubGraph n -> DotSubGraph n -> Bool
< :: DotSubGraph n -> DotSubGraph n -> Bool
$c< :: forall n. Ord n => DotSubGraph n -> DotSubGraph n -> Bool
compare :: DotSubGraph n -> DotSubGraph n -> Ordering
$ccompare :: forall n. Ord n => DotSubGraph n -> DotSubGraph n -> Ordering
Ord, Int -> DotSubGraph n -> ShowS
forall n. Show n => Int -> DotSubGraph n -> ShowS
forall n. Show n => [DotSubGraph n] -> ShowS
forall n. Show n => DotSubGraph n -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [DotSubGraph n] -> ShowS
$cshowList :: forall n. Show n => [DotSubGraph n] -> ShowS
show :: DotSubGraph n -> String
$cshow :: forall n. Show n => DotSubGraph n -> String
showsPrec :: Int -> DotSubGraph n -> ShowS
$cshowsPrec :: forall n. Show n => Int -> DotSubGraph n -> ShowS
Show, ReadPrec [DotSubGraph n]
ReadPrec (DotSubGraph n)
ReadS [DotSubGraph n]
forall n. Read n => ReadPrec [DotSubGraph n]
forall n. Read n => ReadPrec (DotSubGraph n)
forall n. Read n => Int -> ReadS (DotSubGraph n)
forall n. Read n => ReadS [DotSubGraph n]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [DotSubGraph n]
$creadListPrec :: forall n. Read n => ReadPrec [DotSubGraph n]
readPrec :: ReadPrec (DotSubGraph n)
$creadPrec :: forall n. Read n => ReadPrec (DotSubGraph n)
readList :: ReadS [DotSubGraph n]
$creadList :: forall n. Read n => ReadS [DotSubGraph n]
readsPrec :: Int -> ReadS (DotSubGraph n)
$creadsPrec :: forall n. Read n => Int -> ReadS (DotSubGraph n)
Read)

instance (PrintDot n) => PrintDot (DotSubGraph n) where
  unqtDot :: DotSubGraph n -> DotCode
unqtDot = forall a stmts.
(a -> DotCode)
-> (a -> AttributeType)
-> (a -> stmts)
-> (stmts -> DotCode)
-> a
-> DotCode
printStmtBased forall n. DotSubGraph n -> DotCode
printSubGraphID' forall n. DotSubGraph n -> AttributeType
subGraphAttrType
                           forall n. DotSubGraph n -> DotStatements n
subGraphStmts forall a. PrintDot a => a -> DotCode
toDot

  unqtListToDot :: [DotSubGraph n] -> DotCode
unqtListToDot = forall a stmts.
(a -> DotCode)
-> (a -> AttributeType)
-> (a -> stmts)
-> (stmts -> DotCode)
-> [a]
-> DotCode
printStmtBasedList forall n. DotSubGraph n -> DotCode
printSubGraphID' forall n. DotSubGraph n -> AttributeType
subGraphAttrType
                                     forall n. DotSubGraph n -> DotStatements n
subGraphStmts forall a. PrintDot a => a -> DotCode
toDot

  listToDot :: [DotSubGraph n] -> DotCode
listToDot = forall a. PrintDot a => [a] -> DotCode
unqtListToDot

subGraphAttrType :: DotSubGraph n -> AttributeType
subGraphAttrType :: forall n. DotSubGraph n -> AttributeType
subGraphAttrType = forall a. a -> a -> Bool -> a
bool AttributeType
SubGraphAttribute AttributeType
ClusterAttribute forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall n. DotSubGraph n -> Bool
isCluster

printSubGraphID' :: DotSubGraph n -> DotCode
printSubGraphID' :: forall n. DotSubGraph n -> DotCode
printSubGraphID' = forall a. (a -> (Bool, Maybe GraphID)) -> a -> DotCode
printSubGraphID (forall n. DotSubGraph n -> Bool
isCluster forall (a :: * -> * -> *) b c c'.
Arrow a =>
a b c -> a b c' -> a b (c, c')
&&& forall n. DotSubGraph n -> Maybe GraphID
subGraphID)

instance (ParseDot n) => ParseDot (DotSubGraph n) where
  parseUnqt :: Parse (DotSubGraph n)
parseUnqt = forall stmt c.
(Bool -> Maybe GraphID -> stmt -> c) -> Parse stmt -> Parse c
parseSubGraph forall n. Bool -> Maybe GraphID -> DotStatements n -> DotSubGraph n
DotSG forall a. ParseDot a => Parse a
parseUnqt
              forall s a. Parser s a -> Parser s a -> Parser s a
`onFail`
              -- Take "anonymous" DotSubGraphs into account.
              forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (forall n. Bool -> Maybe GraphID -> DotStatements n -> DotSubGraph n
DotSG Bool
False forall a. Maybe a
Nothing)
                   (forall a. AttributeType -> Parse a -> Parse a
parseBracesBased AttributeType
SubGraphAttribute forall a. ParseDot a => Parse a
parseUnqt)

  parse :: Parse (DotSubGraph n)
parse = forall a. ParseDot a => Parse a
parseUnqt -- Don't want the option of quoting
          forall (p :: * -> *) a. Commitment p => p a -> ShowS -> p a
`adjustErr`
          (String
"Not a valid Sub Graph\n\t"forall a. [a] -> [a] -> [a]
++)

  parseUnqtList :: Parse [DotSubGraph n]
parseUnqtList = forall (p :: * -> *) a sep. PolyParse p => p a -> p sep -> p [a]
sepBy (Parse ()
whitespace forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> forall a. ParseDot a => Parse a
parseUnqt) Parse ()
newline'

  parseList :: Parse [DotSubGraph n]
parseList = forall a. ParseDot a => Parse [a]
parseUnqtList

instance Functor DotSubGraph where
  fmap :: forall a b. (a -> b) -> DotSubGraph a -> DotSubGraph b
fmap a -> b
f DotSubGraph a
sg = DotSubGraph a
sg { subGraphStmts :: DotStatements b
subGraphStmts = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap a -> b
f forall a b. (a -> b) -> a -> b
$ forall n. DotSubGraph n -> DotStatements n
subGraphStmts DotSubGraph a
sg }