Handle errors a bit more sensibly, especially with quoted strings
This commit is contained in:
parent
9baf905cab
commit
c304b519ad
|
@ -89,8 +89,7 @@ class ConfigFile:
|
||||||
while True:
|
while True:
|
||||||
mo = QuotedStrings[chr].match(self._line, self._pos)
|
mo = QuotedStrings[chr].match(self._line, self._pos)
|
||||||
if mo is None:
|
if mo is None:
|
||||||
self.parse_error(_("Unterminated quoted string"))
|
raise ConfigSyntaxError(_("Unterminated quoted string"), self)
|
||||||
return False
|
|
||||||
self._pos = mo.end()
|
self._pos = mo.end()
|
||||||
if self._line[self._pos - 2] == '\\':
|
if self._line[self._pos - 2] == '\\':
|
||||||
string += mo.group(1)[0:-1] + chr
|
string += mo.group(1)[0:-1] + chr
|
||||||
|
@ -103,13 +102,6 @@ class ConfigFile:
|
||||||
else:
|
else:
|
||||||
return False
|
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):
|
def parse(self):
|
||||||
file = open(self.filename)
|
file = open(self.filename)
|
||||||
rc = file.readlines()
|
rc = file.readlines()
|
||||||
|
@ -126,6 +118,7 @@ class ConfigFile:
|
||||||
self.errors = []
|
self.errors = []
|
||||||
|
|
||||||
for self._line in rc:
|
for self._line in rc:
|
||||||
|
try:
|
||||||
self._lnum += 1
|
self._lnum += 1
|
||||||
self._pos = 0
|
self._pos = 0
|
||||||
self._max = len(self._line)
|
self._max = len(self._line)
|
||||||
|
@ -143,13 +136,17 @@ class ConfigFile:
|
||||||
if not self._call_if_match(Colourvalue, self._value, 1):
|
if not self._call_if_match(Colourvalue, self._value, 1):
|
||||||
# bare value
|
# bare value
|
||||||
if not self._call_if_match(Barevalue, self._value, 1):
|
if not self._call_if_match(Barevalue, self._value, 1):
|
||||||
self.parse_error(_("Setting without a value"))
|
raise ConfigSyntaxError(_("Setting without a value"), self)
|
||||||
continue
|
|
||||||
|
|
||||||
self._call_if_match(Ignore, lambda junk: dbg("Ignoring: %s" % junk))
|
self._call_if_match(Ignore, lambda junk: dbg("Ignoring: %s" % junk))
|
||||||
|
|
||||||
if self._line[self._pos:] != '':
|
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:
|
if self.errors:
|
||||||
raise ParsedWithErrors(self.filename, self.errors)
|
raise ParsedWithErrors(self.filename, self.errors)
|
||||||
|
|
Loading…
Reference in New Issue