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

Commit 1679ce4

Browse files
geo2arv-auditor
andauthored
Allows printing Kore JSON with pyk print (#568)
This small change extends the functionality of the `pyk` executable with pretty-printing of Kore JSON files. This is useful for diffing up bug reports submitted to the Haskell backend team. --------- Co-authored-by: devops <[email protected]>
1 parent f0f2e0f commit 1679ce4

File tree

3 files changed

+17
-5
lines changed

3 files changed

+17
-5
lines changed

package/version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.1.393
1+
0.1.394

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.393"
7+
version = "0.1.394"
88
description = ""
99
authors = [
1010
"Runtime Verification, Inc. <[email protected]>",

src/pyk/__main__.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import logging
44
import sys
55
from argparse import ArgumentParser, FileType
6+
from enum import Enum
67
from pathlib import Path
78
from typing import TYPE_CHECKING
89

@@ -31,6 +32,11 @@
3132
_LOGGER: Final = logging.getLogger(__name__)
3233

3334

35+
class PrintInput(Enum):
36+
KORE_JSON = 'kore-json'
37+
KAST_JSON = 'kast-json'
38+
39+
3440
def main() -> None:
3541
# KAST terms can end up nested quite deeply, because of the various assoc operators (eg. _Map_, _Set_, ...).
3642
# Most pyk operations are defined recursively, meaning you get a callstack the same depth as the term.
@@ -53,8 +59,13 @@ def main() -> None:
5359
def exec_print(args: Namespace) -> None:
5460
kompiled_dir: Path = args.definition_dir
5561
printer = KPrint(kompiled_dir)
56-
_LOGGER.info(f'Reading Kast from file: {args.term.name}')
57-
term = KInner.from_json(args.term.read())
62+
if args.input == PrintInput.KORE_JSON:
63+
_LOGGER.info(f'Reading Kore JSON from file: {args.term.name}')
64+
kore = Pattern.from_json(args.term.read())
65+
term = printer.kore_to_kast(kore)
66+
else:
67+
_LOGGER.info(f'Reading Kast JSON from file: {args.term.name}')
68+
term = KInner.from_json(args.term.read())
5869
if is_top(term):
5970
args.output_file.write(printer.pretty_print(term))
6071
_LOGGER.info(f'Wrote file: {args.output_file.name}')
@@ -147,7 +158,8 @@ def create_argument_parser() -> ArgumentParser:
147158
help='Pretty print a term.',
148159
parents=[k_cli_args.logging_args, definition_args, k_cli_args.display_args],
149160
)
150-
print_args.add_argument('term', type=FileType('r'), help='Input term (in JSON).')
161+
print_args.add_argument('term', type=FileType('r'), help='Input term (in format specified with --input).')
162+
print_args.add_argument('--input', default=PrintInput.KAST_JSON, type=PrintInput, choices=list(PrintInput))
151163
print_args.add_argument('--omit-labels', default='', nargs='?', help='List of labels to omit from output.')
152164
print_args.add_argument(
153165
'--keep-cells', default='', nargs='?', help='List of cells with primitive values to keep in output.'

0 commit comments

Comments
 (0)