Minor fixups in docs plus some minor Refactoring

pull/35/head
Lennart Spitzner 2017-04-12 14:31:53 +02:00
parent 2dd6fe83f5
commit 14884be8df
2 changed files with 66 additions and 71 deletions

View File

@ -64,13 +64,13 @@ See [this example ast output](output-example-01.md)
, docLit $ Text.pack " " , docLit $ Text.pack " "
, docForceSingleline typeDoc2 , docForceSingleline typeDoc2
] ]
, docPar -- an multi-line result, with the "child" indented. , docPar -- a multi-line result, with the "child" indented.
typeDoc1 -- "Maybe\ typeDoc1 -- "Maybe\
(docEnsureIndent BrIndentRegular typeDoc2) -- Int" (docEnsureIndent BrIndentRegular typeDoc2) -- Int"
] ]
~~~~ ~~~~
here, all functions prefixed with "doc" produces new BriDoc(F) nodes. here, all functions prefixed with "doc" produce new BriDoc(F) nodes.
I think this example can be understood already, even when many details I think this example can be understood already, even when many details
(what is `docSharedWrapper`? (what is `docSharedWrapper`?
What are the exact semantics of the different `doc..` functions? What are the exact semantics of the different `doc..` functions?
@ -144,8 +144,8 @@ in a single line now.
We will not go into detail about how this "alt-transformation" (the one doing We will not go into detail about how this "alt-transformation" (the one doing
the "selection work" works and what other transformations follow here. the "selection work" works and what other transformations follow here.
For this example not much happens; you can see so in the output which you For this example not much happens; you can see so in the final `BriDoc` which
probably already noticed in the last example. you probably already noticed in the last example.
But for the "alt-transformation" itself, lets at least consider what it does: But for the "alt-transformation" itself, lets at least consider what it does:
We traverse the input BriDoc and whenever a `BDAlt` is encountered, one of the We traverse the input BriDoc and whenever a `BDAlt` is encountered, one of the
@ -215,7 +215,7 @@ We don't use this directly, but the code below uses this,
and if the type `ToBriDocM` scared you, see how mundane it and if the type `ToBriDocM` scared you, see how mundane it
is used here (`m` will be `ToBriDocM` mostly): is used here (`m` will be `ToBriDocM` mostly):
~~~~ ~~~~.hs
allocNodeIndex :: MonadMultiState NodeAllocIndex m => m Int allocNodeIndex :: MonadMultiState NodeAllocIndex m => m Int
allocNodeIndex = do allocNodeIndex = do
NodeAllocIndex i <- mGet NodeAllocIndex i <- mGet

View File

@ -188,7 +188,8 @@ ppModule lmod@(L loc m@(HsModule _name _exports _imports decls _ _)) = do
in (anns', post) in (anns', post)
MultiRWSS.withMultiReader anns' $ processDefault emptyModule MultiRWSS.withMultiReader anns' $ processDefault emptyModule
decls `forM_` ppDecl decls `forM_` ppDecl
let finalComments = filter ( fst .> \case let finalComments = filter
( fst .> \case
ExactPrint.Types.AnnComment{} -> True ExactPrint.Types.AnnComment{} -> True
_ -> False _ -> False
) )
@ -257,39 +258,34 @@ layoutBriDoc :: Data.Data.Data ast => ast -> BriDocNumbered -> PPM ()
layoutBriDoc ast briDoc = do layoutBriDoc ast briDoc = do
-- first step: transform the briDoc. -- first step: transform the briDoc.
briDoc' <- MultiRWSS.withMultiStateS BDEmpty $ do briDoc' <- MultiRWSS.withMultiStateS BDEmpty $ do
-- Note that briDoc is BriDocNumbered, but state type is BriDoc.
-- That's why the alt-transform looks a bit special here.
traceIfDumpConf "bridoc raw" _dconf_dump_bridoc_raw traceIfDumpConf "bridoc raw" _dconf_dump_bridoc_raw
$ briDocToDoc $ briDocToDoc
$ unwrapBriDocNumbered $ unwrapBriDocNumbered
$ briDoc $ briDoc
-- bridoc transformation: remove alts -- bridoc transformation: remove alts
transformAlts briDoc >>= mSet transformAlts briDoc >>= mSet
mGet mGet >>= briDocToDoc .> traceIfDumpConf "bridoc post-alt"
>>= traceIfDumpConf "bridoc post-alt" _dconf_dump_bridoc_simpl_alt _dconf_dump_bridoc_simpl_alt
. briDocToDoc
-- bridoc transformation: float stuff in -- bridoc transformation: float stuff in
mGet <&> transformSimplifyFloating >>= mSet mGet >>= transformSimplifyFloating .> mSet
mGet mGet >>= briDocToDoc .> traceIfDumpConf "bridoc post-floating"
>>= traceIfDumpConf "bridoc post-floating"
_dconf_dump_bridoc_simpl_floating _dconf_dump_bridoc_simpl_floating
. briDocToDoc
-- bridoc transformation: par removal -- bridoc transformation: par removal
mGet <&> transformSimplifyPar >>= mSet mGet >>= transformSimplifyPar .> mSet
mGet mGet >>= briDocToDoc .> traceIfDumpConf "bridoc post-par"
>>= traceIfDumpConf "bridoc post-par" _dconf_dump_bridoc_simpl_par _dconf_dump_bridoc_simpl_par
. briDocToDoc
-- bridoc transformation: float stuff in -- bridoc transformation: float stuff in
mGet <&> transformSimplifyColumns >>= mSet mGet >>= transformSimplifyColumns .> mSet
mGet mGet >>= briDocToDoc .> traceIfDumpConf "bridoc post-columns"
>>= traceIfDumpConf "bridoc post-columns" _dconf_dump_bridoc_simpl_columns _dconf_dump_bridoc_simpl_columns
. briDocToDoc -- bridoc transformation: indent
-- -- bridoc transformation: indent mGet >>= transformSimplifyIndent .> mSet
mGet <&> transformSimplifyIndent >>= mSet mGet >>= briDocToDoc .> traceIfDumpConf "bridoc post-indent"
mGet _dconf_dump_bridoc_simpl_indent
>>= traceIfDumpConf "bridoc post-indent" _dconf_dump_bridoc_simpl_indent mGet >>= briDocToDoc .> traceIfDumpConf "bridoc final"
. briDocToDoc _dconf_dump_bridoc_final
mGet
>>= traceIfDumpConf "bridoc final" _dconf_dump_bridoc_final
. briDocToDoc
-- -- convert to Simple type -- -- convert to Simple type
-- simpl <- mGet <&> transformToSimple -- simpl <- mGet <&> transformToSimple
-- return simpl -- return simpl
@ -317,10 +313,9 @@ layoutBriDoc ast briDoc = do
state' <- MultiRWSS.withMultiStateS state $ layoutBriDocM briDoc' state' <- MultiRWSS.withMultiStateS state $ layoutBriDocM briDoc'
let let remainingComments =
remainingComments =
extractAllComments =<< Map.elems (_lstate_comments state') extractAllComments =<< Map.elems (_lstate_comments state')
remainingComments remainingComments
`forM_` (mTell . (:[]) . LayoutErrorUnusedComment . show . fst) `forM_` (fst .> show .> LayoutErrorUnusedComment .> (:[]) .> mTell)
return $ () return $ ()