-- | JSON representation of a call-graph.
export :: [Node] -> Doc
export = block one "{" "}"
  where
  one pre Node { .. } =
    hang (pre <+> exportFun fun <> colon) 2 $ vcat
      [ text "{ \"stage\": "   <+> int stage
      , text ", \"calls\":"    <+> block oneFun "[" "]" calls
      , text ", \"calledBy\":" <+> block oneFun "[" "]" calledBy
      , text "}"
      ]

  oneFun pre f           = pre <+> exportFun f

  exportFun              = text . show . funHash

  block _   start end [] = text (start ++ end)
  block how start end xs = vcat (zipWith how (map text (start : repeat ",")) xs)
                           $$ text end

-- | Construct the call-graph for all functions that we know.
export :: [Node] -> Doc
export = block one "{" "}"
  where
  one pre Node { .. } =
    hang (pre <+> exportFun fun <> colon) 2 $ vcat
      [ text "{ \"stage\": "   <+> int stage
      , text ", \"calls\":"    <+> block oneFun "[" "]" calls
      , text ", \"calledBy\":" <+> block oneFun "[" "]" calledBy
      , text "}"
      ]

  oneFun pre f           = pre <+> exportFun f

  exportFun              = text . show . funHash

  block _   start end [] = text (start ++ end)
  block how start end xs = vcat (zipWith how (map text (start : repeat ",")) xs)
                           $$ text end

-- | Construct the call-graph for all functions that we know.
export = block one "{" "}"
  where
  one pre Node { .. } =
    hang (pre <+> exportFun fun <> colon) 2 $ vcat
      [ text "{ \"stage\": "   <+> int stage
      , text ", \"calls\":"    <+> block oneFun "[" "]" calls
      , text ", \"calledBy\":" <+> block oneFun "[" "]" calledBy
      , text "}"
      ]

  oneFun pre f           = pre <+> exportFun f

  exportFun              = text . show . funHash

  block _   start end [] = text (start ++ end)
  block how start end xs = vcat (zipWith how (map text (start : repeat ",")) xs)
                           $$ text end

-- | Construct the call-graph for all functions that we know.