From 860088078dc1166745282f94ba674160851a5885 Mon Sep 17 00:00:00 2001 From: Kevin Matz Date: Mon, 29 Oct 2018 07:53:49 -1000 Subject: [PATCH] allow spans to be bounded by floats --- OscCommentMacroListener.py | 21 ++++++++++++--------- README.md | 2 +- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/OscCommentMacroListener.py b/OscCommentMacroListener.py index b2262cb..3092a6b 100644 --- a/OscCommentMacroListener.py +++ b/OscCommentMacroListener.py @@ -45,6 +45,14 @@ def beautify_lisp_string(in_string): return out_string +# floating point ranges +def frange(start, stop, step=1): + i = start + while i < stop: + yield i + i += step + + class HogDevice(): # button state constants buttonDOWN = 1 @@ -115,15 +123,10 @@ class OscCommentMacroListener(CommentMacroListener): ctx.parentCtx.targets.append(ctx.value) def exitSpan(self, ctx: CommentMacroParser.SpanContext): - n1 = ctx.n1.value - n2 = ctx.n2.value - if (isinstance(n1, int) and isinstance(n2, int)): - minimum = min(n1, n2) - maximum = max(n1, n2) - for i in (range(minimum, maximum + 1)): - ctx.parentCtx.targets.append(i) - else: - logger.error("ERROR: Spans must be ranged with intigers.") + minimum = min(ctx.n1.value, ctx.n2.value) + maximum = max(ctx.n1.value, ctx.n2.value) + for i in (frange(minimum, maximum + 1)): + ctx.parentCtx.targets.append(i) def exitMasterGo(self, ctx: CommentMacroParser.MasterGoContext): if ctx.target() is None: diff --git a/README.md b/README.md index d9a5595..5f449ff 100644 --- a/README.md +++ b/README.md @@ -61,7 +61,7 @@ that are implimented in python. | ----------------|-----|-----------| | fade times | t5 | no | | multiple targets | 1,2 | Yes | -| ranges | 1>4 | Yes, integers only | +| ranges | 1>4 | Yes, intervals of 1 | | multiple macros | GM1:GL3 | Yes | | network devices | h4 | Yes, H devices only | | wait times | WAIT1 | BaconScript only; Continue script after n seconds.