24
24
from textual .app import ComposeResult
25
25
from textual .events import Click
26
26
27
+ from ..cterm import CSubst
27
28
from ..kast import KInner
28
29
from ..ktool .kprint import KPrint
29
30
from .show import NodePrinter
@@ -277,13 +278,23 @@ def _boolify(c: KInner) -> KInner:
277
278
else :
278
279
return c
279
280
281
+ def _boolify_print (c : KInner ) -> str :
282
+ return self ._kprint .pretty_print (_boolify (c ))
283
+
280
284
def _cterm_text (cterm : CTerm ) -> tuple [str , str ]:
281
285
config = cterm .config
282
286
constraints = map (_boolify , cterm .constraints )
283
287
if self ._minimize :
284
288
config = minimize_term (config )
285
289
return (self ._kprint .pretty_print (config ), '\n ' .join (self ._kprint .pretty_print (c ) for c in constraints ))
286
290
291
+ def _csubst_text (csubst : CSubst ) -> tuple [str , str ]:
292
+ equalities = map (
293
+ _boolify_print , flatten_label ('#And' , csubst .pred (sort_with = self ._kprint .definition , constraints = False ))
294
+ )
295
+ constraints = map (_boolify_print , flatten_label ('#And' , csubst .constraint ))
296
+ return '\n ' .join (equalities ), '\n ' .join (constraints )
297
+
287
298
term_str = 'Term'
288
299
constraint_str = 'Constraint'
289
300
custom_str = 'Custom'
@@ -309,30 +320,18 @@ def _cterm_text(cterm: CTerm) -> tuple[str, str]:
309
320
term_str , constraint_str = _cterm_text (crewrite )
310
321
311
322
elif type (self ._element ) is KCFG .Cover :
312
- subst_equalities = map (
313
- _boolify ,
314
- flatten_label (
315
- '#And' , self ._element .csubst .pred (sort_with = self ._kprint .definition , constraints = False )
316
- ),
317
- )
318
- constraints = map (_boolify , flatten_label ('#And' , self ._element .csubst .constraint ))
319
- term_str = '\n ' .join (self ._kprint .pretty_print (se ) for se in subst_equalities )
320
- constraint_str = '\n ' .join (self ._kprint .pretty_print (c ) for c in constraints )
323
+ term_str , constraint_str = _csubst_text (self ._element .csubst )
321
324
322
325
elif type (self ._element ) is KCFG .Split :
323
326
term_strs = [f'split: { shorten_hashes (self ._element .source .id )} ' ]
324
327
for target_id , csubst in self ._element .splits .items ():
325
328
term_strs .append ('' )
326
329
term_strs .append (f' - { shorten_hashes (target_id )} ' )
327
- if len (csubst .subst ) > 0 :
328
- subst_equalities = map (
329
- _boolify ,
330
- flatten_label ('#And' , csubst .pred (sort_with = self ._kprint .definition , constraints = False )),
331
- )
332
- term_strs .extend (f' { self ._kprint .pretty_print (cline )} ' for cline in subst_equalities )
333
- if len (csubst .constraints ) > 0 :
334
- constraints = map (_boolify , flatten_label ('#And' , csubst .constraint ))
335
- term_strs .extend (f' { self ._kprint .pretty_print (cline )} ' for cline in constraints )
330
+ equalities_str , constraints_str = _csubst_text (csubst )
331
+ if equalities_str != '#Top' :
332
+ term_strs .extend ([f' { es } ' for es in equalities_str .split ('\n ' )])
333
+ if constraints_str != '#Top' :
334
+ term_strs .extend ([f' { es } ' for es in constraints_str .split ('\n ' )])
336
335
term_str = '\n ' .join (term_strs )
337
336
338
337
elif type (self ._element ) is KCFG .NDBranch :
0 commit comments