<commit_before>module Main where

import System.Environment (getArgs)
import Text.CSS.Parse
import Data.Text hiding (head)

main :: IO ()
main = do
  args <- getArgs
  parseFile args
  where showFile [] = printError
        showFile (filePath:_) = readFile filePath >>= putStr
        
        parseFile [] = printError
        parseFile (filePath:_) = do contents <- readFile filePath
                                    let Right rules = parseBlocks (pack contents)
                                    print $ head rules
          
        printError = putStrLn "Need a file to parse"
        <commit_msg>Adds some Ruleset and Rule types and printing the first 3<commit_after>{-# LANGUAGE OverloadedStrings #-}
module Main where

import System.Environment (getArgs)
import Text.CSS.Parse
import Data.Text (Text, pack)

main :: IO ()
main = do
  args <- getArgs
  parseFile args
  where showFile [] = printError
        showFile (filePath:_) = readFile filePath >>= putStr
        
        parseFile [] = printError
        parseFile (filePath:_) = do contents <- readFile filePath
                                    either printParseError displayRulesets $ parseBlocks (pack contents)
                                    
        displayRulesets rawRulesets = do let rulesets = map buildRuleset rawRulesets
                                         print $ take 3 rulesets
        buildRulesets = map buildRuleset
        buildRuleset (selector, rawRules) = Ruleset selector (buildRules rawRules)
        buildRules = map (uncurry Rule)
        
        printError = putStrLn "Need a file to parse"
        printParseError error = putStrLn $ "Error parsing css: " ++ error

data Rule = Rule {property :: Text, value :: Text}
            deriving (Show)
                     
data Ruleset = Ruleset {selector :: Text, rules :: [Rule]}
             deriving (Show)
{'fraction_non_alphanumeric': 0.07296137339055794, 'fraction_numerical': 0.001072961373390558, 'mean_word_length': 1.984, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5642401', 'n_tokens_mistral': 480, 'n_tokens_neox': 467, 'n_words': 165}