我正在尝试使用exactPrint
函数来生成一些代码,但是它没有给我任何输出。
首先尝试使用伪造的SrcSpan
,然后尝试使用实际编号的SrcSpan
位置信息。
还尝试使用伪造的注释,重用的注释(通过解析另一个.hs
文件和手写的注释。它们似乎都不起作用。
输出是一个空字符串。
这是我的代码:
import Language.Haskell.GHC.ExactPrint
import qualified Data.ByteString as BS
-- import Data.Text as T
import Data.List as DL
import GHC hiding (parseModule)
import qualified HsSyn as GHC
import qualified RdrName as GHC
import qualified SrcLoc as GHC
import SrcLoc
import Safe
import BasicTypes
import qualified Data.Map as Map
import FastString
rlSrcSpan :: SrcSpan
rlSrcSpan = mkSrcSpan (mkSrcLoc (fsLit "testFiles/SampleCode.hs") 1 1) (mkSrcLoc (fsLit "testFiles/SampleCode.hs") 10 20)
srcSpan :: (Int, Int, Int, Int) -> SrcSpan
srcSpan (sLine, sCol, eLine, eCol) = mkSrcSpan (mkSrcLoc (fsLit "testFiles/SampleCode.hs") sLine sCol) (mkSrcLoc (fsLit "testFiles/SampleCode.hs") eLine eCol)
newAnn :: Anns
newAnn =
let annKey = AnnKey noSrcSpan (CN "AnnName")
kwId = AnnSemiSep
currentAnnsDP = [(kwId, DP (10, 2) )]
in Map.singleton annKey (Ann (DP (1, 1) ) [] [] currentAnnsDP Nothing Nothing )
outputModule :: IO ()
outputModule = putStrLn $ "Haskell Module: " ++ (exactPrint (L rlSrcSpan haskellModule) newAnn )
haskellModule :: GHC.HsModule GHC.GhcPs
haskellModule = do
let modName = Just $ L (srcSpan (2, 1, 2, 30) ) $ mkModuleName "TestQueryDBR"
let exportList = Nothing
let importList = [L (srcSpan (3, 1, 4, 30) ) $ ImportDecl (SourceText "mod") (L (srcSpan (3, 1, 4, 30) ) $ mkModuleName "Data.Text") Nothing False False False False (Just $ L (srcSpan (3, 10, 3, 30) ) $ mkModuleName "T") Nothing ]
let declarations = []
GHC.HsModule modName exportList importList declarations Nothing Nothing