<commit_before>{-# LANGUAGE CPP, TemplateHaskell #-}
{-# OPTIONS_GHC -fno-warn-orphans #-}
-----------------------------------------------------------------------------
-- |
-- Module      :  Text.Show.Text.Text.Read
-- Copyright   :  (C) 2014 <NAME>
-- License     :  BSD-style (see the file LICENSE)
-- Maintainer  :  <NAME>
-- Stability   :  Experimental
-- Portability :  GHC
-- 
-- Monomorphic 'Show' function for 'Lexeme' (and 'Number', if using a
-- recent-enough version of @base@).
----------------------------------------------------------------------------
module Text.Show.Text.Text.Read (
      showbLexemePrec
#if MIN_VERSION_base(4,7,0)
    , showbNumberPrec
#endif
    ) where

import Data.Text.Lazy.Builder (Builder)

import Text.Read.Lex (Lexeme)
#if MIN_VERSION_base(4,7,0)
import Text.Read.Lex (Number)
#endif

import Text.Show.Text.Class (showbPrec)
import Text.Show.Text.Data.Char ()
import Text.Show.Text.Data.Integral ()
import Text.Show.Text.Data.List ()
import Text.Show.Text.Data.Maybe ()
import Text.Show.Text.TH.Internal (deriveShow)

-- | Convert a 'Lexeme' to a 'Builder' with the given precedence.
showbLexemePrec :: Int -> Lexeme -> Builder
showbLexemePrec = showbPrec
{-# INLINE showbLexemePrec #-}

#if MIN_VERSION_base(4,7,0)
-- | Convert a 'Number' to a 'Builder' with the given precedence.
showbNumberPrec :: Int -> Number -> Builder
showbNumberPrec = showbPrec
{-# INLINE showbNumberPrec #-}
#endif

$(deriveShow ''Lexeme)
#if MIN_VERSION_base(4,7,0)
$(deriveShow ''Number)
#endif<commit_msg>Don't use TH for Text.Read.Lex data types<commit_after>{-# LANGUAGE CPP, NoImplicitPrelude, OverloadedStrings #-}
{-# OPTIONS_GHC -fno-warn-orphans #-}
-----------------------------------------------------------------------------
-- |
-- Module      :  Text.Show.Text.Text.Read
-- Copyright   :  (C) 2014 <NAME>
-- License     :  BSD-style (see the file LICENSE)
-- Maintainer  :  <NAME>
-- Stability   :  Experimental
-- Portability :  GHC
-- 
-- Monomorphic 'Show' function for 'Lexeme' (and 'Number', if using a
-- recent-enough version of @base@).
----------------------------------------------------------------------------
module Text.Show.Text.Text.Read (
      showbLexemePrec
#if MIN_VERSION_base(4,7,0)
    , showbNumberPrec
#endif
    ) where

import           Data.Text.Lazy.Builder (Builder, fromString)

import           GHC.Show (appPrec, appPrec1)

import qualified Prelude as P
import           Prelude hiding (Show)

import           Text.Read.Lex (Lexeme(..))
#if MIN_VERSION_base(4,7,0)
import           Text.Read.Lex (Number)
#endif
import           Text.Show.Text.Class (Show(showbPrec), showbParen)
import           Text.Show.Text.Data.Char (showbLitChar)
#if !(MIN_VERSION_base(4,6,0))
import           Text.Show.Text.Data.Integral (showbIntegerPrec, showbRatioPrec)
#endif
import           Text.Show.Text.Utils ((<>))

-- | Convert a 'Lexeme' to a 'Builder' with the given precedence.
showbLexemePrec :: Int -> Lexeme -> Builder
showbLexemePrec p (Char c)   = showbParen (p > appPrec) $ "Char "   <> showbLitChar c
showbLexemePrec p (String s) = showbParen (p > appPrec) $ "String " <> fromString s
showbLexemePrec p (Punc pun) = showbParen (p > appPrec) $ "Punc "   <> fromString pun
showbLexemePrec p (Ident i)  = showbParen (p > appPrec) $ "Ident "  <> fromString i
showbLexemePrec p (Symbol s) = showbParen (p > appPrec) $ "Symbol " <> fromString s
#if MIN_VERSION_base(4,6,0)
showbLexemePrec p (Number n) = showbParen (p > appPrec) $ "Number " <> fromString (P.showsPrec appPrec1 n "")
#else
showbLexemePrec p (Int i)    = showbParen (p > appPrec) $ "Int "    <> showbIntegerPrec appPrec1 i
showbLexemePrec p (Rat r)    = showbParen (p > appPrec) $ "Rat "    <> showbRatioPrec appPrec1 r
#endif
showbLexemePrec _ EOF        = "EOF"
{-# INLINE showbLexemePrec #-}

#if MIN_VERSION_base(4,7,0)
-- | Convert a 'Number' to a 'Builder' with the given precedence.
showbNumberPrec :: Int -> Number -> Builder
showbNumberPrec p n = fromString $ P.showsPrec p n ""
{-# INLINE showbNumberPrec #-}
#endif

instance Show Lexeme where
    showbPrec = showbLexemePrec
    {-# INLINE showbPrec #-}

#if MIN_VERSION_base(4,7,0)
instance Show Number where
    showbPrec = showbNumberPrec
    {-# INLINE showbPrec #-}
#endif
{'fraction_non_alphanumeric': 0.1970939770330443, 'fraction_numerical': 0.009842981017108038, 'mean_word_length': 2.5865546218487396, 'pattern_counts': {'":': 0, '<': 16, '<?xml version=': 0, '>': 32, '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': '4905321', 'n_tokens_mistral': 1533, 'n_tokens_neox': 1420, 'n_words': 364}