module BNFC.Backend.Agda.Printer 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.Utilities.Utils import BNFC.Backend.Haskell.Options (TokenText (..)) import BNFC.Backend.Haskell.Printer (cf2printer) import Control.Monad.State import Data.Bifunctor import qualified Data.Map as Map import System.FilePath ( takeBaseName ) agdaPrinter :: LBNF -> State AgdaBackendState Result agdaPrinter lbnf = do st <- get let cfName = takeBaseName $ optInput $ globalOpt st inDirectory = inDir $ agdaOpts st nSpace = nameSpace $ agdaOpts st rules = filterRules $ hsAstRules st tks = tokens st funct = functor $ agdaOpts st prettyPrinter = cf2printer lbnf cfName inDirectory nSpace False rules tks funct TextToken return [(mkFilePath inDirectory nSpace cfName "Print" "hs", prettyPrinter)] where filterRules :: [(Type, [(Label, ([Type], (Integer, ARHS)))])] -> [(Type, [(Label, ([Type], (Integer, ARHS)))])] filterRules rules = filter (\(_,l) -> not (null l)) (Data.Bifunctor.second (filterLabelsPrinter fNames) <$> rules) -- Functions names. fNames :: [String] fNames = toList <$> Map.keys (_lbnfFunctions lbnf)