1
0
Fork 0

inline string to int/float

This commit is contained in:
Kevin Matz 2018-10-25 16:26:15 -04:00
parent 01e8a09925
commit 54340773bc
1 changed files with 5 additions and 8 deletions

View File

@ -23,13 +23,6 @@ from CommentMacroListener import CommentMacroListener
logger = logging.getLogger("CommentMacro")
def num(s):
try:
return int(s)
except ValueError:
return float(s)
# https://raw.githubusercontent.com/jszheng/py3antlr4book/master/bin/pygrun
# this is a python version of TestRig
def beautify_lisp_string(in_string):
@ -91,7 +84,11 @@ class OscCommentMacroListener(CommentMacroListener):
ctx.parentCtx.targets.extend(ctx.targets) # add to parent targets
def exitNumber(self, ctx: CommentMacroParser.NumberContext):
ctx.value = num(ctx.getText())
try:
ctx.value = int(ctx.getText())
except ValueError:
ctx.value = float(ctx.getText())
if isinstance(ctx.parentCtx, CommentMacroParser.TargetContext):
ctx.parentCtx.targets.append(ctx.value)
else: