From 5a82968a7b361a939185b9c05d7e5d9558892fb4 Mon Sep 17 00:00:00 2001 From: Lennart Spitzner Date: Tue, 4 Jul 2017 22:32:03 +0200 Subject: [PATCH] Add sub-config-alternative default to lib interface i.e. `forwardOptionsSyntaxExtsEnabled` --- src-literatetests/Main.hs | 1 + src-unittests/TestUtils.hs | 1 + src/Language/Haskell/Brittany.hs | 2 + src/Language/Haskell/Brittany/Internal.hs | 1 + .../Haskell/Brittany/Internal/Config.hs | 64 +++++++++++++++++++ .../Haskell/Brittany/Internal/Config/Types.hs | 44 ------------- 6 files changed, 69 insertions(+), 44 deletions(-) diff --git a/src-literatetests/Main.hs b/src-literatetests/Main.hs index fdac364..fe966e6 100644 --- a/src-literatetests/Main.hs +++ b/src-literatetests/Main.hs @@ -19,6 +19,7 @@ import Data.List ( groupBy ) import Language.Haskell.Brittany.Internal import Language.Haskell.Brittany.Internal.Config.Types +import Language.Haskell.Brittany.Internal.Config import Data.Coerce ( coerce ) diff --git a/src-unittests/TestUtils.hs b/src-unittests/TestUtils.hs index e94267a..30eac3e 100644 --- a/src-unittests/TestUtils.hs +++ b/src-unittests/TestUtils.hs @@ -13,6 +13,7 @@ import NeatInterpolation import Language.Haskell.Brittany.Internal import Language.Haskell.Brittany.Internal.Config.Types +import Language.Haskell.Brittany.Internal.Config import System.Timeout ( timeout ) diff --git a/src/Language/Haskell/Brittany.hs b/src/Language/Haskell/Brittany.hs index 706984b..5f9a128 100644 --- a/src/Language/Haskell/Brittany.hs +++ b/src/Language/Haskell/Brittany.hs @@ -3,6 +3,7 @@ module Language.Haskell.Brittany ( parsePrintModule , staticDefaultConfig + , forwardOptionsSyntaxExtsEnabled , Config , CConfig(..) , CDebugConfig(..) @@ -21,4 +22,5 @@ where import Language.Haskell.Brittany.Internal import Language.Haskell.Brittany.Internal.Types import Language.Haskell.Brittany.Internal.Config.Types +import Language.Haskell.Brittany.Internal.Config diff --git a/src/Language/Haskell/Brittany/Internal.hs b/src/Language/Haskell/Brittany/Internal.hs index 6ed1dd8..51635c0 100644 --- a/src/Language/Haskell/Brittany/Internal.hs +++ b/src/Language/Haskell/Brittany/Internal.hs @@ -28,6 +28,7 @@ import qualified Data.Text.Lazy.Builder as Text.Builder import Language.Haskell.Brittany.Internal.Types import Language.Haskell.Brittany.Internal.Config.Types +import Language.Haskell.Brittany.Internal.Config import Language.Haskell.Brittany.Internal.LayouterBasics import Language.Haskell.Brittany.Internal.Layouters.Type diff --git a/src/Language/Haskell/Brittany/Internal/Config.hs b/src/Language/Haskell/Brittany/Internal/Config.hs index 593e616..ba6b1af 100644 --- a/src/Language/Haskell/Brittany/Internal/Config.hs +++ b/src/Language/Haskell/Brittany/Internal/Config.hs @@ -7,6 +7,7 @@ module Language.Haskell.Brittany.Internal.Config , Config , configParser , staticDefaultConfig + , forwardOptionsSyntaxExtsEnabled , readMergePersConfig , showConfigYaml ) @@ -32,6 +33,68 @@ import Data.Coerce ( Coercible, coerce ) +staticDefaultConfig :: Config +staticDefaultConfig = Config + { _conf_version = coerce (1 :: Int) + , _conf_debug = DebugConfig + { _dconf_dump_config = coerce False + , _dconf_dump_annotations = coerce False + , _dconf_dump_ast_unknown = coerce False + , _dconf_dump_ast_full = coerce False + , _dconf_dump_bridoc_raw = coerce False + , _dconf_dump_bridoc_simpl_alt = coerce False + , _dconf_dump_bridoc_simpl_floating = coerce False + , _dconf_dump_bridoc_simpl_par = coerce False + , _dconf_dump_bridoc_simpl_columns = coerce False + , _dconf_dump_bridoc_simpl_indent = coerce False + , _dconf_dump_bridoc_final = coerce False + , _dconf_roundtrip_exactprint_only = coerce False + } + , _conf_layout = LayoutConfig + { _lconfig_cols = coerce (80 :: Int) + , _lconfig_indentPolicy = coerce IndentPolicyFree + , _lconfig_indentAmount = coerce (2 :: Int) + , _lconfig_indentWhereSpecial = coerce True + , _lconfig_indentListSpecial = coerce True + , _lconfig_importColumn = coerce (60 :: Int) + , _lconfig_altChooser = coerce (AltChooserBoundedSearch 3) + , _lconfig_columnAlignMode = coerce (ColumnAlignModeMajority 0.7) + , _lconfig_alignmentLimit = coerce (30 :: Int) + , _lconfig_alignmentBreakOnMultiline = coerce True + } + , _conf_errorHandling = ErrorHandlingConfig + { _econf_produceOutputOnErrors = coerce False + , _econf_Werror = coerce False + , _econf_ExactPrintFallback = coerce ExactPrintFallbackModeInline + , _econf_omit_output_valid_check = coerce False + } + , _conf_preprocessor = PreProcessorConfig + { _ppconf_CPPMode = coerce CPPModeAbort + , _ppconf_hackAroundIncludes = coerce False + } + , _conf_forward = ForwardOptions + { _options_ghc = Identity [] + } + } + +forwardOptionsSyntaxExtsEnabled :: ForwardOptions +forwardOptionsSyntaxExtsEnabled = ForwardOptions + { _options_ghc = Identity + [ "-XLambdaCase" + , "-XMultiWayIf" + , "-XGADTs" + , "-XPatternGuards" + , "-XViewPatterns" + , "-XTupleSections" + , "-XExplicitForAll" + , "-XImplicitParams" + , "-XQuasiQuotes" + , "-XTemplateHaskell" + , "-XBangPatterns" + , "-XTypeApplications" + ] + } + configParser :: CmdParser Identity out (CConfig Option) configParser = do -- TODO: why does the default not trigger; ind never should be []!! @@ -162,3 +225,4 @@ showConfigYaml :: Config -> String showConfigYaml = Data.ByteString.Char8.unpack . Data.Yaml.encode . cMap (\(Identity x) -> Just x) + diff --git a/src/Language/Haskell/Brittany/Internal/Config/Types.hs b/src/Language/Haskell/Brittany/Internal/Config/Types.hs index 243bf98..43f6695 100644 --- a/src/Language/Haskell/Brittany/Internal/Config/Types.hs +++ b/src/Language/Haskell/Brittany/Internal/Config/Types.hs @@ -317,50 +317,6 @@ data ExactPrintFallbackMode -- A PROGRAM BY TRANSFORMING IT. deriving (Show, Generic, Data) -staticDefaultConfig :: Config -staticDefaultConfig = Config - { _conf_version = coerce (1 :: Int) - , _conf_debug = DebugConfig - { _dconf_dump_config = coerce False - , _dconf_dump_annotations = coerce False - , _dconf_dump_ast_unknown = coerce False - , _dconf_dump_ast_full = coerce False - , _dconf_dump_bridoc_raw = coerce False - , _dconf_dump_bridoc_simpl_alt = coerce False - , _dconf_dump_bridoc_simpl_floating = coerce False - , _dconf_dump_bridoc_simpl_par = coerce False - , _dconf_dump_bridoc_simpl_columns = coerce False - , _dconf_dump_bridoc_simpl_indent = coerce False - , _dconf_dump_bridoc_final = coerce False - , _dconf_roundtrip_exactprint_only = coerce False - } - , _conf_layout = LayoutConfig - { _lconfig_cols = coerce (80 :: Int) - , _lconfig_indentPolicy = coerce IndentPolicyFree - , _lconfig_indentAmount = coerce (2 :: Int) - , _lconfig_indentWhereSpecial = coerce True - , _lconfig_indentListSpecial = coerce True - , _lconfig_importColumn = coerce (60 :: Int) - , _lconfig_altChooser = coerce (AltChooserBoundedSearch 3) - , _lconfig_columnAlignMode = coerce (ColumnAlignModeMajority 0.7) - , _lconfig_alignmentLimit = coerce (30 :: Int) - , _lconfig_alignmentBreakOnMultiline = coerce True - } - , _conf_errorHandling = ErrorHandlingConfig - { _econf_produceOutputOnErrors = coerce False - , _econf_Werror = coerce False - , _econf_ExactPrintFallback = coerce ExactPrintFallbackModeInline - , _econf_omit_output_valid_check = coerce False - } - , _conf_preprocessor = PreProcessorConfig - { _ppconf_CPPMode = coerce CPPModeAbort - , _ppconf_hackAroundIncludes = coerce False - } - , _conf_forward = ForwardOptions - { _options_ghc = Identity [] - } - } - cMap :: CZipWith k => (forall a . f a -> g a) -> k f -> k g cMap f c = cZipWith (\_ -> f) c c