<commit_before>module Main where
import System.Directory
import System.FilePath.Glob
import Text.ParserCombinators.Parsec.Char
import Text.Parsec
import Data.List
import System.Environment

-- | Read the library from a directory
readRawLibrary :: FilePath -> IO [String]
readRawLibrary libDir = do
    -- Get the .hs files in the library directory
    libDirHsFiles <- filter (match $ compile "*.hs") <$> listDirectory libDir

    -- Get the contents of the library
    libFilesContents <- withCurrentDirectory libDir 
                     $ sequence $ readFile <$> libDirHsFiles

    -- Return the contest
    return ["{" ++ s ++ "}" | Right s <- parse parseJSONComment "" <$> libFilesContents]

-- | Parse the {-% %-} blocks
parseJSONComment :: Parsec String () String
parseJSONComment = manyTill anyToken (string "{-%") >> manyTill anyToken (string "%-}")

-- | Turn a list of JSON blobs in to a JSON list of JSON things
libify :: [String] -> String
libify jsons = "{\"library\":[" ++ intercalate "," jsons ++ "]}"

-- | Produce a single JSON file called "library.json"
--   from a library
main = do
  args <- getArgs
  let dir = head args
  library <- libify <$> readRawLibrary dir
  writeFile "library.json" library
<commit_msg>Pretty up<commit_after>module Main where
import System.Directory
import System.FilePath.Glob
import Text.ParserCombinators.Parsec.Char
import Text.Parsec
import Data.List
import System.Environment

-- | Read the library from a directory
readRawLibrary :: FilePath -> IO [String]
readRawLibrary libDir = do
  -- Get the .hs files in the library directory
  libDirHsFiles <- filter (match $ compile "*.hs") <$> listDirectory libDir

  -- Get the contents of the library
  libFilesContents <- withCurrentDirectory libDir 
                   $ sequence $ readFile <$> libDirHsFiles

  -- Return the contest
  return ["{" ++ s ++ "}" | Right s <- parse parseJSONComment "" <$> libFilesContents]

-- | Parse the {-% %-} blocks
parseJSONComment :: Parsec String () String
parseJSONComment = manyTill anyToken (string "{-%") >> manyTill anyToken (string "%-}")

-- | Turn a list of JSON blobs in to a JSON list of JSON things
libify :: [String] -> String
libify jsons = "{\"library\":[" ++ intercalate "," jsons ++ "]}"

-- | Produce a single JSON file called "library.json"
--   from a library
main = do
  args <- getArgs
  let dir = head args
  library <- libify <$> readRawLibrary dir
  writeFile "library.json" library

{'fraction_non_alphanumeric': 0.12091503267973856, 'fraction_numerical': 0.0, 'mean_word_length': 3.468978102189781, 'pattern_counts': {'":': 2, '<': 21, '<?xml version=': 0, '>': 19, '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': '1832312', 'n_tokens_mistral': 719, 'n_tokens_neox': 697, 'n_words': 253}