content: -- File generated by the BNF Converter (bnfc 2.9.5).
  
  {-# LANGUAGE CPP #-}
  {-# LANGUAGE FlexibleInstances #-}
  {-# LANGUAGE LambdaCase #-}
  #if __GLASGOW_HASKELL__ <= 708
  {-# LANGUAGE OverlappingInstances #-}
  #endif
  
  -- | Pretty-printer for PrintRawPVSLang.
  
  module PrintRawPVSLang where
  
  import Prelude
    ( ($), (.)
    , Bool(..), (==), (<)
    , Int, Integer, Double, (+), (-), (*)
    , String, (++)
    , ShowS, showChar, showString
    , all, elem, foldr, id, map, null, replicate, shows, span
    )
  import Data.Char ( Char, isSpace )
  import qualified AbsRawPVSLang
  
  -- | The top-level printing method.
  
  printTree :: Print a => a -> String
  printTree = render . prt 0
  
  type Doc = [ShowS] -> [ShowS]
  
  doc :: ShowS -> Doc
  doc = (:)
  
  render :: Doc -> String
  render d = rend 0 False (map ($ "") $ d []) ""
    where
    rend
      :: Int        -- ^ Indentation level.
      -> Bool       -- ^ Pending indentation to be output before next character?
      -> [String]
      -> ShowS
    rend i p = \case
        "["      :ts -> char '[' . rend i False ts
        "("      :ts -> char '(' . rend i False ts
        "{"      :ts -> onNewLine i     p . showChar   '{'  . new (i+1) ts
        "}" : ";":ts -> onNewLine (i-1) p . showString "};" . new (i-1) ts
        "}"      :ts -> onNewLine (i-1) p . showChar   '}'  . new (i-1) ts
        [";"]        -> char ';'
        ";"      :ts -> char ';' . new i ts
        t  : ts@(s:_) | closingOrPunctuation s
                     -> pending . showString t . rend i False ts
        t        :ts -> pending . space t      . rend i False ts
        []           -> id
      where
      -- Output character after pending indentation.
      char :: Char -> ShowS
      char c = pending . showChar c
  
      -- Output pending indentation.
      pending :: ShowS
      pending = if p then indent i else id
  
    -- Indentation (spaces) for given indentation level.
    indent :: Int -> ShowS
    indent i = replicateS (2*i) (showChar ' ')
  
    -- Continue rendering in new line with new indentation.
    new :: Int -> [String] -> ShowS
    new j ts = showChar '\n' . rend j True ts
  
    -- Make sure we are on a fresh line.
    onNewLine :: Int -> Bool -> ShowS
    onNewLine i p = (if p then id else showChar '\n') . indent i
  
    -- Separate given string from following text by a space (if needed).
    space :: String -> ShowS
    space t s =
      case (all isSpace t, null spc, null rest) of
        (True , _   , True ) -> []             -- remove trailing space
        (False, _   , True ) -> t              -- remove trailing space
        (False, True, False) -> t ++ ' ' : s   -- add space if none
        _                    -> t ++ s
      where
        (spc, rest) = span isSpace s
  
    closingOrPunctuation :: String -> Bool
    closingOrPunctuation [c] = c `elem` closerOrPunct
    closingOrPunctuation _   = False
  
    closerOrPunct :: String
    closerOrPunct = ")],;"
  
  parenth :: Doc -> Doc
  parenth ss = doc (showChar '(') . ss . doc (showChar ')')
  
  concatS :: [ShowS] -> ShowS
  concatS = foldr (.) id
  
  concatD :: [Doc] -> Doc
  concatD = foldr (.) id
  
  replicateS :: Int -> ShowS -> ShowS
  replicateS n f = concatS (replicate n f)
  
  -- | The printer class does the job.
  
  class Print a where
    prt :: Int -> a -> Doc
  
  instance {-# OVERLAPPABLE #-} Print a => Print [a] where
    prt i = concatD . map (prt i)
  
  instance Print Char where
    prt _ c = doc (showChar '\'' . mkEsc '\'' c . showChar '\'')
  
  instance Print String where
    prt _ = printString
  
  printString :: String -> Doc
  printString s = doc (showChar '"' . concatS (map (mkEsc '"') s) . showChar '"')
  
  mkEsc :: Char -> Char -> ShowS
  mkEsc q = \case
    s | s == q -> showChar '\\' . showChar s
    '\\' -> showString "\\\\"
    '\n' -> showString "\\n"
    '\t' -> showString "\\t"
    s -> showChar s
  
  prPrec :: Int -> Int -> Doc -> Doc
  prPrec i j = if j < i then parenth else id
  
  instance Print Integer where
    prt _ x = doc (shows x)
  
  instance Print Double where
    prt _ x = doc (shows x)
  
  instance Print AbsRawPVSLang.Id where
    prt _ (AbsRawPVSLang.Id i) = doc $ showString i
  instance Print [AbsRawPVSLang.Id] where
    prt _ [] = concatD []
    prt _ [x] = concatD [prt 0 x]
    prt _ (x:xs) = concatD [prt 0 x, doc (showString ","), prt 0 xs]
  
  instance Print AbsRawPVSLang.ElsIf where
    prt i = \case
      AbsRawPVSLang.ElsIf expr1 expr2 -> prPrec i 0 (concatD [doc (showString "ELSIF"), prt 0 expr1, doc (showString "THEN"), prt 0 expr2])
  
  instance Print [AbsRawPVSLang.ElsIf] where
    prt _ [] = concatD []
    prt _ [x] = concatD [prt 0 x]
    prt _ (x:xs) = concatD [prt 0 x, prt 0 xs]
  
  instance Print AbsRawPVSLang.LetElem where
    prt i = \case
      AbsRawPVSLang.LetElem id_ expr -> prPrec i 0 (concatD [prt 0 id_, doc (showString "="), prt 0 expr])
      AbsRawPVSLang.LetElemType id_ type_ expr -> prPrec i 0 (concatD [prt 0 id_, doc (showString ":"), prt 0 type_, doc (showString "="), prt 0 expr])
  
  instance Print [AbsRawPVSLang.LetElem] where
    prt _ [] = concatD []
    prt _ [x] = concatD [prt 0 x]
    prt _ (x:xs) = concatD [prt 0 x, doc (showString ","), prt 0 xs]
  
  instance Print AbsRawPVSLang.RecordElem where
    prt i = \case
      AbsRawPVSLang.RecordElem id_ expr -> prPrec i 0 (concatD [prt 0 id_, doc (showString ":="), prt 0 expr])
  
  instance Print [AbsRawPVSLang.RecordElem] where
    prt _ [] = concatD []
    prt _ [x] = concatD [prt 0 x]
    prt _ (x:xs) = concatD [prt 0 x, doc (showString ","), prt 0 xs]
  
  instance Print AbsRawPVSLang.LambdaKeyWord where
    prt i = \case
      AbsRawPVSLang.LambdaWord1 -> prPrec i 0 (concatD [doc (showString "LAMBDA")])
      AbsRawPVSLang.LambdaWord2 -> prPrec i 0 (concatD [doc (showString "lambda")])
  
  instance Print AbsRawPVSLang.LambdaExpr where
    prt i = \case
      AbsRawPVSLang.Lambda lambdakeyword id_1 expr1 expr2 id_2 type_ expr3 -> prPrec i 0 (concatD [prt 0 lambdakeyword, doc (showString "("), prt 0 id_1, doc (showString ":"), doc (showString "SUBRANGE"), doc (showString "("), prt 0 expr1, doc (showString ","), prt 0 expr2, doc (showString ")"), doc (showString ","), prt 0 id_2, doc (showString ":"), prt 0 type_, doc (showString ")"), doc (showString ":"), prt 0 expr3])
  
  instance Print [AbsRawPVSLang.Expr] where
    prt _ [] = concatD []
    prt _ [x] = concatD [prt 0 x]
    prt _ (x:xs) = concatD [prt 0 x, doc (showString ","), prt 0 xs]
  
  instance Print AbsRawPVSLang.Expr where
    prt i = \case
      AbsRawPVSLang.Let letelems expr -> prPrec i 0 (concatD [doc (showString "LET"), prt 0 letelems, doc (showString "IN"), prt 0 expr])
      AbsRawPVSLang.Or expr1 expr2 -> prPrec i 1 (concatD [prt 1 expr1, doc (showString "OR"), prt 2 expr2])
      AbsRawPVSLang.And expr1 expr2 -> prPrec i 2 (concatD [prt 2 expr1, doc (showString "AND"), prt 3 expr2])
      AbsRawPVSLang.Not expr -> prPrec i 3 (concatD [doc (showString "NOT"), prt 4 expr])
      AbsRawPVSLang.Eq expr1 expr2 -> prPrec i 4 (concatD [prt 5 expr1, doc (showString "="), prt 5 expr2])
      AbsRawPVSLang.Neq expr1 expr2 -> prPrec i 4 (concatD [prt 5 expr1, doc (showString "/="), prt 5 expr2])
      AbsRawPVSLang.Lt expr1 expr2 -> prPrec i 4 (concatD [prt 5 expr1, doc (showString "<"), prt 5 expr2])
      AbsRawPVSLang.LtE expr1 expr2 -> prPrec i 4 (concatD [prt 5 expr1, doc (showString "<="), prt 5 expr2])
      AbsRawPVSLang.Gt expr1 expr2 -> prPrec i 4 (concatD [prt 5 expr1, doc (showString ">"), prt 5 expr2])
      AbsRawPVSLang.GtE expr1 expr2 -> prPrec i 4 (concatD [prt 5 expr1, doc (showString ">="), prt 5 expr2])
      AbsRawPVSLang.ExprAdd expr1 expr2 -> prPrec i 5 (concatD [prt 5 expr1, doc (showString "+"), prt 6 expr2])
      AbsRawPVSLang.ExprSub expr1 expr2 -> prPrec i 5 (concatD [prt 5 expr1, doc (showString "-"), prt 6 expr2])
      AbsRawPVSLang.ExprMul expr1 expr2 -> prPrec i 6 (concatD [prt 6 expr1, doc (showString "*"), prt 7 expr2])
      AbsRawPVSLang.ExprDiv expr1 expr2 -> prPrec i 6 (concatD [prt 6 expr1, doc (showString "/"), prt 7 expr2])
      AbsRawPVSLang.With expr1 expr2 expr3 -> prPrec i 6 (concatD [prt 6 expr1, doc (showString "WITH"), doc (showString "["), prt 0 expr2, doc (showString ":="), prt 0 expr3, doc (showString "]")])
      AbsRawPVSLang.ExprNeg expr -> prPrec i 7 (concatD [doc (showString "-"), prt 8 expr])
      AbsRawPVSLang.ExprPow expr1 expr2 -> prPrec i 8 (concatD [prt 9 expr1, doc (showString "^"), prt 8 expr2])
      AbsRawPVSLang.If expr1 expr2 expr3 -> prPrec i 9 (concatD [doc (showString "IF"), prt 0 expr1, doc (showString "THEN"), prt 0 expr2, doc (showString "ELSE"), prt 0 expr3, doc (showString "ENDIF")])
      AbsRawPVSLang.ListIf expr1 expr2 elsifs expr3 -> prPrec i 9 (concatD [doc (showString "IF"), prt 0 expr1, doc (showString "THEN"), prt 0 expr2, prt 0 elsifs, doc (showString "ELSE"), prt 0 expr3, doc (showString "ENDIF")])
      AbsRawPVSLang.For expr1 expr2 expr3 lambdaexpr -> prPrec i 9 (concatD [doc (showString "for"), doc (showString "("), prt 0 expr1, doc (showString ","), prt 0 expr2, doc (showString ","), prt 0 expr3, doc (showString ","), prt 0 lambdaexpr, doc (showString ")")])
      AbsRawPVSLang.ForDown expr1 expr2 expr3 lambdaexpr -> prPrec i 9 (concatD [doc (showString "for_down"), doc (showString "("), prt 0 expr1, doc (showString ","), prt 0 expr2, doc (showString ","), prt 0 expr3, doc (showString ","), prt 0 lambdaexpr, doc (showString ")")])
      AbsRawPVSLang.TupleIndex id_ n -> prPrec i 10 (concatD [prt 0 id_, doc (showString "`"), prt 0 n])
      AbsRawPVSLang.RecordField id_1 id_2 -> prPrec i 10 (concatD [prt 0 id_1, doc (showString "`"), prt 0 id_2])
      AbsRawPVSLang.TupleFunIndex id_ exprs n -> prPrec i 10 (concatD [prt 0 id_, doc (showString "("), prt 0 exprs, doc (showString ")"), doc (showString "`"), prt 0 n])
      AbsRawPVSLang.RecordFunField id_1 exprs id_2 -> prPrec i 10 (concatD [prt 0 id_1, doc (showString "("), prt 0 exprs, doc (showString ")"), doc (showString "`"), prt 0 id_2])
      AbsRawPVSLang.RecordExpr recordelems -> prPrec i 10 (concatD [doc (showString "(#"), prt 0 recordelems, doc (showString "#)")])
      AbsRawPVSLang.TupleExpr exprs -> prPrec i 10 (concatD [doc (showString "("), prt 0 exprs, doc (showString ")")])
      AbsRawPVSLang.Call id_ exprs -> prPrec i 10 (concatD [prt 0 id_, doc (showString "("), prt 0 exprs, doc (showString ")")])
      AbsRawPVSLang.ExprId id_ -> prPrec i 10 (concatD [prt 0 id_])
      AbsRawPVSLang.Int n -> prPrec i 10 (concatD [prt 0 n])
      AbsRawPVSLang.Rat d -> prPrec i 10 (concatD [prt 0 d])
      AbsRawPVSLang.BTrue -> prPrec i 10 (concatD [doc (showString "TRUE")])
      AbsRawPVSLang.BFalse -> prPrec i 10 (concatD [doc (showString "FALSE")])
  
  instance Print AbsRawPVSLang.FieldDecls where
    prt i = \case
      AbsRawPVSLang.FieldDecls id_ type_ -> prPrec i 0 (concatD [prt 0 id_, doc (showString ":"), prt 0 type_])
  
  instance Print [AbsRawPVSLang.Type] where
    prt _ [] = concatD []
    prt _ [x] = concatD [prt 0 x]
    prt _ (x:xs) = concatD [prt 0 x, doc (showString ","), prt 0 xs]
  
  instance Print [AbsRawPVSLang.FieldDecls] where
    prt _ [] = concatD []
    prt _ [x] = concatD [prt 0 x]
    prt _ (x:xs) = concatD [prt 0 x, doc (showString ","), prt 0 xs]
  
  instance Print AbsRawPVSLang.Type where
    prt i = \case
      AbsRawPVSLang.TypeSimple id_ -> prPrec i 0 (concatD [prt 0 id_])
      AbsRawPVSLang.ParametricTypeBi id_ n1 n2 -> prPrec i 0 (concatD [prt 0 id_, doc (showString "("), prt 0 n1, doc (showString ","), prt 0 n2, doc (showString ")")])
      AbsRawPVSLang.TypeBelow expr -> prPrec i 0 (concatD [doc (showString "below"), doc (showString "("), prt 0 expr, doc (showString ")")])
      AbsRawPVSLang.TypeRecord fielddeclss -> prPrec i 0 (concatD [doc (showString "[#"), prt 0 fielddeclss, doc (showString "#]")])
      AbsRawPVSLang.TypeTuple types -> prPrec i 0 (concatD [doc (showString "["), prt 0 types, doc (showString "]")])
      AbsRawPVSLang.TypeArray types type_ -> prPrec i 0 (concatD [doc (showString "ARRAY"), doc (showString "["), prt 0 types, doc (showString "->"), prt 0 type_, doc (showString "]")])
      AbsRawPVSLang.TypeFun types type_ -> prPrec i 0 (concatD [doc (showString "FUNCTION"), doc (showString "["), prt 0 types, doc (showString "->"), prt 0 type_, doc (showString "]")])
      AbsRawPVSLang.TypeFun2 types type_ -> prPrec i 0 (concatD [doc (showString "["), prt 0 types, doc (showString "->"), prt 0 type_, doc (showString "]")])
      AbsRawPVSLang.TypeList type_ -> prPrec i 0 (concatD [doc (showString "list"), doc (showString "["), prt 0 type_, doc (showString "]")])
  
  instance Print [AbsRawPVSLang.Arg] where
    prt _ [] = concatD []
    prt _ [x] = concatD [prt 0 x]
    prt _ (x:xs) = concatD [prt 0 x, doc (showString ","), prt 0 xs]
  
  instance Print AbsRawPVSLang.Arg where
    prt i = \case
      AbsRawPVSLang.FArg ids type_ -> prPrec i 0 (concatD [prt 0 ids, doc (showString ":"), prt 0 type_])
      AbsRawPVSLang.FArgGuard ids type_ expr -> prPrec i 0 (concatD [prt 0 ids, doc (showString ":"), prt 0 type_, doc (showString "|"), prt 0 expr])
  
  instance Print AbsRawPVSLang.Args where
    prt i = \case
      AbsRawPVSLang.FArgs args -> prPrec i 0 (concatD [prt 0 args])
      AbsRawPVSLang.FArgsNoType ids -> prPrec i 0 (concatD [prt 0 ids])
  
  instance Print [AbsRawPVSLang.Decl] where
    prt _ [] = concatD []
    prt _ [x] = concatD [prt 0 x]
    prt _ (x:xs) = concatD [prt 0 x, prt 0 xs]
  
  instance Print AbsRawPVSLang.Decl where
    prt i = \case
      AbsRawPVSLang.DeclN id_ args type_ expr -> prPrec i 0 (concatD [prt 0 id_, doc (showString "("), prt 0 args, doc (showString ")"), doc (showString ":"), prt 0 type_, doc (showString "="), prt 0 expr])
      AbsRawPVSLang.Decl0 id_ type_ expr -> prPrec i 0 (concatD [prt 0 id_, doc (showString ":"), prt 0 type_, doc (showString "="), prt 0 expr])
  
  instance Print AbsRawPVSLang.Imp where
    prt i = \case
      AbsRawPVSLang.LibImp ids -> prPrec i 0 (concatD [doc (showString "IMPORTING"), prt 0 ids])
  
  instance Print AbsRawPVSLang.Program where
    prt i = \case
      AbsRawPVSLang.ProgImp id_1 imp decls id_2 -> prPrec i 0 (concatD [prt 0 id_1, doc (showString ":"), doc (showString "THEORY"), doc (showString "BEGIN"), prt 0 imp, prt 0 decls, doc (showString "END"), prt 0 id_2])
      AbsRawPVSLang.Prog id_1 decls id_2 -> prPrec i 0 (concatD [prt 0 id_1, doc (showString ":"), doc (showString "THEORY"), doc (showString "BEGIN"), prt 0 decls, doc (showString "END"), prt 0 id_2])
  