mirror of
https://github.com/Sei-Lisa/LSL-PyOptimizer
synced 2025-07-01 23:58:20 +00:00
Fix several bugs in lslbasefuncs; change InternalJsonScanMatching strategy.
Fix bug: add(Key, Key) is not valid. Fix bug: llList2CSV was raising an exception always. Fix bug in test program: llDumpList2String requires Unicode separator. Patch test program to not output the passed tests.
This commit is contained in:
parent
e620c9f305
commit
f03466629f
3 changed files with 16 additions and 25 deletions
|
@ -476,7 +476,7 @@ def add(a, b, f32=True):
|
||||||
if ta == tb in (list, unicode):
|
if ta == tb in (list, unicode):
|
||||||
return a + b
|
return a + b
|
||||||
# string + key, key + string are allowed here
|
# string + key, key + string are allowed here
|
||||||
if ta in (unicode, Key) and tb in (unicode, Key):
|
if ta in (unicode, Key) and tb in (unicode, Key) and not (ta == tb == Key):
|
||||||
return a + b
|
return a + b
|
||||||
if ta == list:
|
if ta == list:
|
||||||
return a + [b]
|
return a + [b]
|
||||||
|
@ -931,7 +931,7 @@ def llIntegerToBase64(x):
|
||||||
def llList2CSV(lst):
|
def llList2CSV(lst):
|
||||||
assert islist(lst)
|
assert islist(lst)
|
||||||
ret = []
|
ret = []
|
||||||
for elem in val:
|
for elem in lst:
|
||||||
# This always uses LSO rules for float to string.
|
# This always uses LSO rules for float to string.
|
||||||
if type(elem) == float:
|
if type(elem) == float:
|
||||||
ret.append(u'%.6f' % elem)
|
ret.append(u'%.6f' % elem)
|
||||||
|
|
|
@ -143,19 +143,11 @@ def InternalJsonF2S(f):
|
||||||
def InternalJsonScanMatching(json, idx):
|
def InternalJsonScanMatching(json, idx):
|
||||||
"""Shortcut: scan for a matching pair of {} or [] with proper nesting
|
"""Shortcut: scan for a matching pair of {} or [] with proper nesting
|
||||||
and string handling, with no validity check other than well-formedness,
|
and string handling, with no validity check other than well-formedness,
|
||||||
meaning all {} and [] must match.
|
meaning all {} or [] must match.
|
||||||
"""
|
"""
|
||||||
# TODO: InternalJsonScanMatching: Decide whether to use two nesting level variables rather than a stack.
|
matching = json[idx]
|
||||||
# That would mean that a nested malformed string like [{]} would be valid. SL may accept that.
|
matching += '}' if json[idx] == '{' else ']'
|
||||||
# (Or maybe even just ONE nesting level variable for the current element,
|
level = 1
|
||||||
# disregarding the nesting of the other, e.g. if we're on an object,
|
|
||||||
# the [] are not tracked thus {[} would be valid. That sounds like LSL.
|
|
||||||
# Or track [] and {} as the same, distinguishing whether
|
|
||||||
# the one at nesting level 0 matches the first (e.g. {[{}}} would be valid)
|
|
||||||
# Or just track the current one and screw the other (e.g. {{]]][]{}][}}
|
|
||||||
# would be valid). That sounds even more like LSL.
|
|
||||||
# Experiments are advisable.
|
|
||||||
stk = [json[idx]]
|
|
||||||
str = False
|
str = False
|
||||||
esc = False
|
esc = False
|
||||||
for i in xrange(idx+1, len(json)):
|
for i in xrange(idx+1, len(json)):
|
||||||
|
@ -169,13 +161,12 @@ def InternalJsonScanMatching(json, idx):
|
||||||
str = False
|
str = False
|
||||||
elif c == u'"':
|
elif c == u'"':
|
||||||
str = True
|
str = True
|
||||||
elif c in u'{[':
|
elif c in matching:
|
||||||
stk.append(c)
|
if c == matching[0]:
|
||||||
elif c in u']}':
|
level += 1
|
||||||
if stk[-1] != (u'{' if c == u'}' else u'['):
|
else:
|
||||||
return None # bad nesting
|
level -= 1
|
||||||
stk = stk[:-1]
|
if not level:
|
||||||
if stk == []:
|
|
||||||
return i+1
|
return i+1
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
|
@ -62,7 +62,7 @@ def test(fn, expected):
|
||||||
errors += 1
|
errors += 1
|
||||||
#raise ETestFailed
|
#raise ETestFailed
|
||||||
else:
|
else:
|
||||||
sys.stdout.write("PASSED! %s == %s\n" % (fn, repr(expected)))
|
pass#sys.stdout.write("PASSED! %s == %s\n" % (fn, repr(expected)))
|
||||||
|
|
||||||
def shouldexcept(txt, exc):
|
def shouldexcept(txt, exc):
|
||||||
global tests
|
global tests
|
||||||
|
@ -78,7 +78,7 @@ def shouldexcept(txt, exc):
|
||||||
try:
|
try:
|
||||||
eval(txt)
|
eval(txt)
|
||||||
except exc:
|
except exc:
|
||||||
sys.stdout.write("PASSED! %s on %s\n" % (exc.__name__, txt))
|
#sys.stdout.write("PASSED! %s on %s\n" % (exc.__name__, txt))
|
||||||
return
|
return
|
||||||
|
|
||||||
werr = sys.stderr.write
|
werr = sys.stderr.write
|
||||||
|
@ -130,7 +130,7 @@ def verify(msg, result, expected):
|
||||||
werr("Expect: " + repr(expected) + '\n')
|
werr("Expect: " + repr(expected) + '\n')
|
||||||
#return 0
|
#return 0
|
||||||
else:
|
else:
|
||||||
sys.stdout.write("PASSED! %s, expect=actual=%s\n" % (msg, repr(expected)))
|
pass#sys.stdout.write("PASSED! %s, expect=actual=%s\n" % (msg, repr(expected)))
|
||||||
#return 1
|
#return 1
|
||||||
|
|
||||||
def verify_list(msg, result, expected):
|
def verify_list(msg, result, expected):
|
||||||
|
@ -642,7 +642,7 @@ def do_tests():
|
||||||
u"9999999933815812510711506376257961984.000000, "
|
u"9999999933815812510711506376257961984.000000, "
|
||||||
u"99999996802856924650656260769173209088.000000")
|
u"99999996802856924650656260769173209088.000000")
|
||||||
|
|
||||||
test('llDumpList2String([F32(1e11)], "/")', u'100000000000.000000')
|
test('llDumpList2String([F32(1e11)], u"/")', u'100000000000.000000')
|
||||||
|
|
||||||
# Inputs
|
# Inputs
|
||||||
inp = [F32(i) for i in [1e0, 1e1, 1e2, 1e3, 1e4, 1e5, 1e6, 1e7, 1e8, 1e9, 1e10, 1e11, 1e12, 1e13, 1e14,
|
inp = [F32(i) for i in [1e0, 1e1, 1e2, 1e3, 1e4, 1e5, 1e6, 1e7, 1e8, 1e9, 1e10, 1e11, 1e12, 1e13, 1e14,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue