mirror of
https://github.com/Sei-Lisa/LSL-PyOptimizer
synced 2024-11-21 06:15:56 -07:00
Get rid of builtins.txt.dat by adding a parameter to the parser ctor.
This commit is contained in:
parent
1160fea8cf
commit
1a67db64dc
5 changed files with 31 additions and 1206 deletions
16
builtins-unittest.txt
Normal file
16
builtins-unittest.txt
Normal file
|
@ -0,0 +1,16 @@
|
|||
const key a="\t"
|
||||
event ev(integer i)
|
||||
event ev(integer i)
|
||||
quaternion x(integer i)
|
||||
void x(integer i)
|
||||
blah
|
||||
const vector a = <4,5,3,2>
|
||||
const vector a = <4,5,3,2
|
||||
const vector a = <x,4,3>
|
||||
const vector a = <4,x,3>
|
||||
const vector a = <3,4,x>
|
||||
const rotation a = <3,4,4,x>
|
||||
const list l = []
|
||||
const quaternion q=<1,2,3,4>
|
||||
const string v="
|
||||
const string q="\t"
|
|
@ -1,7 +1,3 @@
|
|||
// builtins.txt provides the data for the parser.
|
||||
// builtins.txt.dat is a copy used only by the unit testing program
|
||||
// testparser.py, and can be removed.
|
||||
|
||||
// Generated by LSL2 Derived Files Generator. Database version: 0.0.20150429000; output module version: 0.0.20140731000
|
||||
integer llAbs( integer val )
|
||||
float llAcos( float val )
|
||||
|
|
1160
builtins.txt.dat
1160
builtins.txt.dat
File diff suppressed because it is too large
Load diff
|
@ -2429,7 +2429,7 @@ list lazy_list_set(list L, integer i, list v)
|
|||
|
||||
return self.parse(script, options)
|
||||
|
||||
def __init__(self):
|
||||
def __init__(self, builtins = 'builtins.txt', seftable = 'seftable.txt'):
|
||||
"""Reads the library."""
|
||||
|
||||
self.events = {}
|
||||
|
@ -2453,7 +2453,7 @@ list lazy_list_set(list L, integer i, list v)
|
|||
parse_num_re = re.compile(r'^\s*(-?(?=[0-9]|\.[0-9])[0-9]*((?:\.[0-9]*)?(?:[Ee][+-]?[0-9]+)?))\s*$')
|
||||
parse_str_re = re.compile(ur'^"((?:[^"\\]|\\.)*)"$')
|
||||
|
||||
f = open(lslcommon.DataPath + 'builtins.txt', 'rb')
|
||||
f = open(lslcommon.DataPath + builtins, 'rb')
|
||||
try:
|
||||
while True:
|
||||
line = f.readline()
|
||||
|
@ -2461,7 +2461,7 @@ list lazy_list_set(list L, integer i, list v)
|
|||
if line[-1] == '\n': line = line[:-1]
|
||||
match = parse_lin_re.match(line)
|
||||
if not match:
|
||||
warning('Syntax error in builtins.txt, line ' + line)
|
||||
warning('Syntax error in ' + builtins + ', line ' + line)
|
||||
continue
|
||||
if match.group(1):
|
||||
# event or function
|
||||
|
@ -2471,7 +2471,7 @@ list lazy_list_set(list L, integer i, list v)
|
|||
if typ == 'void':
|
||||
typ = None
|
||||
elif typ != 'event' and typ not in self.types:
|
||||
warning('Invalid type in builtins.txt, line ' + line + ': ' + typ)
|
||||
warning('Invalid type in ' + builtins + ', line ' + line + ': ' + typ)
|
||||
continue
|
||||
args = []
|
||||
arglist = match.group(3)
|
||||
|
@ -2481,7 +2481,7 @@ list lazy_list_set(list L, integer i, list v)
|
|||
for arg in arglist:
|
||||
argtyp = parse_arg_re.match(arg).group(1)
|
||||
if argtyp not in self.types:
|
||||
warning('Invalid type in builtins.txt, line ' + line + ': ' + argtyp)
|
||||
warning('Invalid type in ' + builtins + ', line ' + line + ': ' + argtyp)
|
||||
bad = True
|
||||
break
|
||||
args.append(parse_arg_re.match(arg).group(1))
|
||||
|
@ -2490,14 +2490,14 @@ list lazy_list_set(list L, integer i, list v)
|
|||
name = match.group(2)
|
||||
if typ == 'event':
|
||||
if name in self.events:
|
||||
warning('Event already defined in bultins.txt, overwriting: ' + name)
|
||||
warning('Event already defined in ' + builtins + ', overwriting: ' + name)
|
||||
self.events[name] = tuple(args)
|
||||
else:
|
||||
# Library functions go to the functions table. If
|
||||
# they are implemented in lslfuncs.*, they get a
|
||||
# reference to the implementation; otherwise None.
|
||||
if name in self.funclibrary:
|
||||
warning('Function already defined in bultins.txt, overwriting: ' + name)
|
||||
warning('Function already defined in ' + builtins + ', overwriting: ' + name)
|
||||
fn = getattr(lslfuncs, name, None)
|
||||
self.funclibrary[name] = {'Kind':'f', 'Type':typ, 'ParamTypes':args}
|
||||
if fn is not None:
|
||||
|
@ -2506,10 +2506,10 @@ list lazy_list_set(list L, integer i, list v)
|
|||
# constant
|
||||
name = match.group(5)
|
||||
if name in self.constants:
|
||||
warning('Global already defined in bultins.txt, overwriting: ' + name)
|
||||
warning('Global already defined in ' + builtins + ', overwriting: ' + name)
|
||||
typ = match.group(4)
|
||||
if typ not in self.types:
|
||||
warning('Invalid type in builtins.txt, line ' + line + ': ' + typ)
|
||||
warning('Invalid type in ' + builtins + ', line ' + line + ': ' + typ)
|
||||
continue
|
||||
if typ == 'quaternion':
|
||||
typ = 'rotation'
|
||||
|
@ -2539,10 +2539,10 @@ list lazy_list_set(list L, integer i, list v)
|
|||
#if typ == 'key':
|
||||
# value = Key(value)
|
||||
else:
|
||||
warning('Invalid string in builtins.txt: ' + line)
|
||||
warning('Invalid string in ' + builtins + ': ' + line)
|
||||
value = None
|
||||
elif typ == 'key':
|
||||
warning('Key constants not supported in builtins.txt: ' + line)
|
||||
warning('Key constants not supported in ' + builtins + ': ' + line)
|
||||
value = None
|
||||
elif typ in ('vector', 'rotation'):
|
||||
try:
|
||||
|
@ -2572,10 +2572,10 @@ list lazy_list_set(list L, integer i, list v)
|
|||
value[3] = lslfuncs.F32(float(num.group(1)))
|
||||
value = Quaternion(value)
|
||||
except ValueError:
|
||||
warning('Invalid vector/rotation syntax in builtins.txt: ' + line)
|
||||
warning('Invalid vector/rotation syntax in ' + builtins + ': ' + line)
|
||||
else:
|
||||
assert typ == 'list'
|
||||
warning('List constants not supported in builtins.txt: ' + line)
|
||||
warning('List constants not supported in ' + builtins + ': ' + line)
|
||||
value = None
|
||||
if value is not None:
|
||||
self.constants[name] = value
|
||||
|
@ -2588,7 +2588,7 @@ list lazy_list_set(list L, integer i, list v)
|
|||
# that includes domain data (min, max) and possibly input
|
||||
# parameter transformations e.g.
|
||||
# llSensor(..., PI, ...) -> llSensor(..., 4, ...).
|
||||
f = open(lslcommon.DataPath + 'seftable.txt', 'rb')
|
||||
f = open(lslcommon.DataPath + seftable, 'rb')
|
||||
try:
|
||||
while True:
|
||||
line = f.readline()
|
||||
|
|
|
@ -34,34 +34,7 @@ class UnitTestCase(unittest.TestCase):
|
|||
|
||||
class Test01_LibraryLoader(UnitTestCase):
|
||||
def test_coverage(self):
|
||||
os.remove('builtins.txt')
|
||||
f = open('builtins.txt', 'wb')
|
||||
f.write(r'''const key a="\t"
|
||||
event ev(integer i)
|
||||
event ev(integer i)
|
||||
quaternion x(integer i)
|
||||
void x(integer i)
|
||||
blah
|
||||
const vector a = <4,5,3,2>
|
||||
const vector a = <4,5,3,2
|
||||
const vector a = <x,4,3>
|
||||
const vector a = <4,x,3>
|
||||
const vector a = <3,4,x>
|
||||
const rotation a = <3,4,4,x>
|
||||
const list l = []
|
||||
const quaternion q=<1,2,3,4>
|
||||
const string v="
|
||||
const string q="\t"
|
||||
''')
|
||||
f.close()
|
||||
parser()
|
||||
f = open('builtins.txt.dat', 'rb')
|
||||
b = f.read()
|
||||
f.close()
|
||||
os.remove('builtins.txt')
|
||||
f = open('builtins.txt', 'wb')
|
||||
f.write(b)
|
||||
f.close()
|
||||
parser(builtins='builtins-unittest.txt')
|
||||
parser()
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue