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 " "
, docForceSingleline typeDoc2
]
, docPar -- an multi-line result, with the "child" indented.
, docPar -- a multi-line result, with the "child" indented.
typeDoc1 -- "Maybe\
(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
(what is `docSharedWrapper`?
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
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
probably already noticed in the last example.
For this example not much happens; you can see so in the final `BriDoc` which
you probably already noticed in the last example.
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
@ -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
is used here (`m` will be `ToBriDocM` mostly):
~~~~
~~~~.hs
allocNodeIndex :: MonadMultiState NodeAllocIndex m => m Int
allocNodeIndex = do
NodeAllocIndex i <- mGet

View File

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