Skip to content

Commit 0d57c13

Browse files
Initial
0 parents  commit 0d57c13

File tree

1 file changed

+28
-0
lines changed
  • Language/Haskell/Exts/Annotated

1 file changed

+28
-0
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
module Language.Haskell.Exts.Annotated.CPP
2+
( parseFileWithComments
3+
, parseFileContentsWithComments
4+
) where
5+
6+
import Language.Preprocessor.Cpphs
7+
import Language.Preprocessor.Unlit
8+
import Language.Haskell.Exts (ParseMode(..))
9+
import Language.Haskell.Exts.Annotated
10+
hiding (parseFileWithComments, parseFileContentsWithComments)
11+
import Control.Applicative
12+
import Data.List
13+
14+
parseFileWithComments :: CpphsOptions -> ParseMode -> FilePath -> IO (ParseResult (Module SrcSpanInfo, [Comment]))
15+
parseFileWithComments cppopts p fp = readFile fp >>= parseFileContentsWithComments cppopts p
16+
17+
parseFileContentsWithComments :: CpphsOptions -> ParseMode -> String -> IO (ParseResult (Module SrcSpanInfo, [Comment]))
18+
parseFileContentsWithComments cppopts p@(ParseMode fn exts ign _ _) rawStr =
19+
let md = delit fn rawStr
20+
allExts = impliesExts $ case (ign, readExtensions md) of
21+
(False,Just es) -> exts ++ es
22+
_ -> exts
23+
in parseModuleWithComments (p { extensions = allExts }) <$> runCpphs cppopts fn md
24+
25+
cpp cppopts str = runCpphs cppopts str
26+
27+
delit :: String -> String -> String
28+
delit fn = if ".lhs" `isSuffixOf` fn then unlit fn else id

0 commit comments

Comments
 (0)