pull/123/merge
Shinya Yamaguchi 2018-03-04 18:19:46 +00:00 committed by GitHub
commit ce8d55acf6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 17 additions and 4 deletions

View File

@ -108,6 +108,7 @@ library {
, cmdargs >=0.10.14 && <0.11
, czipwith >=1.0.0.0 && <1.1
, ghc-boot-th >=8.0.1 && <8.3
, text-latin1 >= 0.3 && < 0.4
}
default-extensions: {
CPP

View File

@ -264,7 +264,7 @@ briDocLineLength briDoc = flip StateS.evalState False $ rec briDoc
where
rec = \case
BDEmpty -> return $ 0
BDLit t -> StateS.put False $> Text.length t
BDLit t -> StateS.put False $> elasticLength t
BDSeq bds -> sum <$> rec `mapM` bds
BDCols _ bds -> sum <$> rec `mapM` bds
BDSeparator -> StateS.get >>= \b -> StateS.put True $> if b then 0 else 1

View File

@ -32,6 +32,7 @@ module Language.Haskell.Brittany.Internal.BackendUtils
, layoutWritePriorComments
, layoutWritePostComments
, layoutRemoveIndentLevelLinger
, elasticLength
)
where
@ -51,6 +52,7 @@ import Language.Haskell.Brittany.Internal.Utils
import GHC ( Located, GenLocated(L), moduleNameString )
import Text.Ascii (isAscii)
traceLocal
@ -97,11 +99,21 @@ layoutWriteAppend t = do
mTell $ Text.Builder.fromText $ t
mModify $ \s -> s
{ _lstate_curYOrAddNewline = Left $ case _lstate_curYOrAddNewline s of
Left c -> c + Text.length t + spaces
Left c -> c + elasticLength t + spaces
Right{} -> Text.length t + spaces
, _lstate_addSepSpace = Nothing
}
-- |
-- >>> elasticLength "あ"
-- 2
-- >>> elasticLength "abc"
-- 3
-- >>> elasticLength "aあa"
-- 4
elasticLength :: Text -> Int
elasticLength = Text.foldl' (\len c -> if isAscii c then len + 1 else len + 2) 0
layoutWriteAppendSpaces
:: ( MonadMultiWriter Text.Builder.Builder m
, MonadMultiState LayoutState m