hse-cpp (empty) → 0.1
raw patch · 4 files changed
+110/−0 lines, 4 filesdep +basedep +cpphsdep +haskell-src-extssetup-changed
Dependencies added: base, cpphs, haskell-src-exts
Files
- LICENSE +19/−0
- Language/Haskell/Exts/Annotated/CPP.hs +66/−0
- Setup.hs +2/−0
- hse-cpp.cabal +23/−0
+ LICENSE view
@@ -0,0 +1,19 @@+Copyright (c) 2013 Roman Cheplyaka++Permission is hereby granted, free of charge, to any person obtaining a copy+of this software and associated documentation files (the "Software"), to deal+in the Software without restriction, including without limitation the rights+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell+copies of the Software, and to permit persons to whom the Software is+furnished to do so, subject to the following conditions:++The above copyright notice and this permission notice shall be included in+all copies or substantial portions of the Software.++THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN+THE SOFTWARE.
+ Language/Haskell/Exts/Annotated/CPP.hs view
@@ -0,0 +1,66 @@+module Language.Haskell.Exts.Annotated.CPP+ ( parseFileWithCommentsAndCPP+ , parseFileContentsWithCommentsAndCPP+ , defaultCpphsOptions+ , CpphsOptions(..)+ , BoolOptions(..)+ ) where++import qualified Language.Preprocessor.Cpphs as Orig+import Language.Preprocessor.Cpphs hiding (defaultCpphsOptions)+import Language.Preprocessor.Unlit+import Language.Haskell.Exts (ParseMode(..))+import Language.Haskell.Exts.Annotated+import Control.Applicative+import Data.List++parseFileWithCommentsAndCPP :: CpphsOptions -> ParseMode -> FilePath+ -> IO (ParseResult (Module SrcSpanInfo, [Comment]))+parseFileWithCommentsAndCPP cppopts parseMode0 file = do+ content <- readFile file+ parseFileContentsWithCommentsAndCPP cppopts parseMode content+ where+ parseMode = parseMode0 { parseFilename = file }++parseFileContentsWithCommentsAndCPP+ :: CpphsOptions -> ParseMode -> String+ -> IO (ParseResult (Module SrcSpanInfo, [Comment]))+parseFileContentsWithCommentsAndCPP cppopts p rawStr = do+ let filename = parseFilename p+ md = delit filename rawStr+ cppMode = updateExtensions p md+ processedSrc <- cpp cppopts cppMode md+ let finalMode = updateExtensions cppMode processedSrc+ return $ parseModuleWithComments finalMode processedSrc++updateExtensions :: ParseMode -> String -> ParseMode+updateExtensions p mod =+ let oldLang = baseLanguage p+ exts = extensions p+ (bLang, extraExts) =+ case (ignoreLanguagePragmas p, readExtensions mod) of+ (False, Just (mLang, es)) ->+ (case mLang of {Nothing -> oldLang;Just newLang -> newLang}, es)+ _ -> (oldLang, [])+ in p { extensions = exts ++ extraExts+ , ignoreLanguagePragmas = False+ , baseLanguage = bLang+ }++cpp cppopts p str+ | CPP `elem` impliesExts (toExtensionList (baseLanguage p) (extensions p))+ = runCpphs cppopts (parseFilename p) str+ | otherwise = return str++delit :: String -> String -> String+delit fn = if ".lhs" `isSuffixOf` fn then unlit fn else id++defaultCpphsOptions =+ Orig.defaultCpphsOptions+ { boolopts = (boolopts Orig.defaultCpphsOptions)+ { locations = True+ , stripC89 = True+ , stripEol = False+ , hashline = False+ }+ }
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ hse-cpp.cabal view
@@ -0,0 +1,23 @@+-- Initial hse-cpp.cabal generated by cabal init. For further +-- documentation, see http://haskell.org/cabal/users-guide/++name: hse-cpp+version: 0.1+synopsis: Preprocess+parse haskell code+-- description: +license: MIT+license-file: LICENSE+author: Roman Cheplyaka+maintainer: Roman Cheplyaka <roma@ro-che.info>+-- copyright: +category: Language+build-type: Simple+cabal-version: >=1.10++library+ exposed-modules: Language.Haskell.Exts.Annotated.CPP+ -- other-modules: + build-depends: base == 4.*+ , cpphs+ , haskell-src-exts >= 1.14+ default-language: Haskell2010