ats-format 0.2.0.31 → 0.2.0.32
raw patch · 3 files changed
+30/−28 lines, 3 filesdep +toml-parserdep −htoml-megaparsecdep −megaparsecdep −unordered-containers
Dependencies added: toml-parser
Dependencies removed: htoml-megaparsec, megaparsec, unordered-containers
Files
- CHANGELOG.md +5/−0
- ats-format.cabal +3/−5
- src/Main.hs +22/−23
CHANGELOG.md view
@@ -1,5 +1,10 @@ # ats-format +## 0.2.2.32++ * Depend on [toml-parser](http://hackage.haskell.org/package/toml-parser) for+ TOML parsing.+ ## 0.2.2.31 * Remove `static` and `profiling` flags; use `--enable-executable-static` from
ats-format.cabal view
@@ -1,6 +1,6 @@ cabal-version: 1.18 name: ats-format-version: 0.2.0.31+version: 0.2.0.32 license: BSD3 license-file: LICENSE copyright: Copyright: (c) 2017-2019 Vanessa McHale@@ -47,14 +47,12 @@ base >=4.9 && <5, language-ats >=1.7.4.0, optparse-applicative -any,- htoml-megaparsec >=2.1.0.0,- megaparsec >=7.0.0, text -any, ansi-wl-pprint -any, directory -any,- unordered-containers -any, process -any,- file-embed >=0.0.9+ file-embed >=0.0.9,+ toml-parser -any if flag(development) ghc-options: -Werror
src/Main.hs view
@@ -3,14 +3,15 @@ module Main where -import Control.Arrow+import Control.Exception (displayException) import Control.Monad (unless, (<=<))+import Data.Bifunctor (first) import Data.FileEmbed (embedStringFile)-import qualified Data.HashMap.Lazy as HM+import Data.List (lookup) import Data.Maybe (fromMaybe) import Data.Monoid ((<>)) import qualified Data.Text.IO as TIO-import Data.Version+import Data.Version (showVersion) import Language.ATS import Options.Applicative import Paths_ats_format@@ -18,9 +19,8 @@ import System.Exit (exitFailure) import System.IO (hPutStr, stderr) import System.Process (readCreateProcess, shell)-import Text.Megaparsec (errorBundlePretty) import Text.PrettyPrint.ANSI.Leijen (pretty)-import Text.Toml+import TOML data Program = Program { _path :: Maybe FilePath , _inplace :: Bool@@ -82,32 +82,31 @@ defaultConfig :: FilePath -> IO () defaultConfig = flip writeFile $(embedStringFile ".atsfmt.toml") -asFloat :: Node -> Maybe Float-asFloat (VFloat d) = Just (realToFrac d)+asFloat :: Value -> Maybe Float+asFloat (Double d) = Just (realToFrac d) asFloat _ = Nothing -asInt :: Node -> Maybe Int-asInt (VInteger i) = Just (fromIntegral i)-asInt _ = Nothing+asInt :: Value -> Maybe Int+asInt (Integer i) = Just (fromIntegral i)+asInt _ = Nothing -asBool :: Node -> Maybe Bool-asBool (VBoolean True) = Just True-asBool (VBoolean False) = Just False-asBool _ = Nothing+asBool :: Value -> Maybe Bool+asBool (Bool x) = Just x+asBool _ = Nothing defaults :: (Float, Int, Bool) defaults = (0.6, 120, False) -parseToml :: String -> IO (Float, Int, Bool)-parseToml p = do- f <- TIO.readFile p- case parseTomlDoc p f of- Right x -> pure . fromMaybe defaults $ do- r <- asFloat =<< HM.lookup "ribbon" x- w <- asInt =<< HM.lookup "width" x- cf <- asBool =<< HM.lookup "clang-format" x+parseToml :: FilePath -> IO (Float, Int, Bool)+parseToml fp = do+ f <- TIO.readFile fp+ case parseTOML f of+ Right x -> pure $ fromMaybe defaults $ do+ r <- asFloat =<< lookup "ribbon" x+ w <- asInt =<< lookup "width" x+ cf <- asBool =<< lookup "clang-format" x pure (r, w, cf)- Left e -> printFail $ errorBundlePretty e+ Left err -> printFail $ displayException err printCustom :: Eq a => ATS a -> IO String printCustom ats = do