packages feed

fortran-src-extras 0.3.1 → 0.3.2

raw patch · 3 files changed

+81/−37 lines, 3 filesdep ~aesondep ~fortran-srcPVP ok

version bump matches the API change (PVP)

Dependency ranges changed: aeson, fortran-src

API changes (from Hackage documentation)

Files

CHANGELOG.md view
@@ -1,3 +1,8 @@+## 0.3.2 (2022-08-22)+  * Update to fortran-src 0.10.1+  * Serializer: add include inlining support (F77e only)+  * Fix Aeson minimum bound+ ## 0.3.1 (2022-07-18)   * Update to fortran-src 0.10.0   * Add helpers for using Fortran 77 include parser with IO actions
app/Language/Fortran/Extras/CLI/Serialize.hs view
@@ -9,6 +9,7 @@ import qualified Language.Fortran.Parser as F.Parser import qualified Language.Fortran.Parser.Monad as F.Parser -- TODO moved to Parser in next version import Language.Fortran.Version+import qualified Language.Fortran.Util.ModFile as F.ModFile import qualified Raehik.CLI.Stream as CLI import qualified Data.Char as Char import qualified System.Exit as System@@ -18,29 +19,25 @@ import qualified Data.ByteString.Lazy as BL  data Cfg = Cfg-  { cfgDirection :: Direction-  , cfgFormat    :: Format-  , cfgVersion   :: FortranVersion+  { cfgDirection       :: Direction+  , cfgFormat          :: Format+  , cfgVersion         :: FortranVersion+  , cfgIncludeHandling :: IncludeHandling+  , cfgIncludeDirs     :: [FilePath]   } deriving (Eq, Show) --- | Serialization format.-data Format = FmtJson | FmtYaml-    deriving (Eq, Show)---- | Coding direction.------ _Encode_ means to consume Fortran source and produce serialized Fortran.--- _Decode_ means to consume serialized Fortran and produce Fortran source.-data Direction-  = DirEncode (CLI.Stream 'CLI.In  "Fortran source")-              (CLI.Stream 'CLI.Out "serialized Fortran")-  | DirDecode (CLI.Stream 'CLI.In  "serialized Fortran")-              (CLI.Stream 'CLI.Out "Fortran source")-    deriving (Eq, Show)- pCfg :: OA.Parser Cfg-pCfg = Cfg <$> pDirection <*> pFormat <*> pFVersion+pCfg = Cfg <$> pDirection+           <*> pFormat+           <*> pFVersion+           <*> pIncludeHandling+           <*> OA.many pIncludeDir +pIncludeDir :: OA.Parser FilePath+pIncludeDir = OA.strOption $  OA.long "include-dir"+                           <> OA.short 'i'+                           <> OA.help "Directory to search for include files in"+ pFVersion :: OA.Parser FortranVersion pFVersion =     OA.option (OA.maybeReader selectFortranVersion) $@@ -49,6 +46,19 @@         <> OA.help "Fortran version"         <> OA.metavar "FORTRAN_VER" +-- | How to handle includes.+data IncludeHandling = DefaultIncludes | InlineIncludes+    deriving (Eq, Show)++pIncludeHandling :: OA.Parser IncludeHandling+pIncludeHandling = OA.flag DefaultIncludes InlineIncludes $+       OA.long "inline-includes"+    <> OA.help "Process (expand) include statement inline"++-- | Serialization format.+data Format = FmtJson | FmtYaml+    deriving (Eq, Show)+ pFormat :: OA.Parser Format pFormat = OA.option (OA.maybeReader go) $ OA.long "format" <> OA.short 't' <> OA.help "Serialization format (allowed: json, yaml)" <> OA.metavar "FORMAT"   where@@ -58,6 +68,17 @@           "yaml" -> Just FmtYaml           _      -> Nothing +-- | Coding direction.+--+-- _Encode_ means to consume Fortran source and produce serialized Fortran.+-- _Decode_ means to consume serialized Fortran and produce Fortran source.+data Direction+  = DirEncode (CLI.Stream 'CLI.In  "Fortran source")+              (CLI.Stream 'CLI.Out "serialized Fortran")+  | DirDecode (CLI.Stream 'CLI.In  "serialized Fortran")+              (CLI.Stream 'CLI.Out "Fortran source")+    deriving (Eq, Show)+ pDirection :: OA.Parser Direction pDirection = OA.hsubparser $        cmd "encode" "Serialize Fortran source to the requested format" pDirectionEncode@@ -67,25 +88,43 @@ pDirectionEncode = DirEncode <$> CLI.pStreamIn <*> CLI.pStreamOut pDirectionDecode = DirDecode <$> CLI.pStreamIn <*> CLI.pStreamOut +runEncodeAndPrint :: (MonadIO m, Aeson.ToJSON a) => Format -> CLI.Stream 'CLI.Out _s -> a -> m ()+runEncodeAndPrint fmt sOut a = CLI.writeStream sOut textBsOut+  where textBsOut = case fmt of FmtJson -> BL.toStrict $ Aeson.encode a+                                FmtYaml -> Yaml.encode a+ run :: MonadIO m => Cfg -> m (Either F.Parser.ParseErrorSimple ()) run cfg = do     case cfgDirection cfg of       DirEncode sIn sOut -> do         bsIn <- CLI.readStream sIn-        case (F.Parser.byVer (cfgVersion cfg)) (CLI.inStreamFileName sIn) bsIn of-          Left  e   -> return $ Left e-          Right src -> do-            let textBsOut = case cfgFormat cfg of-                       FmtJson -> BL.toStrict $ Aeson.encode src-                       FmtYaml -> Yaml.encode src-            CLI.writeStream sOut textBsOut-            return $ Right ()-      DirDecode _sIn _sOut-> do-        liftIO $ putStrLn "converting from serialized Fortran to Fortran source not yet implemented"-        exit 1+        case cfgIncludeHandling cfg of+          DefaultIncludes ->+            let parser = F.Parser.byVer (cfgVersion cfg)+             in case parser (CLI.inStreamFileName sIn) bsIn of+                  Left  e   -> return $ Left e+                  Right src -> do+                    runEncodeAndPrint (cfgFormat cfg) sOut src+                    return $ Right ()+          InlineIncludes ->+            case cfgVersion cfg of+              Fortran77Extended -> do+                let parserM = F.Parser.f77lIncludes ("." : cfgIncludeDirs cfg) F.ModFile.emptyModFiles+                src <- liftIO $ parserM (CLI.inStreamFileName sIn) bsIn+                runEncodeAndPrint (cfgFormat cfg) sOut src+                return $ Right ()+              v -> err 2 $  "--inline-includes only works with"+                         <> " version Fortran77Extended"+                         <> " (got: "<>show v<>")"+      DirDecode _sIn _sOut -> do+        err 1 "converting from serialized Fortran to Fortran source not yet implemented"  -------------------------------------------------------------------------------- -- IO helpers++err :: MonadIO m => Int -> String -> m a+err ec msg = liftIO $ do putStrLn msg+                         System.exitWith $ System.ExitFailure ec  exit :: MonadIO m => Int -> m a exit n = liftIO $ System.exitWith $ System.ExitFailure n
fortran-src-extras.cabal view
@@ -5,7 +5,7 @@ -- see: https://github.com/sol/hpack  name:           fortran-src-extras-version:        0.3.1+version:        0.3.2 synopsis:       Common functions and utils for fortran-src. description:    Various utility functions and orphan instances which may be useful when using fortran-src. category:       Language@@ -62,7 +62,7 @@   ghc-options: -Wall   build-depends:       GenericPretty >=1.2.1-    , aeson >=1.2.3.0+    , aeson >=1.5.0.0     , base >=4.7 && <5     , binary >=0.8.5.1     , bytestring >=0.10.8.1@@ -70,7 +70,7 @@     , directory >=1.3.0.2     , either >=5.0.0 && <5.1     , filepath >=1.4.1.2-    , fortran-src >=0.10.0+    , fortran-src >=0.10.1     , optparse-applicative >=0.14     , text >=1.2.2.2     , uniplate >=1.6.10@@ -106,11 +106,11 @@   ghc-options: -Wall   build-depends:       GenericPretty >=1.2.1-    , aeson >=1.2.3.0+    , aeson >=1.5.0.0     , base >=4.7 && <5     , bytestring >=0.10.8.1     , containers >=0.5.0.0-    , fortran-src >=0.10.0+    , fortran-src >=0.10.1     , fortran-src-extras     , optparse-applicative >=0.14     , text >=1.2.2.2@@ -151,11 +151,11 @@       hspec-discover:hspec-discover   build-depends:       GenericPretty >=1.2.1-    , aeson >=1.2.3.0+    , aeson >=1.5.0.0     , base >=4.7 && <5     , bytestring >=0.10.8.1     , containers >=0.5.0.0-    , fortran-src >=0.10.0+    , fortran-src >=0.10.1     , fortran-src-extras     , hspec >=2.2 && <3     , optparse-applicative >=0.14