mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2025-01-31 13:10:34 +00:00
Implement Script.error properly.
It's not good to get an attirbute error when trying to raise another error.
This commit is contained in:
parent
dade60863e
commit
f525be0880
1 changed files with 10 additions and 3 deletions
|
@ -19,6 +19,11 @@
|
||||||
|
|
||||||
# <pep8 compliant>
|
# <pep8 compliant>
|
||||||
|
|
||||||
|
class ScriptError(Exception):
|
||||||
|
def __init__(self, fname, line, message):
|
||||||
|
Exception.__init__(self, "%s:%d: %s" % (fname, line, message))
|
||||||
|
self.line = line
|
||||||
|
|
||||||
class Script:
|
class Script:
|
||||||
def __init__(self, filename, text, single="{}()':"):
|
def __init__(self, filename, text, single="{}()':"):
|
||||||
self.filename = filename
|
self.filename = filename
|
||||||
|
@ -27,6 +32,8 @@ class Script:
|
||||||
self.pos = 0
|
self.pos = 0
|
||||||
self.line = 1
|
self.line = 1
|
||||||
self.unget = False
|
self.unget = False
|
||||||
|
def error(self, msg):
|
||||||
|
raise ScriptError(self.filename, self.line, msg)
|
||||||
def tokenAvailable(self, crossline=False):
|
def tokenAvailable(self, crossline=False):
|
||||||
if self.unget:
|
if self.unget:
|
||||||
return True
|
return True
|
||||||
|
@ -60,16 +67,16 @@ class Script:
|
||||||
return self.token
|
return self.token
|
||||||
if not self.tokenAvailable(crossline):
|
if not self.tokenAvailable(crossline):
|
||||||
if not crossline:
|
if not crossline:
|
||||||
self.error(self, "line is incomplete")
|
self.error("line is incomplete")
|
||||||
return None
|
return None
|
||||||
if self.text[self.pos] == "\"":
|
if self.text[self.pos] == "\"":
|
||||||
self.pos += 1
|
self.pos += 1
|
||||||
start = self.pos
|
start = self.pos
|
||||||
if self.text[self.pos] == len(self.text):
|
if self.text[self.pos] == len(self.text):
|
||||||
self.error(self, "EOF inside quoted string")
|
self.error("EOF inside quoted string")
|
||||||
while self.text[self.pos] != "\"":
|
while self.text[self.pos] != "\"":
|
||||||
if self.pos == len(self.text):
|
if self.pos == len(self.text):
|
||||||
self.error(self, "EOF inside quoted string")
|
self.error("EOF inside quoted string")
|
||||||
return None
|
return None
|
||||||
if self.text[self.pos] == "\n":
|
if self.text[self.pos] == "\n":
|
||||||
self.line += 1
|
self.line += 1
|
||||||
|
|
Loading…
Reference in a new issue