{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TupleSections     #-}

{-|
Module      : Headroom.Ext.PureScript
Description : Extended support for /PureScript/ source code files
Copyright   : (c) 2019-2020 Vaclav Svejcar
License     : BSD-3-Clause
Maintainer  : vaclav.svejcar@gmail.com
Stability   : experimental
Portability : POSIX

This module provides /extended support/ for /PureScript/ source code files.
Current implementation includes extracting of /module name/ from currently
processed /PureScript/ source code file.
-}

module Headroom.Ext.PureScript where

import           Headroom.Configuration.Types   ( CtHeaderConfig )
import           Headroom.Ext.Haskell           ( extractModuleName )
import           Headroom.Types                 ( TemplateMeta(..) )
import           Headroom.Variables             ( mkVariables )
import           Headroom.Variables.Types       ( Variables(..) )
import           RIO


-- | Extracts variables from /PureScript/ source code.
--
-- __List of Extracted Variables:__
--
-- * @___purescript_module_name__@ - name of the /PureScript/ module
extractVariables :: CtHeaderConfig
                 -- ^ license header configuration
                 -> Maybe TemplateMeta
                 -- ^ extracted metadata from corresponding /template/
                 -> Maybe (Int, Int)
                 -- ^ license header position @(startLine, endLine)@
                 -> Text
                 -- ^ input text
                 -> Variables
                 -- ^ extracted variables
extractVariables :: CtHeaderConfig
-> Maybe TemplateMeta -> Maybe (Int, Int) -> Text -> Variables
extractVariables CtHeaderConfig
_ Maybe TemplateMeta
_ Maybe (Int, Int)
_ Text
text = ([(Text, Text)] -> Variables
mkVariables ([(Text, Text)] -> Variables)
-> ([Maybe (Text, Text)] -> [(Text, Text)])
-> [Maybe (Text, Text)]
-> Variables
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Maybe (Text, Text)] -> [(Text, Text)]
forall a. [Maybe a] -> [a]
catMaybes)
  [(Text
"_purescript_module_name", ) (Text -> (Text, Text)) -> Maybe Text -> Maybe (Text, Text)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Text -> Maybe Text
extractModuleName Text
text]