@@ -187,6 +187,32 @@ parseCondition = condOr
187187 sp = skipSpaces
188188
189189
190+ ------------------------------------------------------------------------------
191+
192+ data CondTree' v c a = CondNode
193+ { condTreeData :: a
194+ , condTreeConstraints :: [c ]
195+ , condTreeComponents :: [( Condition v
196+ , CondTree' v c a
197+ , Maybe (CondTree' v c a ))]
198+ }
199+
200+
201+
202+ ppCondTree' :: Show v => CondTree' v c a -> (c -> Doc ) -> Doc
203+ ppCondTree' (CondNode dat cs ifs) ppD =
204+ (text " depends: " <+>
205+ (fsep $ punctuate (char ' ,' ) $ map ppD cs))
206+ $+$
207+ (vcat $ map ppIf ifs)
208+ where
209+ ppIf (c,thenTree,mElseTree) =
210+ ((text " if" <+> ppCond c <> colon) $$
211+ nest 2 (ppCondTree' thenTree ppD))
212+ $+$ (maybe empty (\ t -> text " else: " $$ nest 2 (ppCondTree' t ppD))
213+ mElseTree)
214+
215+
190216-- | A CondTree is the internal (normalized) representation of a specification
191217-- with (optional) conditional statements in it. To get to the final value,
192218-- a sequence of conditions has to be evaluated completely, which then specifies
@@ -391,4 +417,20 @@ test_parseCondition = map (runP 1 "test" parseCondition) testConditions
391417 , " flag( foo_O_-_O_bar )"
392418 ]
393419
420+ test_ppCondTree' = render $ ppCondTree' tstTree (text . show )
421+ where
422+ tstTree :: CondTree' ConfVar Int String
423+ tstTree = CondNode " A" [0 ]
424+ [ (CNot (Var (Flag " a" )),
425+ CondNode " B" [1 ] [] ,
426+ Nothing )
427+ , (CAnd (Var (Flag " b" )) (Var (Flag " c" )),
428+ CondNode " C" [2 ] [] ,
429+ Just $ CondNode " D" [3 ]
430+ [ (Lit True ,
431+ CondNode " E" [4 ] [] ,
432+ Just $ CondNode " F" [5 ] [] ) ])
433+ ]
434+
435+
394436#endif
0 commit comments