inline string to int/float
This commit is contained in:
parent
01e8a09925
commit
54340773bc
|
@ -23,13 +23,6 @@ from CommentMacroListener import CommentMacroListener
|
||||||
logger = logging.getLogger("CommentMacro")
|
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
|
# https://raw.githubusercontent.com/jszheng/py3antlr4book/master/bin/pygrun
|
||||||
# this is a python version of TestRig
|
# this is a python version of TestRig
|
||||||
def beautify_lisp_string(in_string):
|
def beautify_lisp_string(in_string):
|
||||||
|
@ -91,7 +84,11 @@ class OscCommentMacroListener(CommentMacroListener):
|
||||||
ctx.parentCtx.targets.extend(ctx.targets) # add to parent targets
|
ctx.parentCtx.targets.extend(ctx.targets) # add to parent targets
|
||||||
|
|
||||||
def exitNumber(self, ctx: CommentMacroParser.NumberContext):
|
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):
|
if isinstance(ctx.parentCtx, CommentMacroParser.TargetContext):
|
||||||
ctx.parentCtx.targets.append(ctx.value)
|
ctx.parentCtx.targets.append(ctx.value)
|
||||||
else:
|
else:
|
||||||
|
|
Loading…
Reference in New Issue