Skip to content

Commit

Permalink
Merge pull request #30 from TheGreatfpmK/new-master
Browse files Browse the repository at this point in the history
Added range-based support for type double and support for specifying increment step
  • Loading branch information
TheGreatfpmK authored Dec 11, 2023
2 parents afa507e + a1d1d62 commit a9c7c3e
Showing 1 changed file with 27 additions and 7 deletions.
34 changes: 27 additions & 7 deletions paynt/parser/prism_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,13 +118,33 @@ def parse_holes(cls, prism, expression_parser, hole_definitions):
hole_max = []
for hole_name,hole_type,hole_options in hole_definitions:
if ".." in hole_options:
assert hole_type == "int", "cannot use range-based definitions for non-integer hole types"
options = hole_options.split("..")
range_start = int(options[0])
range_end = int(options[1])
hole_min.append(range_start)
hole_max.append(range_end)
options = [str(o) for o in range(range_start,range_end+1)]
assert hole_type == "int" or hole_type == "double", "cannot use range-based definitions for non-integer of non-double hole types"
if hole_type == "double":
assert ":" in hole_options, "using range-based definition for double requires specifying the increment step range_start..range_end:step"
range_start = float(hole_options[0:hole_options.find('..')])
range_end = float(hole_options[hole_options.find('..')+2:hole_options.find(':')].strip())
increment_string = hole_options.split(':')[-1].strip()
increment = float(increment_string)
increment_decimal_precision = len(increment_string.split('.')[-1])
hole_min.append(range_start)
hole_max.append(range_end)
steps = (range_end - range_start) / increment
options = ["{:.{n}f}".format(range_start + x * increment, n=increment_decimal_precision) for x in range(int(round(steps)+1))]
if float(options[-1]) > range_end:
options = options[:-1]
else:
if ":" in hole_options:
range_start = int(hole_options[0:hole_options.find('..')])
range_end = int(hole_options[hole_options.find('..')+2:hole_options.find(':')].strip())
increment = int(hole_options.split(':')[-1].strip())
else:
options = hole_options.split("..")
range_start = int(options[0])
range_end = int(options[1])
increment = 1
hole_min.append(range_start)
hole_max.append(range_end)
options = [str(o) for o in range(range_start,range_end+1, increment)]
else:
options = hole_options.split(",")
if hole_type == "int":
Expand Down

0 comments on commit a9c7c3e

Please sign in to comment.