{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE OverloadedLists #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE DeriveFunctor #-}

-- | All the types corresponding to the grammar in
-- "Penny.Copper.Grammar".  Most of this is automatically generated by
-- Pinchot.
module Penny.Copper.Types where

import qualified Control.Lens as Lens
import Data.Monoid ((<>))
import Penny.Copper.Grammar

import Pinchot (syntaxTrees, wrappedInstances, monoidInstances)

syntaxTrees [''Show, ''Functor] allRules

monoidInstances allRules

wrappedInstances allRules

instance Monoid (WholeFile t a) where
  mempty = WholeFile mempty mempty
  mappend (WholeFile fiSqX wiSqX)
          (WholeFile (FileItemP'Star fiSqY) wiSqY)
    = WholeFile (fiSqX <> fiSq') (wiSq' <> wiSqY)
    where
      (fiSq', wiSq') = case Lens.uncons fiSqY of
        Nothing -> (mempty, wiSqX)
        Just (FileItemP whites fi, rest) ->
          ( FileItemP'Star (Lens.cons (FileItemP (wiSqX <> whites) fi) rest)
          , mempty )

