mirror of
https://github.com/Sei-Lisa/LSL-PyOptimizer
synced 2025-07-03 00:18:20 +00:00
vector v;<0,0,0>-v; triggered EParseTypeMismatch. Fixed. Also minor fixes.
Convert the self.__class__, which was terrible syntax, to the respective classes in the exceptions. Fix the EInternal hack in the buitins.txt parser.
This commit is contained in:
parent
5e4c19e5ec
commit
d1bbe26c49
1 changed files with 44 additions and 37 deletions
|
@ -43,44 +43,51 @@ class EParse(Exception):
|
||||||
class EParseUEOF(EParse):
|
class EParseUEOF(EParse):
|
||||||
def __init__(self, parser):
|
def __init__(self, parser):
|
||||||
parser.errorpos = len(parser.script)
|
parser.errorpos = len(parser.script)
|
||||||
super(self.__class__, self).__init__(parser, u"Unexpected EOF")
|
super(EParseUEOF, self).__init__(parser, u"Unexpected EOF")
|
||||||
|
|
||||||
class EParseSyntax(EParse):
|
class EParseSyntax(EParse):
|
||||||
def __init__(self, parser):
|
def __init__(self, parser):
|
||||||
super(self.__class__, self).__init__(parser, u"Syntax error")
|
super(EParseSyntax, self).__init__(parser, u"Syntax error")
|
||||||
|
|
||||||
class EParseAlreadyDefined(EParse):
|
class EParseAlreadyDefined(EParse):
|
||||||
def __init__(self, parser):
|
def __init__(self, parser):
|
||||||
super(self.__class__, self).__init__(parser, u"Name previously declared within scope")
|
super(EParseAlreadyDefined, self).__init__(parser,
|
||||||
|
u"Name previously declared within scope")
|
||||||
|
|
||||||
class EParseUndefined(EParse):
|
class EParseUndefined(EParse):
|
||||||
def __init__(self, parser):
|
def __init__(self, parser):
|
||||||
super(self.__class__, self).__init__(parser, u"Name not defined within scope")
|
super(EParseUndefined, self).__init__(parser,
|
||||||
|
u"Name not defined within scope")
|
||||||
|
|
||||||
class EParseTypeMismatch(EParse):
|
class EParseTypeMismatch(EParse):
|
||||||
def __init__(self, parser):
|
def __init__(self, parser):
|
||||||
super(self.__class__, self).__init__(parser, u"Type mismatch")
|
super(EParseTypeMismatch, self).__init__(parser, u"Type mismatch")
|
||||||
|
|
||||||
class EParseReturnShouldBeEmpty(EParse):
|
class EParseReturnShouldBeEmpty(EParse):
|
||||||
def __init__(self, parser):
|
def __init__(self, parser):
|
||||||
super(self.__class__, self).__init__(parser, u"Return statement type doesn't match function return type")
|
super(EParseReturnShouldBeEmpty, self).__init__(parser,
|
||||||
|
u"Return statement type doesn't match function return type")
|
||||||
|
|
||||||
class EParseReturnIsEmpty(EParse):
|
class EParseReturnIsEmpty(EParse):
|
||||||
def __init__(self, parser):
|
def __init__(self, parser):
|
||||||
super(self.__class__, self).__init__(parser, u"Function returns a value but return statement doesn't")
|
super(EParseReturnIsEmtpy, self).__init__(parser,
|
||||||
|
u"Function returns a value but return statement doesn't")
|
||||||
|
|
||||||
# This error message may sound funny, for good reasons.
|
# This error message may sound funny, for good reasons.
|
||||||
class EParseInvalidField(EParse):
|
class EParseInvalidField(EParse):
|
||||||
def __init__(self, parser):
|
def __init__(self, parser):
|
||||||
super(self.__class__, self).__init__(parser, u"Use of vector or quaternion method on incorrect type")
|
super(EParseInvalidField, self).__init__(parser,
|
||||||
|
u"Use of vector or quaternion method on incorrect type")
|
||||||
|
|
||||||
class EParseFunctionMismatch(EParse):
|
class EParseFunctionMismatch(EParse):
|
||||||
def __init__(self, parser):
|
def __init__(self, parser):
|
||||||
super(self.__class__, self).__init__(parser, u"Function type mismatches type or number of arguments")
|
super(EParseFunctionMismatch, self).__init__(parser,
|
||||||
|
u"Function type mismatches type or number of arguments")
|
||||||
|
|
||||||
class EParseDeclarationScope(EParse):
|
class EParseDeclarationScope(EParse):
|
||||||
def __init__(self, parser):
|
def __init__(self, parser):
|
||||||
super(self.__class__, self).__init__(parser, u"Declaration requires a new scope -- use { and }")
|
super(EParseDeclarationScope, self).__init__(parser,
|
||||||
|
u"Declaration requires a new scope -- use { and }")
|
||||||
|
|
||||||
class EInternal(Exception):
|
class EInternal(Exception):
|
||||||
"""This exception is a construct to allow a different function to cause an
|
"""This exception is a construct to allow a different function to cause an
|
||||||
|
@ -453,7 +460,7 @@ class parser(object):
|
||||||
|
|
||||||
self.expect(',')
|
self.expect(',')
|
||||||
self.NextToken()
|
self.NextToken()
|
||||||
except EParseSyntax:
|
except EParse: # The errors can be varied, e.g. <0,0,0>-v; raises EParseTypeMismatch
|
||||||
# Backtrack
|
# Backtrack
|
||||||
self.pos = pos
|
self.pos = pos
|
||||||
self.errorpos = errorpos
|
self.errorpos = errorpos
|
||||||
|
@ -1876,19 +1883,17 @@ class parser(object):
|
||||||
name = match.group(5)
|
name = match.group(5)
|
||||||
if name in self.constants:
|
if name in self.constants:
|
||||||
warning('Global already defined in bultins.txt, overwriting: ' + name)
|
warning('Global already defined in bultins.txt, overwriting: ' + name)
|
||||||
try:
|
typ = match.group(4)
|
||||||
typ = match.group(4)
|
if typ == 'quaternion':
|
||||||
if typ == 'quaternion':
|
typ = 'rotation'
|
||||||
typ = 'rotation'
|
value = match.group(6)
|
||||||
value = match.group(6)
|
if typ == 'integer':
|
||||||
if typ == 'integer':
|
value = int(value, 0)
|
||||||
value = int(value, 0)
|
elif typ == 'float':
|
||||||
elif typ == 'float':
|
value = lslfuncs.F32(float(value))
|
||||||
value = lslfuncs.F32(float(value))
|
elif typ == 'string':
|
||||||
elif typ == 'string':
|
value = value.decode('utf8')
|
||||||
value = value.decode('utf8')
|
if parse_str_re.match(value):
|
||||||
if not parse_str_re.match(value):
|
|
||||||
raise EInternal
|
|
||||||
esc = False
|
esc = False
|
||||||
tmp = value[1:-1]
|
tmp = value[1:-1]
|
||||||
value = u''
|
value = u''
|
||||||
|
@ -1906,10 +1911,14 @@ class parser(object):
|
||||||
value += c
|
value += c
|
||||||
#if typ == 'key':
|
#if typ == 'key':
|
||||||
# value = Key(value)
|
# value = Key(value)
|
||||||
elif typ == 'key':
|
else:
|
||||||
warning('Key constants not supported in builtins.txt: ' + line)
|
warning('Invalid string in builtins.txt: ' + line)
|
||||||
value = None
|
value = None
|
||||||
elif typ in ('vector', 'rotation'):
|
elif typ == 'key':
|
||||||
|
warning('Key constants not supported in builtins.txt: ' + line)
|
||||||
|
value = None
|
||||||
|
elif typ in ('vector', 'rotation'):
|
||||||
|
try:
|
||||||
if value[0:1] != '<' or value[-1:] != '>':
|
if value[0:1] != '<' or value[-1:] != '>':
|
||||||
raise ValueError
|
raise ValueError
|
||||||
value = value[1:-1].split(',')
|
value = value[1:-1].split(',')
|
||||||
|
@ -1935,16 +1944,14 @@ class parser(object):
|
||||||
raise ValueError
|
raise ValueError
|
||||||
value[3] = lslfuncs.F32(float(num.group(1)))
|
value[3] = lslfuncs.F32(float(num.group(1)))
|
||||||
value = Quaternion(value)
|
value = Quaternion(value)
|
||||||
else:
|
except ValueError:
|
||||||
assert typ == 'list'
|
warning('Invalid vector/rotation syntax in builtins.txt: ' + line)
|
||||||
warning('List constants not supported in builtins.txt: ' + line)
|
else:
|
||||||
value = None
|
assert typ == 'list'
|
||||||
if value is not None:
|
warning('List constants not supported in builtins.txt: ' + line)
|
||||||
self.constants[name] = value
|
value = None
|
||||||
|
if value is not None:
|
||||||
|
self.constants[name] = value
|
||||||
|
|
||||||
except EInternal:
|
|
||||||
warning('Invalid string in builtins.txt: ' + line)
|
|
||||||
except ValueError:
|
|
||||||
warning('Invalid vector syntax in builtins.txt: ' + line)
|
|
||||||
finally:
|
finally:
|
||||||
f.close()
|
f.close()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue