<commit_before>{-# LANGUAGE OverloadedStrings #-}
module Render where

import Data.Monoid
import Data.Foldable
import Data.Text.Lazy.Builder

import qualified Data.Text.Lazy.IO as Text

import Rules    (Property (Property), Rule (Rule))
import Selector (Selector (..))


renderAndPrint :: [Rule] -> IO ()
renderAndPrint = Text.putStr . toLazyText . render

render :: [Rule] -> Builder
render = foldMap rule

rule :: Rule -> Builder
rule (Rule sel props) = mconcat
  [ selector sel
  , "\n{\n"
  , foldMap property props
  , "}\n"
  ]

selector :: Selector -> Builder
selector sel =
  case sel of
    None         -> mempty
    Star         -> singleton '*'
    Elem     t   -> fromText t
    Id       t   -> singleton '#' <> fromText t
    Class    t   -> singleton '.' <> fromText t
    Child    a b -> selector a <> " > " <> selector b
    Deep     a b -> selector a <> "   " <> selector b
    Adjacent a b -> selector a <> " + " <> selector b
    Combined a b -> selector a <> " , " <> selector b

property :: Property -> Builder
property (Property key val) =
  fromText key <> ": " <> fromText val <> ";\n"<commit_msg>Render two spaces before properties.<commit_after>{-# LANGUAGE OverloadedStrings #-}
module Render where

import Data.Monoid
import Data.Foldable
import Data.Text.Lazy.Builder

import qualified Data.Text.Lazy.IO as Text

import Rules    (Property (Property), Rule (Rule))
import Selector (Selector (..))


renderAndPrint :: [Rule] -> IO ()
renderAndPrint = Text.putStr . toLazyText . render

render :: [Rule] -> Builder
render = foldMap rule

rule :: Rule -> Builder
rule (Rule sel props) = mconcat
  [ selector sel
  , "\n{\n"
  , foldMap property props
  , "}\n"
  ]

selector :: Selector -> Builder
selector sel =
  case sel of
    None         -> mempty
    Star         -> singleton '*'
    Elem     t   -> fromText t
    Id       t   -> singleton '#' <> fromText t
    Class    t   -> singleton '.' <> fromText t
    Child    a b -> selector a <> " > " <> selector b
    Deep     a b -> selector a <> "   " <> selector b
    Adjacent a b -> selector a <> " + " <> selector b
    Combined a b -> selector a <> " , " <> selector b

property :: Property -> Builder
property (Property key val) =
  mconcat ["  ", fromText key, ": ", fromText val, ";\n"]
{'fraction_non_alphanumeric': 0.13570487483530963, 'fraction_numerical': 0.0, 'mean_word_length': 2.499231950844854, 'pattern_counts': {'":': 2, '<': 26, '<?xml version=': 0, '>': 56, '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': '3163857', 'n_tokens_mistral': 728, 'n_tokens_neox': 696, 'n_words': 244}