<commit_before>{-# LANGUAGE BangPatterns        #-}
{-# LANGUAGE CPP                 #-}
{-# LANGUAGE DefaultSignatures   #-}
{-# LANGUAGE LambdaCase          #-}
{-# LANGUAGE OverloadedStrings   #-}
{-# LANGUAGE ScopedTypeVariables #-}

-- | __Warning: internal module!__ This means that the API may change
-- arbitrarily between versions without notice. Depending on this module may
-- lead to unexpected breakages, so proceed with caution!
--
-- For a stable API, use the non-internal modules. For the special case of
-- writing adaptors to this library’s @'Doc'@ type, see
-- "Data.Text.Prettyprint.Doc.Internal.Type".
module Data.Text.Prettyprint.Doc.Internal where



import           Data.Int
import           Data.List.NonEmpty (NonEmpty (..))
import           Data.Maybe
import           Data.String        (IsString (..))
import           Data.Text          (Text)
import qualified Data.Text          as T
import qualified Data.Text.Lazy     as Lazy
import           Data.Void
import           Data.Word

-- Depending on the Cabal file, this might be from base, or for older builds,
-- from the semigroups package.
import Data.Semigroup

-- Base 4.8 introduced Foldable, Traversable and Monoid to the Prelude, and
-- Natural to Base.
#if MIN_VERSION_base(4,8,0)
import Numeric.Natural
#else
import Data.Foldable (Foldable (..))
import Data.Monoid   hiding ((<>))
import Prelude       hiding (foldr, foldr1)
#endif



-- $setup
-- >>> :set -XOverloadedStrings
-- >>> import qualified Data.Text.IO as T
-- >>> import Data.Text.Prettyprint.Doc.Render.Text
-- >>> import Test.QuickCheck.Modifiers
-- >>> let layoutOptions w = LayoutOptions { layoutRibbonFraction = 1, layoutPageWidth = CharsPerLine w }
-- >>> let putDocW w doc = renderIO System.IO.stdout (layoutPretty (layoutOptions w) doc)



-- | The abstract data type @'Doc' ann@ represents pretty documents that have
-- been annotated with data of type @ann@.
--
-- More specifically, a value of type @'Doc'@ represents a non-empty set of
-- possible layouts of a document. The layout functions select one of these
-- possibilities.
--
-- The simplest way to display a 'Doc' is via the 'Show' class.
--
-- >>> putStrLn (show (vsep ["hello", "world"]))
-- hello
-- world
data Doc ann =

    -- | Occurs when flattening a line. The layouter will reject this document,
    -- choosing a more suitable rendering.
    Fail

    -- | The empty document; unit of 'Cat' (observationally)
    | Empty

    -- | invariant: char is not '\n'
    | Char Char

    -- | Invariants: at least two characters long, does not contain '\n'. For
    -- empty documents, there is @Empty@; for singleton documents, there is
    -- @Char@; newlines should be replaced by e.g. @Line@.
    --
    -- Since the frequently used 'T.length' of 'Text' is /O(length)/, we cache
    -- it in this constructor.
    | Text {-# UNPACK #-} !Int Text

    -- | Line break
    | Line

    -- | Lay out the first 'Doc', but when flattened (via 'group'), fall back to
    -- the second. The flattened version should in general be higher and
    -- narrower than the fallback.
    | FlatAlt (Doc ann) (Doc ann)

    -- | Concatenation of two documents
    | Cat (Doc ann) (Doc ann)

    -- | Document indented by a number of columns
    | Nest !Int (Doc ann)

    -- | Invariant: first lines of first '(Doc ann)' longer than the first lines of
    -- the second one. Used to implement layout alternatives for 'group'.
    | Union (Doc ann) (Doc ann)
<commit_msg>Remove UNPACK pragms (since GHC unboxes automatically)<commit_after>{-# LANGUAGE BangPatterns        #-}
{-# LANGUAGE CPP                 #-}
{-# LANGUAGE DefaultSignatures   #-}
{-# LANGUAGE LambdaCase          #-}
{-# LANGUAGE OverloadedStrings   #-}
{-# LANGUAGE ScopedTypeVariables #-}

-- | __Warning: internal module!__ This means that the API may change
-- arbitrarily between versions without notice. Depending on this module may
-- lead to unexpected breakages, so proceed with caution!
--
-- For a stable API, use the non-internal modules. For the special case of
-- writing adaptors to this library’s @'Doc'@ type, see
-- "Data.Text.Prettyprint.Doc.Internal.Type".
module Data.Text.Prettyprint.Doc.Internal where



import           Data.Int
import           Data.List.NonEmpty (NonEmpty (..))
import           Data.Maybe
import           Data.String        (IsString (..))
import           Data.Text          (Text)
import qualified Data.Text          as T
import qualified Data.Text.Lazy     as Lazy
import           Data.Void
import           Data.Word

-- Depending on the Cabal file, this might be from base, or for older builds,
-- from the semigroups package.
import Data.Semigroup

-- Base 4.8 introduced Foldable, Traversable and Monoid to the Prelude, and
-- Natural to Base.
#if MIN_VERSION_base(4,8,0)
import Numeric.Natural
#else
import Data.Foldable (Foldable (..))
import Data.Monoid   hiding ((<>))
import Prelude       hiding (foldr, foldr1)
#endif



-- $setup
-- >>> :set -XOverloadedStrings
-- >>> import qualified Data.Text.IO as T
-- >>> import Data.Text.Prettyprint.Doc.Render.Text
-- >>> import Test.QuickCheck.Modifiers
-- >>> let layoutOptions w = LayoutOptions { layoutRibbonFraction = 1, layoutPageWidth = CharsPerLine w }
-- >>> let putDocW w doc = renderIO System.IO.stdout (layoutPretty (layoutOptions w) doc)



-- | The abstract data type @'Doc' ann@ represents pretty documents that have
-- been annotated with data of type @ann@.
--
-- More specifically, a value of type @'Doc'@ represents a non-empty set of
-- possible layouts of a document. The layout functions select one of these
-- possibilities.
--
-- The simplest way to display a 'Doc' is via the 'Show' class.
--
-- >>> putStrLn (show (vsep ["hello", "world"]))
-- hello
-- world
data Doc ann =

    -- | Occurs when flattening a line. The layouter will reject this document,
    -- choosing a more suitable rendering.
    Fail

    -- | The empty document; unit of 'Cat' (observationally)
    | Empty

    -- | invariant: char is not '\n'
    | Char Char

    -- | Invariants: at least two characters long, does not contain '\n'. For
    -- empty documents, there is @Empty@; for singleton documents, there is
    -- @Char@; newlines should be replaced by e.g. @Line@.
    --
    -- Since the frequently used 'T.length' of 'Text' is /O(length)/, we cache
    -- it in this constructor.
    | Text !Int Text

    -- | Line break
    | Line

    -- | Lay out the first 'Doc', but when flattened (via 'group'), fall back to
    -- the second. The flattened version should in general be higher and
    -- narrower than the fallback.
    | FlatAlt (Doc ann) (Doc ann)

    -- | Concatenation of two documents
    | Cat (Doc ann) (Doc ann)

    -- | Document indented by a number of columns
    | Nest !Int (Doc ann)

    -- | Invariant: first lines of first '(Doc ann)' longer than the first lines of
    -- the second one. Used to implement layout alternatives for 'group'.
    | Union (Doc ann) (Doc ann)

{'fraction_non_alphanumeric': 0.11384439359267734, 'fraction_numerical': 0.002002288329519451, 'mean_word_length': 2.661256544502618, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 47, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3429622', 'n_tokens_mistral': 2100, 'n_tokens_neox': 2015, 'n_words': 813}