module BNFC.Backend.Agda.Template where import BNFC.CF import BNFC.Options.GlobalOptions import BNFC.Prelude import BNFC.Backend.Agda.Options import BNFC.Backend.Agda.State import BNFC.Backend.CommonInterface.Backend import BNFC.Backend.Haskell.Template (cf2template) import BNFC.Backend.Haskell.Utilities.Utils import Control.Monad.State import qualified Data.Map as Map import System.FilePath ( takeBaseName ) agdaTemplate :: LBNF -> State AgdaBackendState Result agdaTemplate lbnf = do st <- get let cfName = takeBaseName $ optInput $ globalOpt st rules = filterRules $ hsAstRules st tokensNames = fst <$> tokens st inDirectory = inDir $ agdaOpts st nSpace = nameSpace $ agdaOpts st funct = functor $ agdaOpts st template = cf2template rules tokensNames cfName inDirectory nSpace funct return [(mkFilePath inDirectory nSpace cfName "Skel" "hs", template)] where filterRules :: [(Type, [(Label, ([Type], (Integer, ARHS)))])] -> [(Type, [(Label, ([Type], (Integer, ARHS)))])] filterRules rules = filter (\(_,l) -> not (null l)) ((\(f,s) -> (f, filterLabelsAST fNames s)) <$> rules) -- Functions names. fNames :: [String] fNames = toList <$> Map.keys (_lbnfFunctions lbnf)