Improve tuple layouting (also fixes #18 for tuples)

pull/35/head
Lennart Spitzner 2017-05-02 16:20:35 +02:00
parent f6324da600
commit ca42178eff
3 changed files with 53 additions and 15 deletions

View File

@ -747,11 +747,21 @@ foldrDesc f z = unSwitchQueue $ \q ->
#test issue 18 #test issue 18
autocheckCases = autocheckCases =
[ ("Never Deadlocks", representative deadlocksNever) [ ("Never Deadlocks" , representative deadlocksNever)
, ("No Exceptions", representative exceptionsNever) , ("No Exceptions" , representative exceptionsNever)
, ("Consistent Result", alwaysSame) -- already representative , ("Consistent Result", alwaysSame) -- already representative
] ]
#test issue 18b
autocheckCases =
[ ("Never Deadlocks", representative deadlocksNever)
, ("No Exceptions" , representative exceptionsNever)
, ( "Consistent Result"
, alwaysSame -- already representative
)
]
############################################################################### ###############################################################################
############################################################################### ###############################################################################
############################################################################### ###############################################################################

View File

@ -283,20 +283,46 @@ layoutExpr lexpr@(L _ expr) = docWrapNode lexpr $ case expr of
ExplicitTuple args boxity ExplicitTuple args boxity
| Just argExprs <- args `forM` (\case (L _ (Present e)) -> Just e; _ -> Nothing) -> do | Just argExprs <- args `forM` (\case (L _ (Present e)) -> Just e; _ -> Nothing) -> do
argDocs <- docSharedWrapper layoutExpr `mapM` argExprs argDocs <- docSharedWrapper layoutExpr `mapM` argExprs
case boxity of hasComments <- hasAnyCommentsBelow lexpr
Boxed -> docAlt let (openLit, closeLit) = case boxity of
[ docSeq Boxed -> (docLit $ Text.pack "(", docLit $ Text.pack ")")
$ [ docLit $ Text.pack "(" ] Unboxed -> (docLit $ Text.pack "(#", docLit $ Text.pack "#)")
++ List.intersperse (appSep $ docLit $ Text.pack ",") argDocs case splitFirstLast argDocs of
++ [ docLit $ Text.pack ")"] FirstLastEmpty -> docSeq
-- TODO [ openLit
, docNodeAnnKW lexpr (Just AnnOpenP) $ closeLit
] ]
Unboxed -> docAlt FirstLastSingleton e -> docAlt
[ docCols ColTuple
[ openLit
, docNodeAnnKW lexpr (Just AnnOpenP) $ docForceSingleline e
, closeLit
]
, docSetBaseY $ docLines
[ docSeq [ docSeq
$ [ docLit $ Text.pack "(#" ] [ openLit
++ List.intersperse (appSep $ docLit $ Text.pack ",") argDocs , docNodeAnnKW lexpr (Just AnnOpenP) $ docForceSingleline e
++ [ docLit $ Text.pack "#)"] ]
-- TODO , closeLit
]
]
FirstLast e1 ems eN ->
docAltFilter
[ (,) (not hasComments)
$ docCols ColTuple
( [docSeq [openLit, docForceSingleline e1]]
++ (ems <&> \e -> docSeq [docCommaSep, docForceSingleline e])
++ [docSeq [docCommaSep, docNodeAnnKW lexpr (Just AnnOpenP) (docForceSingleline eN), closeLit]]
)
, (,) True
$ let
start = docCols ColTuples
[appSep $ openLit, e1]
linesM = ems <&> \d ->
docCols ColTuples [docCommaSep, d]
lineN = docCols ColTuples [docCommaSep, docNodeAnnKW lexpr (Just AnnOpenP) eN]
end = closeLit
in docSetBaseY $ docLines $ [start] ++ linesM ++ [lineN] ++ [end]
] ]
ExplicitTuple{} -> ExplicitTuple{} ->
unknownNodeError "ExplicitTuple|.." lexpr unknownNodeError "ExplicitTuple|.." lexpr

View File

@ -168,6 +168,8 @@ data ColSig
| ColListComp | ColListComp
| ColList | ColList
| ColApp | ColApp
| ColTuple
| ColTuples
| ColOpPrefix -- merge with ColList ? other stuff? | ColOpPrefix -- merge with ColList ? other stuff?
-- TODO -- TODO