Handle errors a bit more sensibly, especially with quoted strings

This commit is contained in:
Thomas Hurst 2008-08-26 17:12:29 +01:00
parent 9baf905cab
commit c304b519ad
1 changed files with 26 additions and 29 deletions

View File

@ -89,8 +89,7 @@ class ConfigFile:
while True:
mo = QuotedStrings[chr].match(self._line, self._pos)
if mo is None:
self.parse_error(_("Unterminated quoted string"))
return False
raise ConfigSyntaxError(_("Unterminated quoted string"), self)
self._pos = mo.end()
if self._line[self._pos - 2] == '\\':
string += mo.group(1)[0:-1] + chr
@ -103,13 +102,6 @@ class ConfigFile:
else:
return False
def parse_error(self, error):
e = ConfigSyntaxError(error, self)
if self.errors_are_fatal:
raise e
else:
self.errors.append(e)
def parse(self):
file = open(self.filename)
rc = file.readlines()
@ -126,6 +118,7 @@ class ConfigFile:
self.errors = []
for self._line in rc:
try:
self._lnum += 1
self._pos = 0
self._max = len(self._line)
@ -143,13 +136,17 @@ class ConfigFile:
if not self._call_if_match(Colourvalue, self._value, 1):
# bare value
if not self._call_if_match(Barevalue, self._value, 1):
self.parse_error(_("Setting without a value"))
continue
raise ConfigSyntaxError(_("Setting without a value"), self)
self._call_if_match(Ignore, lambda junk: dbg("Ignoring: %s" % junk))
if self._line[self._pos:] != '':
self.parse_error(_("Unexpected token"))
raise ConfigSyntaxError(_("Unexpected token"), self)
except ConfigSyntaxError, e:
if self.errors_are_fatal:
raise e
else:
self.errors.append(e)
if self.errors:
raise ParsedWithErrors(self.filename, self.errors)