hpp 0.5.1 → 0.5.2
raw patch · 8 files changed
+49/−27 lines, 8 filesPVP: major bump suggested
API removals or changes: PVP suggests a major version bump
API changes (from Hackage documentation)
- Hpp.RunHpp: runHpp :: forall m a src. (MonadIO m, HasHppState m) => (FilePath -> m src) -> (src -> m ()) -> HppT src m a -> m (Either (FilePath, Error) (HppResult a))
+ Hpp.RunHpp: runHpp :: forall m a src. (MonadIO m) => Config -> (FilePath -> m src) -> (src -> m ()) -> HppT src m a -> m (Either (FilePath, Error) (HppResult a))
Files
- hpp.cabal +1/−1
- src/Hpp.hs +8/−3
- src/Hpp/CmdLine.hs +8/−7
- src/Hpp/Parser.hs +6/−1
- src/Hpp/RunHpp.hs +10/−10
- src/Hpp/StringSig.hs +1/−0
- src/Hpp/Types.hs +5/−1
- tests/mcpp-validation.sh +10/−4
hpp.cabal view
@@ -1,5 +1,5 @@ name: hpp-version: 0.5.1+version: 0.5.2 synopsis: A Haskell pre-processor description: See the README for usage examples license: BSD3
src/Hpp.hs view
@@ -71,8 +71,10 @@ streamHpp st snk (HppT h) = do (a, st') <- S.runStateT (evalParse- (R.runHpp (liftIO . readLines)- (lift . lift . lift . snk) h)+ (R.runHpp (T.hppConfig st)+ (liftIO . readLines)+ (lift . lift . lift . snk)+ h) []) st either (throwE . snd) (return . (,st') . R.hppFilesRead) a@@ -80,7 +82,10 @@ -- | Like 'runHpp', but does not access the filesystem. Run a -- preprocessor action with some initial state. Returns the result of -- preprocessing as well as an updated preprocessor state--- representation. Since this operation performs no IO, @#include@ directives are ignored in terms of the generated output lines, but the files named in those directive are available in the 'HppOutput' value returned.+-- representation. Since this operation performs no IO, @#include@+-- directives are ignored in terms of the generated output lines, but+-- the files named in those directive are available in the 'HppOutput'+-- value returned. expand :: T.HppState -> HppT (S.State ([ByteString] -> [ByteString])) a -> Except T.Error (HppOutput, T.HppState)
src/Hpp/CmdLine.hs view
@@ -2,7 +2,7 @@ -- | A front-end to run Hpp with textual arguments as from a command -- line invocation. module Hpp.CmdLine (runWithArgs) where-import Control.Monad (unless)+import Control.Monad (unless, (>=>)) import Control.Monad.Trans.Except (runExceptT) import Data.String (fromString) import Hpp@@ -101,18 +101,19 @@ let fileName = curFileName cfg cfg' = cfg { curFileNameF = pure fileName } (snk, closeSnk) <- case outPath of- Nothing -> return (mapM_ (putStringy stdout) , return ())+ Nothing -> return ( mapM_ (putStringy stdout)+ , return () ) Just f -> do h <- makeAbsolute f >>= flip openFile WriteMode return ( \os -> mapM_ (putStringy h) os , hClose h )- let errorExcept = fmap (either (error . show) id) . runExceptT+ let errorExcept = runExceptT >=> either (error . show) pure _ <- readLines fileName- >>= errorExcept- . streamHpp (initHppState cfg' env) snk- . preprocess- . (map fromString lns ++)+ >>= errorExcept+ . streamHpp (initHppState cfg' env) snk+ . preprocess+ . (map fromString lns ++) -- (lns', _) <- readLines fileName -- >>= errorExcept -- . runHpp (initHppState cfg' env)
src/Hpp/Parser.hs view
@@ -14,11 +14,16 @@ -- * Parsers +-- | Our input is a list of values each of which is either an action or a value. type RopeM m a = [Either (m ()) a] --- | A 'Parser' is a bit of state carrying a source of input.+-- | A 'ParserT' is a bit of state that carries a source of input. type ParserT m src i = StateT (Headspring m src i, src) m +-- | A 'Parser' is a bit of state that carries a source of input+-- consisting of a list of values which are either actions in an+-- underlying monad or sequences of inputs. Thus we have chunks of+-- input values with interspersed effects. type Parser m i = ParserT m (RopeM m [i]) i data Headspring m src i =
src/Hpp/RunHpp.hs view
@@ -247,33 +247,33 @@ -- | Interpret the IO components of the preprocessor. This -- implementation relies on IO for the purpose of checking search -- paths for included files.-runHpp :: forall m a src. (MonadIO m, HasHppState m)- => (FilePath -> m src)+runHpp :: forall m a src. (MonadIO m)+ => Config+ -> (FilePath -> m src) -> (src -> m ()) -> HppT src m a -> m (Either (FilePath,Error) (HppResult a))-runHpp source sink m = runHppT m >>= go []+runHpp cfg source sink m = runHppT m >>= go [] where go :: [FilePath] -> FreeF (HppF src) a (HppT src m a) -> m (Either (FilePath, Error) (HppResult a)) go files (PureF x) = return $ Right (HppResult files x) go files (FreeF s) = case s of ReadFile ln file k ->- (includePaths <$> use config)- >>= liftIO . flip searchForInclude file+ liftIO (searchForInclude (includePaths cfg) file) >>= readAux (file:files) ln file k ReadNext ln file k ->- (includePaths <$> use config)- >>= liftIO . flip searchForNextInclude file+ liftIO (searchForNextInclude (includePaths cfg) file) >>= readAux (file:files) ln file k WriteOutput output k -> sink output >> runHppT k >>= go files readAux _files ln file _ Nothing =- Left . (, IncludeDoesNotExist ln file) . curFileName <$> use config+ pure (Left (curFileName cfg, IncludeDoesNotExist ln file)) readAux files _ln _file k (Just file') = source file' >>= runHppT . k >>= go files {-# SPECIALIZE runHpp ::- (FilePath -> Parser (StateT HppState (ExceptT Error IO)) [TOKEN] [String])+ Config+ -> (FilePath -> Parser (StateT HppState (ExceptT Error IO)) [TOKEN] [String]) -> ([String] -> Parser (StateT HppState (ExceptT Error IO)) [TOKEN] ()) -> HppT [String] (Parser (StateT HppState (ExceptT Error IO)) [TOKEN]) a -> Parser (StateT HppState (ExceptT Error IO)) [TOKEN] (Either (FilePath,Error) (HppResult a)) #-}@@ -673,7 +673,7 @@ hppIOSink' cfg env' snk src = fmap (fmap hppFilesRead) . dischargeHppCaps cfg env' $- runHpp (liftIO . readLines) (liftIO . snk) (preprocess src)+ runHpp cfg (liftIO . readLines) (liftIO . snk) (preprocess src) -- | General hpp runner against input source file lines. Output lines -- are fed to the caller-supplied sink function. Any errors
src/Hpp/StringSig.hs view
@@ -12,6 +12,7 @@ data CharOrSub s = CharMatch !s !s | SubMatch !s !s | NoMatch +-- | A collection of operations relating to sequences of characters. class (IsString s, Monoid s) => Stringy s where -- | Stringification puts double quotes around a string and -- backslashes before existing double quote characters and backslash
src/Hpp/Types.hs view
@@ -85,8 +85,12 @@ -- | Dynamic state of the preprocessor engine. data HppState = HppState { hppConfig :: Config+ -- ^ Initial configuration , hppLineNum :: LineNum- , hppEnv :: Env }+ -- ^ Current line number of input file+ , hppEnv :: Env+ -- ^ Preprocessor binding environment+ } -- | A free monad construction to strictly delimit what capabilities -- we need to perform pre-processing.
tests/mcpp-validation.sh view
@@ -8,7 +8,7 @@ # with BSD or OS X head. # Get the include paths GCC will use by default.-GCCDIR=($(echo | ${GCC} -E -v - 2>&1 | sed -n '/#include <...> search starts/,/End of search list/ p' | tail -n +2 | sed '$ d' | grep -v '(framework directory)' | sed 's/^[[:space:]]*//'))+GCCDIR=($(${GCC} -xc -E -v /dev/null 2>&1 | sed -n '/#include <...> search starts/,/End of search list/p' | tail -n +2 | sed '$ d' | grep -v '(framework directory)' | sed 's/^[[:space:]]*//' | tac)) if (! [ $? -eq 0 ]) || [ -z "${GCCDIR}" ]; then GCCDIR=""@@ -35,7 +35,7 @@ if [ -z "$TRAVIS" ]; then (cd .. && stack build hpp:hpp) else- (cd .. && cabal build)+ (cd .. && cabal new-build) fi if ! [ $? -eq 0 ]; then echo 'Building hpp failed'@@ -52,10 +52,16 @@ # Note that we define __i386__ as the architecture as the MCPP # validation test n_12.c assumes a long is 32 bits. + if [ -z "$TRAVIS" ]; then- (cd mcpp-2.7.2/test-c && ../tool/cpp_test HPP "$(cd ../../.. && stack exec which -- hpp) -I/usr/include ${GCCDIR} --cpp -D__i386__ -D__DARWIN_ONLY_UNIX_CONFORMANCE %s.c | gcc -o %s -w -x c -" "rm %s" < n_i_.lst)+ case $(uname -s) in+ Darwin)+ (cd mcpp-2.7.2/test-c && ../tool/cpp_test HPP "$(cd ../../.. && stack exec which -- hpp) -I/usr/include ${GCCDIR} --cpp -D__i386__ -D__DARWIN_ONLY_UNIX_CONFORMANCE %s.c | gcc -o %s -w -x c -" "rm %s" < n_i_.lst)+ ;;+ *) (cd mcpp-2.7.2/test-c && ../tool/cpp_test HPP "$(find $(pwd)/../../../.stack-work -type f -executable -name hpp -print -quit) ${GCCDIR} --cpp -D__x86_64__ %s.c | gcc -o %s -w -x c -" "rm %s" < n_i_.lst)+ esac else- (cd mcpp-2.7.2/test-c && ../tool/cpp_test HPP "$(find ../../../dist -type f -executable -name hpp) -I/usr/include ${GCCDIR} --cpp -D__i386__ -D__DARWIN_ONLY_UNIX_CONFORMANCE %s.c | gcc -o %s -w -x c -" "rm %s" < n_i_.lst)+ (cd mcpp-2.7.2/test-c && ../tool/cpp_test HPP "$(find $(pwd)/../../../../dist-newstyle -type f -executable -name hpp) ${GCCDIR} --cpp -D__x86_64__ %s.c | gcc -o %s -w -x c -" "rm %s" < n_i_.lst) fi if ! [ $? -eq 0 ]; then