module Fay.Compiler.Desugar.Name
( withScopedTmpName
, unscopedTmpNames
) where
import Fay.Compiler.Prelude
import Fay.Compiler.Desugar.Types
import Control.Monad.Reader (asks, local)
import Language.Haskell.Exts (Name (..))
withScopedTmpName :: (Data l, Typeable l) => l -> (Name l -> Desugar l a) -> Desugar l a
withScopedTmpName l f = do
prefix <- asks readerTmpNamePrefix
n <- asks readerNameDepth
local (\r -> r { readerNameDepth = n + 1 }) $
f $ tmpName l prefix n
unscopedTmpNames :: l -> String -> [Name l]
unscopedTmpNames l prefix = map (tmpName l prefix) [0..]
tmpName :: l -> String -> Int -> Name l
tmpName l prefix n = Ident l $ prefix ++ show n