packages feed

hindent 4.2.0 → 4.2.1

raw patch · 4 files changed

+68/−18 lines, 4 filesdep ~haskell-src-extsPVP: major bump suggested

API removals or changes: PVP suggests a major version bump

Dependency ranges changed: haskell-src-exts

API changes (from Hackage documentation)

- HIndent: reformat :: Style -> Text -> Either String Builder
+ HIndent: reformat :: Style -> Maybe [Extension] -> Text -> Either String Builder

Files

hindent.cabal view
@@ -1,5 +1,5 @@ name:                hindent-version:             4.2.0+version:             4.2.1 synopsis:            Extensible Haskell pretty printer description:         Extensible Haskell pretty printer. Both a library and an executable.                      .@@ -41,6 +41,7 @@                    , hindent                    , text                    , descriptive >= 0.0.2 && < 0.1+                   , haskell-src-exts  executable hindent-generate-tests   hs-source-dirs:    src/main
src/HIndent.hs view
@@ -43,9 +43,11 @@ import           Data.Maybe (fromMaybe)  -- | Format the given source.-reformat :: Style -> Text -> Either String Builder-reformat style x =-  case parseModuleWithComments parseMode+reformat :: Style -> Maybe [Extension] -> Text -> Either String Builder+reformat style mexts x =+  case parseModuleWithComments (case mexts of+                                  Just exts -> parseMode {extensions = exts}+                                  Nothing -> parseMode)                                (T.unpack x) of     ParseOk (m,comments) ->       let (cs,ast) =@@ -81,7 +83,7 @@ test :: Style -> Text -> IO () test style =   either error (T.putStrLn . T.toLazyText) .-  reformat style+  reformat style Nothing  -- | Test with all styles, prints to stdout. testAll :: Text -> IO ()
src/main/Main.hs view
@@ -1,3 +1,4 @@+{-# LANGUAGE PatternGuards #-} {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE ViewPatterns #-} @@ -10,6 +11,7 @@ import           HIndent  import           Control.Applicative+import           Data.List import           Data.Text (Text) import qualified Data.Text as T import qualified Data.Text.Lazy.Builder as T@@ -17,6 +19,7 @@ import           Data.Version (showVersion) import           Descriptive import           Descriptive.Options+import           Language.Haskell.Exts.Annotated hiding (Style) import           Paths_hindent (version) import           System.Environment @@ -29,19 +32,63 @@          error (T.unpack (textDescription (describe options [])))        Right result ->          case result of-           Left{} -> putStrLn ("hindent " ++ showVersion version)-           Right style -> T.interact-                            (either error T.toLazyText .-                             reformat style)+           Left{} ->+             putStrLn ("hindent " ++ showVersion version)+           Right (style,exts) ->+             T.interact+               (either error T.toLazyText .+                reformat style (Just exts))  -- | Program options.-options :: Consumer [Text] Option (Either Text (Style))+options :: Consumer [Text] Option (Either Text (Style,[Extension])) options =   fmap Left (constant "--version") <|>-  (fmap Right-        (constant "--style" *>-         foldr1 (<|>)-                (map (\style ->-                        fmap (const style)-                             (constant (styleName style)))-                     styles)))+  (fmap Right ((,) <$> style <*> exts))+  where style =+          constant "--style" *>+          foldr1 (<|>)+                 (map (\style ->+                         fmap (const style)+                              (constant (styleName style)))+                      styles)+        exts =+          fmap getExtensions (many (prefix "X" "Language extension"))++--------------------------------------------------------------------------------+-- Extensions stuff stolen from hlint++-- | Consume an extensions list from arguments.+getExtensions :: [Text] -> [Extension]+getExtensions = foldl f defaultExtensions . map T.unpack+  where f _ "Haskell98" = []+        f a ('N':'o':x)+          | Just x' <- readExtension x =+            delete x' a+        f a x+          | Just x' <- readExtension x =+            x' :+            delete x' a+        f _ x = error $ "Unknown extension: " ++ x++-- | Parse an extension.+readExtension :: String -> Maybe Extension+readExtension x =+  case classifyExtension x of+    UnknownExtension _ -> Nothing+    x' -> Just x'++-- | Default extensions.+defaultExtensions :: [Extension]+defaultExtensions =+  [e | e@EnableExtension{} <- knownExtensions] \\+  map EnableExtension badExtensions++-- | Extensions which steal too much syntax.+badExtensions :: [KnownExtension]+badExtensions =+    [Arrows -- steals proc+    ,TransformListComp -- steals the group keyword+    ,XmlSyntax, RegularPatterns -- steals a-b+    ,UnboxedTuples -- breaks (#) lens operator+    ,QuasiQuotes -- breaks [x| ...], making whitespace free list comps break+    ]
src/main/TestGenerate.hs view
@@ -58,7 +58,7 @@ expectationFileContents :: HIndent.Style -> String -> String expectationFileContents style contents =   let testDecls = parsePieces contents-      fmt input = L.unpack $ L.toLazyText $ case HIndent.reformat style $ L.pack input of+      fmt input = L.unpack $ L.toLazyText $ case HIndent.reformat style Nothing $ L.pack input of                                               Left err      -> error err                                               Right builder -> builder       outputs = map (replaceEmptyNewlines . fmt) testDecls