Add BDDebug node to BriDoc
parent
1c5795f718
commit
449d4b4787
|
@ -412,6 +412,10 @@ transformAlts briDoc
|
||||||
BDFForceParSpacing bd -> rec bd
|
BDFForceParSpacing bd -> rec bd
|
||||||
BDFProhibitMTEL bd ->
|
BDFProhibitMTEL bd ->
|
||||||
reWrap . BDFProhibitMTEL <$> rec bd
|
reWrap . BDFProhibitMTEL <$> rec bd
|
||||||
|
BDFDebug s bd -> do
|
||||||
|
acp :: AltCurPos <- mGet
|
||||||
|
tellDebugMess $ "transformAlts: BDFDEBUG " ++ s ++ " (node-id=" ++ show brDcId ++ "): acp=" ++ show acp
|
||||||
|
reWrap . BDFDebug s <$> rec bd
|
||||||
processSpacingSimple :: (MonadMultiReader
|
processSpacingSimple :: (MonadMultiReader
|
||||||
Config m,
|
Config m,
|
||||||
MonadMultiState AltCurPos m, MonadMultiWriter (Seq String) m) => BriDocNumbered -> m ()
|
MonadMultiState AltCurPos m, MonadMultiWriter (Seq String) m) => BriDocNumbered -> m ()
|
||||||
|
@ -439,7 +443,7 @@ getSpacing :: forall m . (MonadMultiReader Config m, MonadMultiWriter (Seq Strin
|
||||||
getSpacing !bridoc = rec bridoc
|
getSpacing !bridoc = rec bridoc
|
||||||
where
|
where
|
||||||
rec :: BriDocNumbered -> m (LineModeValidity VerticalSpacing)
|
rec :: BriDocNumbered -> m (LineModeValidity VerticalSpacing)
|
||||||
rec (_, brDc) = do
|
rec (brDcId, brDc) = do
|
||||||
config <- mAsk
|
config <- mAsk
|
||||||
result <- case brDc of
|
result <- case brDc of
|
||||||
-- BDWrapAnnKey _annKey bd -> rec bd
|
-- BDWrapAnnKey _annKey bd -> rec bd
|
||||||
|
@ -550,11 +554,12 @@ getSpacing !bridoc = rec bridoc
|
||||||
mVs <- rec bd
|
mVs <- rec bd
|
||||||
return $ [ vs | vs <- mVs, _vs_parFlag vs || _vs_paragraph vs == VerticalSpacingParNone ]
|
return $ [ vs | vs <- mVs, _vs_parFlag vs || _vs_paragraph vs == VerticalSpacingParNone ]
|
||||||
BDFProhibitMTEL bd -> rec bd
|
BDFProhibitMTEL bd -> rec bd
|
||||||
|
BDFDebug s bd -> do
|
||||||
|
r <- rec bd
|
||||||
|
tellDebugMess $ "getSpacing: BDFDebug " ++ show s ++ " (node-id=" ++ show brDcId ++ "): mVs=" ++ show r
|
||||||
|
return r
|
||||||
#if INSERTTRACESGETSPACING
|
#if INSERTTRACESGETSPACING
|
||||||
mTell $ Seq.singleton ("getSpacing: visiting: "
|
tellDebugMess $ "getSpacing: visiting: " ++ show (toConstr $ brDc) ++ " -> " ++ show result
|
||||||
++ show (toConstr $ brDc)
|
|
||||||
++ " -> "
|
|
||||||
++ show result)
|
|
||||||
#endif
|
#endif
|
||||||
return result
|
return result
|
||||||
maxVs :: [LineModeValidity VerticalSpacing] -> LineModeValidity VerticalSpacing
|
maxVs :: [LineModeValidity VerticalSpacing] -> LineModeValidity VerticalSpacing
|
||||||
|
@ -743,6 +748,10 @@ getSpacings limit bridoc = rec bridoc
|
||||||
mVs <- rec bd
|
mVs <- rec bd
|
||||||
return $ [ vs | vs <- mVs, _vs_parFlag vs || _vs_paragraph vs == VerticalSpacingParNone ]
|
return $ [ vs | vs <- mVs, _vs_parFlag vs || _vs_paragraph vs == VerticalSpacingParNone ]
|
||||||
BDFProhibitMTEL bd -> rec bd
|
BDFProhibitMTEL bd -> rec bd
|
||||||
|
BDFDebug s bd -> do
|
||||||
|
r <- rec bd
|
||||||
|
tellDebugMess $ "getSpacings: BDFDebug " ++ show s ++ " (node-id=" ++ show brDcId ++ "): vs=" ++ show r
|
||||||
|
return r
|
||||||
#if INSERTTRACESGETSPACING
|
#if INSERTTRACESGETSPACING
|
||||||
case brdc of
|
case brdc of
|
||||||
BDFAnnotationPrior{} -> return ()
|
BDFAnnotationPrior{} -> return ()
|
||||||
|
@ -837,6 +846,8 @@ transformSimplifyFloating = stepBO .> stepFull
|
||||||
Just $ BDCols sig $ List.init cols ++ [BDAnnotationPost annKey1 $ List.last cols]
|
Just $ BDCols sig $ List.init cols ++ [BDAnnotationPost annKey1 $ List.last cols]
|
||||||
BDAnnotationPost annKey1 (BDAddBaseY indent x) ->
|
BDAnnotationPost annKey1 (BDAddBaseY indent x) ->
|
||||||
Just $ BDAddBaseY indent $ BDAnnotationPost annKey1 x
|
Just $ BDAddBaseY indent $ BDAnnotationPost annKey1 x
|
||||||
|
BDAnnotationPost annKey1 (BDDebug s x) ->
|
||||||
|
Just $ BDDebug s $ BDAnnotationPost annKey1 x
|
||||||
_ -> Nothing
|
_ -> Nothing
|
||||||
descendPrior = transformDownMay $ \case
|
descendPrior = transformDownMay $ \case
|
||||||
-- prior floating in
|
-- prior floating in
|
||||||
|
@ -850,22 +861,32 @@ transformSimplifyFloating = stepBO .> stepFull
|
||||||
Just $ BDCols sig (BDAnnotationPrior annKey1 l:lr)
|
Just $ BDCols sig (BDAnnotationPrior annKey1 l:lr)
|
||||||
BDAnnotationPrior annKey1 (BDAddBaseY indent x) ->
|
BDAnnotationPrior annKey1 (BDAddBaseY indent x) ->
|
||||||
Just $ BDAddBaseY indent $ BDAnnotationPrior annKey1 x
|
Just $ BDAddBaseY indent $ BDAnnotationPrior annKey1 x
|
||||||
|
BDAnnotationPrior annKey1 (BDDebug s x) ->
|
||||||
|
Just $ BDDebug s $ BDAnnotationPrior annKey1 x
|
||||||
_ -> Nothing
|
_ -> Nothing
|
||||||
descendBYPush = transformDownMay $ \case
|
descendBYPush = transformDownMay $ \case
|
||||||
BDBaseYPushCur (BDCols sig cols@(_:_)) ->
|
BDBaseYPushCur (BDCols sig cols@(_:_)) ->
|
||||||
Just $ BDCols sig (BDBaseYPushCur (List.head cols) : List.tail cols)
|
Just $ BDCols sig (BDBaseYPushCur (List.head cols) : List.tail cols)
|
||||||
|
BDBaseYPushCur (BDDebug s x) ->
|
||||||
|
Just $ BDDebug s (BDBaseYPushCur x)
|
||||||
_ -> Nothing
|
_ -> Nothing
|
||||||
descendBYPop = transformDownMay $ \case
|
descendBYPop = transformDownMay $ \case
|
||||||
BDBaseYPop (BDCols sig cols@(_:_)) ->
|
BDBaseYPop (BDCols sig cols@(_:_)) ->
|
||||||
Just $ BDCols sig (List.init cols ++ [BDBaseYPop (List.last cols)])
|
Just $ BDCols sig (List.init cols ++ [BDBaseYPop (List.last cols)])
|
||||||
|
BDBaseYPop (BDDebug s x) ->
|
||||||
|
Just $ BDDebug s (BDBaseYPop x)
|
||||||
_ -> Nothing
|
_ -> Nothing
|
||||||
descendILPush = transformDownMay $ \case
|
descendILPush = transformDownMay $ \case
|
||||||
BDIndentLevelPushCur (BDCols sig cols@(_:_)) ->
|
BDIndentLevelPushCur (BDCols sig cols@(_:_)) ->
|
||||||
Just $ BDCols sig (BDIndentLevelPushCur (List.head cols) : List.tail cols)
|
Just $ BDCols sig (BDIndentLevelPushCur (List.head cols) : List.tail cols)
|
||||||
|
BDIndentLevelPushCur (BDDebug s x) ->
|
||||||
|
Just $ BDDebug s (BDIndentLevelPushCur x)
|
||||||
_ -> Nothing
|
_ -> Nothing
|
||||||
descendILPop = transformDownMay $ \case
|
descendILPop = transformDownMay $ \case
|
||||||
BDIndentLevelPop (BDCols sig cols@(_:_)) ->
|
BDIndentLevelPop (BDCols sig cols@(_:_)) ->
|
||||||
Just $ BDCols sig (List.init cols ++ [BDIndentLevelPop (List.last cols)])
|
Just $ BDCols sig (List.init cols ++ [BDIndentLevelPop (List.last cols)])
|
||||||
|
BDIndentLevelPop (BDDebug s x) ->
|
||||||
|
Just $ BDDebug s (BDIndentLevelPop x)
|
||||||
_ -> Nothing
|
_ -> Nothing
|
||||||
descendAddB = transformDownMay $ \case
|
descendAddB = transformDownMay $ \case
|
||||||
-- AddIndent floats into Lines.
|
-- AddIndent floats into Lines.
|
||||||
|
@ -891,6 +912,8 @@ transformSimplifyFloating = stepBO .> stepFull
|
||||||
Just $ BDBaseYPushCur (BDAddBaseY ind x)
|
Just $ BDBaseYPushCur (BDAddBaseY ind x)
|
||||||
BDAddBaseY ind (BDBaseYPop x) ->
|
BDAddBaseY ind (BDBaseYPop x) ->
|
||||||
Just $ BDBaseYPop (BDAddBaseY ind x)
|
Just $ BDBaseYPop (BDAddBaseY ind x)
|
||||||
|
BDAddBaseY ind (BDDebug s x) ->
|
||||||
|
Just $ BDDebug s (BDAddBaseY ind x)
|
||||||
_ -> Nothing
|
_ -> Nothing
|
||||||
stepBO :: BriDoc -> BriDoc
|
stepBO :: BriDoc -> BriDoc
|
||||||
stepBO = -- traceFunctionWith "stepBO" (show . briDocToDocWithAnns) (show . briDocToDocWithAnns) $
|
stepBO = -- traceFunctionWith "stepBO" (show . briDocToDocWithAnns) (show . briDocToDocWithAnns) $
|
||||||
|
@ -1098,6 +1121,7 @@ transformSimplifyColumns = Uniplate.rewrite $ \case
|
||||||
BDProhibitMTEL{} -> Nothing
|
BDProhibitMTEL{} -> Nothing
|
||||||
BDSetParSpacing{} -> Nothing
|
BDSetParSpacing{} -> Nothing
|
||||||
BDForceParSpacing{} -> Nothing
|
BDForceParSpacing{} -> Nothing
|
||||||
|
BDDebug{} -> Nothing
|
||||||
BDNonBottomSpacing x -> Just x
|
BDNonBottomSpacing x -> Just x
|
||||||
|
|
||||||
-- prepare layouting by translating BDPar's, replacing them with Indents and
|
-- prepare layouting by translating BDPar's, replacing them with Indents and
|
||||||
|
@ -1165,6 +1189,7 @@ briDocLineLength briDoc = flip StateS.evalState False $ rec briDoc
|
||||||
BDSetParSpacing bd -> rec bd
|
BDSetParSpacing bd -> rec bd
|
||||||
BDForceParSpacing bd -> rec bd
|
BDForceParSpacing bd -> rec bd
|
||||||
BDNonBottomSpacing bd -> rec bd
|
BDNonBottomSpacing bd -> rec bd
|
||||||
|
BDDebug _ bd -> rec bd
|
||||||
|
|
||||||
layoutBriDocM
|
layoutBriDocM
|
||||||
:: forall w m
|
:: forall w m
|
||||||
|
@ -1325,6 +1350,9 @@ layoutBriDocM = \case
|
||||||
state' <- mGet
|
state' <- mGet
|
||||||
when (_lstate_inhibitMTEL state') $ do
|
when (_lstate_inhibitMTEL state') $ do
|
||||||
mSet $ state' { _lstate_inhibitMTEL = _lstate_inhibitMTEL state }
|
mSet $ state' { _lstate_inhibitMTEL = _lstate_inhibitMTEL state }
|
||||||
|
BDDebug s bd -> do
|
||||||
|
mTell $ Text.Builder.fromText $ Text.pack $ "{-" ++ s ++ "-}"
|
||||||
|
layoutBriDocM bd
|
||||||
where
|
where
|
||||||
-- alignColsPar :: [BriDoc]
|
-- alignColsPar :: [BriDoc]
|
||||||
-- -> m ()
|
-- -> m ()
|
||||||
|
|
|
@ -64,6 +64,7 @@ module Language.Haskell.Brittany.LayoutBasics
|
||||||
, docNonBottomSpacing
|
, docNonBottomSpacing
|
||||||
, docSetParSpacing
|
, docSetParSpacing
|
||||||
, docForceParSpacing
|
, docForceParSpacing
|
||||||
|
, docDebug
|
||||||
, briDocByExact
|
, briDocByExact
|
||||||
, briDocByExactNoComment
|
, briDocByExactNoComment
|
||||||
, fromMaybeIdentity
|
, fromMaybeIdentity
|
||||||
|
@ -942,6 +943,9 @@ docSetParSpacing bdm = allocateNode . BDFSetParSpacing =<< bdm
|
||||||
docForceParSpacing :: ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
|
docForceParSpacing :: ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
|
||||||
docForceParSpacing bdm = allocateNode . BDFForceParSpacing =<< bdm
|
docForceParSpacing bdm = allocateNode . BDFForceParSpacing =<< bdm
|
||||||
|
|
||||||
|
docDebug :: String -> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
|
||||||
|
docDebug s bdm = allocateNode . BDFDebug s =<< bdm
|
||||||
|
|
||||||
appSep :: ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
|
appSep :: ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
|
||||||
appSep x = docSeq [x, docSeparator]
|
appSep x = docSeq [x, docSeparator]
|
||||||
|
|
||||||
|
|
|
@ -238,6 +238,7 @@ data BriDoc
|
||||||
-- still work, but i should probably completely
|
-- still work, but i should probably completely
|
||||||
-- remove it, as i have no proper usecase for
|
-- remove it, as i have no proper usecase for
|
||||||
-- it anymore.
|
-- it anymore.
|
||||||
|
| BDDebug String BriDoc
|
||||||
deriving (Data.Data.Data, Eq, Ord)
|
deriving (Data.Data.Data, Eq, Ord)
|
||||||
|
|
||||||
data BriDocF f
|
data BriDocF f
|
||||||
|
@ -282,6 +283,7 @@ data BriDocF f
|
||||||
-- still work, but i should probably completely
|
-- still work, but i should probably completely
|
||||||
-- remove it, as i have no proper usecase for
|
-- remove it, as i have no proper usecase for
|
||||||
-- it anymore.
|
-- it anymore.
|
||||||
|
| BDFDebug String (f (BriDocF f))
|
||||||
|
|
||||||
-- deriving instance Data.Data.Data (BriDocF Identity)
|
-- deriving instance Data.Data.Data (BriDocF Identity)
|
||||||
deriving instance Data.Data.Data (BriDocF ((,) Int))
|
deriving instance Data.Data.Data (BriDocF ((,) Int))
|
||||||
|
@ -314,11 +316,12 @@ instance Uniplate.Uniplate BriDoc where
|
||||||
uniplate (BDSetParSpacing bd) = plate BDSetParSpacing |* bd
|
uniplate (BDSetParSpacing bd) = plate BDSetParSpacing |* bd
|
||||||
uniplate (BDForceParSpacing bd) = plate BDForceParSpacing |* bd
|
uniplate (BDForceParSpacing bd) = plate BDForceParSpacing |* bd
|
||||||
uniplate (BDProhibitMTEL bd) = plate BDProhibitMTEL |* bd
|
uniplate (BDProhibitMTEL bd) = plate BDProhibitMTEL |* bd
|
||||||
|
uniplate (BDDebug s bd) = plate BDDebug |- s |* bd
|
||||||
|
|
||||||
newtype NodeAllocIndex = NodeAllocIndex Int
|
newtype NodeAllocIndex = NodeAllocIndex Int
|
||||||
|
|
||||||
unwrapBriDocNumbered :: BriDocNumbered -> BriDoc
|
unwrapBriDocNumbered :: BriDocNumbered -> BriDoc
|
||||||
unwrapBriDocNumbered = snd .> \case
|
unwrapBriDocNumbered tpl = case snd tpl of
|
||||||
BDFEmpty -> BDEmpty
|
BDFEmpty -> BDEmpty
|
||||||
BDFLit t -> BDLit t
|
BDFLit t -> BDLit t
|
||||||
BDFSeq list -> BDSeq $ rec <$> list
|
BDFSeq list -> BDSeq $ rec <$> list
|
||||||
|
@ -343,6 +346,7 @@ unwrapBriDocNumbered = snd .> \case
|
||||||
BDFSetParSpacing bd -> BDSetParSpacing $ rec bd
|
BDFSetParSpacing bd -> BDSetParSpacing $ rec bd
|
||||||
BDFForceParSpacing bd -> BDForceParSpacing $ rec bd
|
BDFForceParSpacing bd -> BDForceParSpacing $ rec bd
|
||||||
BDFProhibitMTEL bd -> BDProhibitMTEL $ rec bd
|
BDFProhibitMTEL bd -> BDProhibitMTEL $ rec bd
|
||||||
|
BDFDebug s bd -> BDDebug (s ++ "@" ++ show (fst tpl)) $ rec bd
|
||||||
where
|
where
|
||||||
rec = unwrapBriDocNumbered
|
rec = unwrapBriDocNumbered
|
||||||
|
|
||||||
|
@ -372,6 +376,7 @@ briDocSeqSpine = \case
|
||||||
BDSetParSpacing bd -> briDocSeqSpine bd
|
BDSetParSpacing bd -> briDocSeqSpine bd
|
||||||
BDForceParSpacing bd -> briDocSeqSpine bd
|
BDForceParSpacing bd -> briDocSeqSpine bd
|
||||||
BDProhibitMTEL bd -> briDocSeqSpine bd
|
BDProhibitMTEL bd -> briDocSeqSpine bd
|
||||||
|
BDDebug _s bd -> briDocSeqSpine bd
|
||||||
|
|
||||||
briDocForceSpine :: BriDoc -> BriDoc
|
briDocForceSpine :: BriDoc -> BriDoc
|
||||||
briDocForceSpine bd = briDocSeqSpine bd `seq` bd
|
briDocForceSpine bd = briDocSeqSpine bd `seq` bd
|
||||||
|
|
Loading…
Reference in New Issue