Prepare implementation for `IndentPolicyLeft`

pull/66/head
Lennart Spitzner 2017-09-21 23:26:23 +02:00
parent fdd2f5f6dc
commit 4568bd3553
3 changed files with 978 additions and 975 deletions

View File

@ -191,7 +191,7 @@ data IndentPolicy = IndentPolicyLeft -- never create a new indentation at more
| IndentPolicyFree -- can create new indentations whereever | IndentPolicyFree -- can create new indentations whereever
| IndentPolicyMultiple -- can create indentations only | IndentPolicyMultiple -- can create indentations only
-- at any n * amount. -- at any n * amount.
deriving (Show, Generic, Data) deriving (Eq, Show, Generic, Data)
data AltChooser = AltChooserSimpleQuick -- always choose last alternative. data AltChooser = AltChooserSimpleQuick -- always choose last alternative.
-- leads to tons of sparsely filled -- leads to tons of sparsely filled

File diff suppressed because it is too large Load Diff

View File

@ -26,57 +26,58 @@ import {-# SOURCE #-} Language.Haskell.Brittany.Internal.Layouters.Expr
layoutStmt :: ToBriDoc' (StmtLR RdrName RdrName (LHsExpr RdrName)) layoutStmt :: ToBriDoc' (StmtLR RdrName RdrName (LHsExpr RdrName))
layoutStmt lstmt@(L _ stmt) = docWrapNode lstmt $ case stmt of layoutStmt lstmt@(L _ stmt) = do
LastStmt body False _ -> do docWrapNode lstmt $ case stmt of
layoutExpr body LastStmt body False _ -> do
BindStmt lPat expr _ _ _ -> do layoutExpr body
patDoc <- fmap return $ colsWrapPat =<< layoutPat lPat BindStmt lPat expr _ _ _ -> do
expDoc <- docSharedWrapper layoutExpr expr patDoc <- fmap return $ colsWrapPat =<< layoutPat lPat
docAlt expDoc <- docSharedWrapper layoutExpr expr
[ docCols docAlt
ColBindStmt [ docCols
[ appSep patDoc ColBindStmt
, docSeq [appSep $ docLit $ Text.pack "<-", docForceParSpacing expDoc] [ appSep patDoc
, docSeq [appSep $ docLit $ Text.pack "<-", docForceParSpacing expDoc]
]
, docCols
ColBindStmt
[ appSep patDoc
, docAddBaseY BrIndentRegular
$ docPar (docLit $ Text.pack "<-") (expDoc)
]
] ]
, docCols LetStmt binds -> layoutLocalBinds binds >>= \case
ColBindStmt Nothing -> docLit $ Text.pack "let" -- i just tested
[ appSep patDoc -- it, and it is
, docAddBaseY BrIndentRegular -- indeed allowed.
$ docPar (docLit $ Text.pack "<-") (expDoc) -- heh.
Just [] -> docLit $ Text.pack "let" -- this probably never happens
Just [bindDoc] -> docAlt
[ docCols
ColDoLet
[ appSep $ docLit $ Text.pack "let"
, docSetBaseAndIndent $ return bindDoc
]
, docAddBaseY BrIndentRegular $ docPar
(docLit $ Text.pack "let")
(docSetBaseAndIndent $ return bindDoc)
] ]
] Just bindDocs -> docAlt
LetStmt binds -> layoutLocalBinds binds >>= \case [ docSeq
Nothing -> docLit $ Text.pack "let" -- i just tested [ appSep $ docLit $ Text.pack "let"
-- it, and it is , docSetBaseAndIndent $ docLines $ return <$> bindDocs
-- indeed allowed. ]
-- heh. , docAddBaseY BrIndentRegular $ docPar
Just [] -> docLit $ Text.pack "let" -- this probably never happens (docLit $ Text.pack "let")
Just [bindDoc] -> docAlt (docSetBaseAndIndent $ docLines $ return <$> bindDocs)
[ docCols
ColDoLet
[ appSep $ docLit $ Text.pack "let"
, docSetBaseAndIndent $ return bindDoc
] ]
, docAddBaseY BrIndentRegular RecStmt stmts _ _ _ _ _ _ _ _ _ -> do
$ docPar (docLit $ Text.pack "let") docSeq
(docSetBaseAndIndent $ return bindDoc) [ docLit (Text.pack "rec")
] , docSeparator
Just bindDocs -> docAlt , docSetBaseAndIndent $ docLines $ layoutStmt <$> stmts
[ docSeq
[ appSep $ docLit $ Text.pack "let"
, docSetBaseAndIndent $ docLines $ return <$> bindDocs
] ]
, docAddBaseY BrIndentRegular $ docPar BodyStmt expr _ _ _ -> do
(docLit $ Text.pack "let") expDoc <- docSharedWrapper layoutExpr expr
(docSetBaseAndIndent $ docLines $ return <$> bindDocs) docAddBaseY BrIndentRegular $ expDoc
] _ -> briDocByExactInlineOnly "some unknown statement" lstmt
RecStmt stmts _ _ _ _ _ _ _ _ _ -> do
docSeq
[ docLit (Text.pack "rec")
, docSeparator
, docSetBaseAndIndent $ docLines $ layoutStmt <$> stmts
]
BodyStmt expr _ _ _ -> do
expDoc <- docSharedWrapper layoutExpr expr
docAddBaseY BrIndentRegular $ expDoc
_ -> briDocByExactInlineOnly "some unknown statement" lstmt