Add square bracket range+count syntax
This commit is contained in:
parent
3daf9cac46
commit
35229d9488
|
@ -109,6 +109,9 @@ def draw_xy_grid(p, xs, ys, x_label, y_label, cell):
|
|||
re_range = re.compile(r"\s*([+-]?\s*\d+)\s*-\s*([+-]?\s*\d+)(?:\s*\(([+-]\d+)\s*\))?\s*")
|
||||
re_range_float = re.compile(r"\s*([+-]?\s*\d+(?:.\d*)?)\s*-\s*([+-]?\s*\d+(?:.\d*)?)(?:\s*\(([+-]\d+(?:.\d*)?)\s*\))?\s*")
|
||||
|
||||
re_range_count = re.compile(r"\s*([+-]?\s*\d+)\s*-\s*([+-]?\s*\d+)(?:\s*\[(\d+)\s*\])?\s*")
|
||||
re_range_count_float = re.compile(r"\s*([+-]?\s*\d+(?:.\d*)?)\s*-\s*([+-]?\s*\d+(?:.\d*)?)(?:\s*\[(\d+(?:.\d*)?)\s*\])?\s*")
|
||||
|
||||
class Script(scripts.Script):
|
||||
def title(self):
|
||||
return "X/Y plot"
|
||||
|
@ -138,6 +141,7 @@ class Script(scripts.Script):
|
|||
|
||||
for val in valslist:
|
||||
m = re_range.fullmatch(val)
|
||||
mc = re_range_count.fullmatch(val)
|
||||
if m is not None:
|
||||
|
||||
start = int(m.group(1))
|
||||
|
@ -145,6 +149,12 @@ class Script(scripts.Script):
|
|||
step = int(m.group(3)) if m.group(3) is not None else 1
|
||||
|
||||
valslist_ext += list(range(start, end, step))
|
||||
elif mc is not None:
|
||||
start = int(mc.group(1))
|
||||
end = int(mc.group(2))
|
||||
num = int(mc.group(3)) if mc.group(3) is not None else 1
|
||||
|
||||
valslist_ext += [int(x) for x in np.linspace(start = start, stop = end, num = num).tolist()]
|
||||
else:
|
||||
valslist_ext.append(val)
|
||||
|
||||
|
@ -154,12 +164,19 @@ class Script(scripts.Script):
|
|||
|
||||
for val in valslist:
|
||||
m = re_range_float.fullmatch(val)
|
||||
mc = re_range_count_float.fullmatch(val)
|
||||
if m is not None:
|
||||
start = float(m.group(1))
|
||||
end = float(m.group(2))
|
||||
step = float(m.group(3)) if m.group(3) is not None else 1
|
||||
|
||||
valslist_ext += np.arange(start, end + step, step).tolist()
|
||||
elif mc is not None:
|
||||
start = float(mc.group(1))
|
||||
end = float(mc.group(2))
|
||||
num = int(mc.group(3)) if mc.group(3) is not None else 1
|
||||
|
||||
valslist_ext += np.linspace(start = start, stop = end, num = num).tolist()
|
||||
else:
|
||||
valslist_ext.append(val)
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user