module Language.Bond.Codegen.Util
( commonHeader
, newlineSep
, commaLineSep
, newlineSepEnd
, newlineBeginSep
, doubleLineSep
, doubleLineSepEnd
) where
import Data.Int (Int64)
import Data.Word
import Prelude
import Data.Text.Lazy (Text, justifyRight)
import Text.Shakespeare.Text
import Paths_bond (version)
import Data.Version (showVersion)
import Language.Bond.Util
instance ToText Word16 where
toText = toText . show
instance ToText Double where
toText = toText . show
instance ToText Integer where
toText = toText . show
indent :: Int64 -> Text
indent n = justifyRight (4 * n) ' ' ""
commaLine :: Int64 -> Text
commaLine n = [lt|,
#{indent n}|]
newLine :: Int64 -> Text
newLine n = [lt|
#{indent n}|]
doubleLine :: Int64 -> Text
doubleLine n = [lt|
#{indent n}|]
newlineSep, commaLineSep, newlineSepEnd, newlineBeginSep, doubleLineSep, doubleLineSepEnd
:: Int64 -> (a -> Text) -> [a] -> Text
newlineSep = sepBy . newLine
commaLineSep = sepBy . commaLine
newlineSepEnd = sepEndBy . newLine
newlineBeginSep = sepBeginBy . newLine
doubleLineSep = sepBy . doubleLine
doubleLineSepEnd = sepEndBy . doubleLine
commonHeader :: ToText a => a -> a -> Text
commonHeader c file = [lt|
#{c}------------------------------------------------------------------------------
#{c} This code was generated by a tool.
#{c}
#{c} Tool : Bond Compiler #{showVersion version}
#{c} File : #{file}
#{c}
#{c} Changes to this file may cause incorrect behavior and will be lost when
#{c} the code is regenerated.
#{c} <auto-generated />
#{c}------------------------------------------------------------------------------
|]