Skip to content
This repository was archived by the owner on Apr 25, 2024. It is now read-only.

Commit b518f19

Browse files
ehildenbrv-auditor
andauthored
Print parseable rules from KCFGShow (#857)
In this PR: #835, the function `build_rule` is modified to maintain all structure of a rule. But that routine is also used for creating pretty-printing rules for parsing via the frontend. Rules that need to be parsed via the frontend must not contain the `<generated*>` cells. This PR makes sure that `KCFGShow(...)` still minimizes the rules that are printed via `to_module`. This should allow undoing most of the output changes here: runtimeverification/kontrol#325. --------- Co-authored-by: devops <[email protected]>
1 parent 4493d41 commit b518f19

File tree

4 files changed

+23
-17
lines changed

4 files changed

+23
-17
lines changed

docs/conf.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
project = 'pyk'
1010
author = 'Runtime Verification, Inc'
1111
copyright = '2024, Runtime Verification, Inc'
12-
version = '0.1.612'
13-
release = '0.1.612'
12+
version = '0.1.613'
13+
release = '0.1.613'
1414

1515
# -- General configuration ---------------------------------------------------
1616
# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration

package/version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.1.612
1+
0.1.613

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "poetry.core.masonry.api"
44

55
[tool.poetry]
66
name = "pyk"
7-
version = "0.1.612"
7+
version = "0.1.613"
88
description = ""
99
authors = [
1010
"Runtime Verification, Inc. <[email protected]>",

src/pyk/kcfg/show.py

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,11 @@
99
from ..kast.manip import (
1010
flatten_label,
1111
inline_cell_maps,
12+
minimize_rule,
1213
minimize_term,
1314
ml_pred_to_bool,
1415
push_down_rewrites,
16+
remove_generated_cells,
1517
sort_ac_collections,
1618
)
1719
from ..kast.outer import KRule
@@ -92,17 +94,6 @@ def _hide_cells(_k: KInner) -> KInner:
9294
return top_down(_hide_cells, term)
9395
return term
9496

95-
@staticmethod
96-
def hide_cells_in_rules(
97-
module: KFlatModule, module_name: str | None = None, omit_cells: Iterable[str] = ()
98-
) -> KFlatModule:
99-
def _hide_cells_in_rule(_sent: KSentence) -> KSentence:
100-
if type(_sent) is KRule:
101-
return _sent.let(body=KCFGShow.hide_cells(_sent.body, omit_cells))
102-
return _sent
103-
104-
return module.let(sentences=map(_hide_cells_in_rule, module.sentences))
105-
10697
@staticmethod
10798
def simplify_config(config: KInner, omit_cells: Iterable[str]) -> KInner:
10899
config = inline_cell_maps(config)
@@ -302,8 +293,23 @@ def pretty(
302293
) -> Iterable[str]:
303294
return (line for _, seg_lines in self.pretty_segments(kcfg, minimize=minimize) for line in seg_lines)
304295

305-
def to_module(self, cfg: KCFG, module_name: str | None = None, omit_cells: Iterable[str] = ()) -> KFlatModule:
306-
return KCFGShow.hide_cells_in_rules(cfg.to_module(module_name), omit_cells=omit_cells)
296+
def to_module(
297+
self,
298+
cfg: KCFG,
299+
module_name: str | None = None,
300+
omit_cells: Iterable[str] = (),
301+
parseable_output: bool = True,
302+
) -> KFlatModule:
303+
def _process_sentence(sent: KSentence) -> KSentence:
304+
if type(sent) is KRule:
305+
sent = sent.let(body=KCFGShow.hide_cells(sent.body, omit_cells))
306+
if parseable_output:
307+
sent = sent.let(body=remove_generated_cells(sent.body))
308+
sent = minimize_rule(sent)
309+
return sent
310+
311+
module = cfg.to_module(module_name)
312+
return module.let(sentences=[_process_sentence(sent) for sent in module.sentences])
307313

308314
def show(
309315
self,

0 commit comments

Comments
 (0)