writeIsaFile :: HetcatsOpts -> FilePath -> G_theory -> LibName -> IRI
             -> IO ()
writeIsaFile opts filePrefix raw_gTh ln i = do
  let Result ds mTh = createIsaTheory raw_gTh
      addThn = (++ '_' : iriToStringShortUnsecure i)
      fp = addThn filePrefix
  showDiags opts ds
  case mTh of
    Nothing ->
      putIfVerbose opts 0 $ "could not translate to Isabelle theory: " ++ fp
    Just (sign, sens) -> do
      let tn = addThn . reverse . takeWhile (/= '/') . reverse $ case
               libToFileName ln of
                   [] -> filePrefix
                   lstr -> lstr
          sf = shows (printIsaTheory tn sign sens) "\n"
          f = fp ++ ".thy"
      case parse parseTheory f sf of
        Left err -> putIfVerbose opts 0 $ show err
        _ -> putIfVerbose opts 3 $ "reparsed: " ++ f
      writeVerbFile opts f sf
      when (hasPrfOut opts && verbose opts >= 3) $ let
        (axs, rest) = partition ( \ s -> isAxiom s || isDef s) sens
         in mapM_ ( \ s -> let
           tnf = tn ++ "_" ++ senAttr s
           tf = fp ++ "_" ++ senAttr s ++ ".thy"
           in writeVerbFile opts tf $ shows
                   (printIsaTheory tnf sign $ s : axs) "\n") rest
writeIsaFile :: HetcatsOpts -> FilePath -> G_theory -> LibName -> IRI
             -> IO ()
writeIsaFile opts filePrefix raw_gTh ln i = do
  let Result ds mTh = createIsaTheory raw_gTh
      addThn = (++ '_' : iriToStringShortUnsecure i)
      fp = addThn filePrefix
  showDiags opts ds
  case mTh of
    Nothing ->
      putIfVerbose opts 0 $ "could not translate to Isabelle theory: " ++ fp
    Just (sign, sens) -> do
      let tn = addThn . reverse . takeWhile (/= '/') . reverse $ case
               libToFileName ln of
                   [] -> filePrefix
                   lstr -> lstr
          sf = shows (printIsaTheory tn sign sens) "\n"
          f = fp ++ ".thy"
      case parse parseTheory f sf of
        Left err -> putIfVerbose opts 0 $ show err
        _ -> putIfVerbose opts 3 $ "reparsed: " ++ f
      writeVerbFile opts f sf
      when (hasPrfOut opts && verbose opts >= 3) $ let
        (axs, rest) = partition ( \ s -> isAxiom s || isDef s) sens
         in mapM_ ( \ s -> let
           tnf = tn ++ "_" ++ senAttr s
           tf = fp ++ "_" ++ senAttr s ++ ".thy"
           in writeVerbFile opts tf $ shows
                   (printIsaTheory tnf sign $ s : axs) "\n") rest
writeIsaFile opts filePrefix raw_gTh ln i = do
  let Result ds mTh = createIsaTheory raw_gTh
      addThn = (++ '_' : iriToStringShortUnsecure i)
      fp = addThn filePrefix
  showDiags opts ds
  case mTh of
    Nothing ->
      putIfVerbose opts 0 $ "could not translate to Isabelle theory: " ++ fp
    Just (sign, sens) -> do
      let tn = addThn . reverse . takeWhile (/= '/') . reverse $ case
               libToFileName ln of
                   [] -> filePrefix
                   lstr -> lstr
          sf = shows (printIsaTheory tn sign sens) "\n"
          f = fp ++ ".thy"
      case parse parseTheory f sf of
        Left err -> putIfVerbose opts 0 $ show err
        _ -> putIfVerbose opts 3 $ "reparsed: " ++ f
      writeVerbFile opts f sf
      when (hasPrfOut opts && verbose opts >= 3) $ let
        (axs, rest) = partition ( \ s -> isAxiom s || isDef s) sens
         in mapM_ ( \ s -> let
           tnf = tn ++ "_" ++ senAttr s
           tf = fp ++ "_" ++ senAttr s ++ ".thy"
           in writeVerbFile opts tf $ shows
                   (printIsaTheory tnf sign $ s : axs) "\n") rest