{-|
Module      : Htcc.CRules.Preprocessor.Punctuators
Description : The puncuators of preprocessor
Copyright   : (c) roki, 2019
License     : MIT
Maintainer  : falgon53@yahoo.co.jp
Stability   : experimental
Portability : POSIX

The puncuators of preprocessor
-}
{-# LANGUAGE DeriveGeneric #-}
module Htcc.CRules.Preprocessor.Punctuators (
    -- * The define of C preprocessor
    bgMacro,
    Macros (..),
    -- * Utilities
    macros,
    length
) where

import           Control.DeepSeq (NFData (..))
import           GHC.Generics    (Generic)
import           Prelude         hiding (length)
import qualified Prelude         as P (length)

{-# INLINE bgMacro #-}
-- | `bgMacro` is the character that starts the macro, so it is @#@
bgMacro :: Char
bgMacro :: Char
bgMacro = '#'

-- | `Macros` is a macro token defined in C.
data Macros = MacInclude -- ^ the @include@
    deriving (Macros -> Macros -> Bool
(Macros -> Macros -> Bool)
-> (Macros -> Macros -> Bool) -> Eq Macros
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Macros -> Macros -> Bool
$c/= :: Macros -> Macros -> Bool
== :: Macros -> Macros -> Bool
$c== :: Macros -> Macros -> Bool
Eq, Int -> Macros
Macros -> Int
Macros -> [Macros]
Macros -> Macros
Macros -> Macros -> [Macros]
Macros -> Macros -> Macros -> [Macros]
(Macros -> Macros)
-> (Macros -> Macros)
-> (Int -> Macros)
-> (Macros -> Int)
-> (Macros -> [Macros])
-> (Macros -> Macros -> [Macros])
-> (Macros -> Macros -> [Macros])
-> (Macros -> Macros -> Macros -> [Macros])
-> Enum Macros
forall a.
(a -> a)
-> (a -> a)
-> (Int -> a)
-> (a -> Int)
-> (a -> [a])
-> (a -> a -> [a])
-> (a -> a -> [a])
-> (a -> a -> a -> [a])
-> Enum a
enumFromThenTo :: Macros -> Macros -> Macros -> [Macros]
$cenumFromThenTo :: Macros -> Macros -> Macros -> [Macros]
enumFromTo :: Macros -> Macros -> [Macros]
$cenumFromTo :: Macros -> Macros -> [Macros]
enumFromThen :: Macros -> Macros -> [Macros]
$cenumFromThen :: Macros -> Macros -> [Macros]
enumFrom :: Macros -> [Macros]
$cenumFrom :: Macros -> [Macros]
fromEnum :: Macros -> Int
$cfromEnum :: Macros -> Int
toEnum :: Int -> Macros
$ctoEnum :: Int -> Macros
pred :: Macros -> Macros
$cpred :: Macros -> Macros
succ :: Macros -> Macros
$csucc :: Macros -> Macros
Enum, (forall x. Macros -> Rep Macros x)
-> (forall x. Rep Macros x -> Macros) -> Generic Macros
forall x. Rep Macros x -> Macros
forall x. Macros -> Rep Macros x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Macros x -> Macros
$cfrom :: forall x. Macros -> Rep Macros x
Generic)

instance NFData Macros

instance Show Macros where
    show :: Macros -> String
show MacInclude = "include"

{-# INLINE macros #-}
-- | all macros
macros :: [Macros]
macros :: [Macros]
macros = Macros -> [Macros]
forall a. Enum a => a -> [a]
enumFrom (Macros -> [Macros]) -> Macros -> [Macros]
forall a b. (a -> b) -> a -> b
$ Int -> Macros
forall a. Enum a => Int -> a
toEnum 0

{-# INLINE length #-}
-- | the length of the macro
length :: Macros -> Int
length :: Macros -> Int
length = String -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
P.length (String -> Int) -> (Macros -> String) -> Macros -> Int
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Macros -> String
forall a. Show a => a -> String
show