Handle trailing spaces in configs properly; don't make them part of the value.
Handle unquoted palette values. Parse errors will occur if they're not exact.
This commit is contained in:
parent
fc53521c80
commit
769b86119b
|
@ -10,7 +10,7 @@ def maybe(*choices): return group(*choices) + '?'
|
||||||
Newline = re.compile(r'[\r\n]+')
|
Newline = re.compile(r'[\r\n]+')
|
||||||
Whitespace = r'[ \f\t]*'
|
Whitespace = r'[ \f\t]*'
|
||||||
Comment = r'#[^\r\n]*'
|
Comment = r'#[^\r\n]*'
|
||||||
Ignore = re.compile(Whitespace + maybe(Comment) + maybe(r'[\r\n]+'))
|
Ignore = re.compile(Whitespace + maybe(Comment) + maybe(r'[\r\n]+') + '$')
|
||||||
|
|
||||||
WhitespaceRE = re.compile(Whitespace)
|
WhitespaceRE = re.compile(Whitespace)
|
||||||
CommentRE = re.compile(Comment)
|
CommentRE = re.compile(Comment)
|
||||||
|
@ -20,8 +20,11 @@ QuotedStrings = {"'": re.compile(r"'([^'\r\n]*)'"), '"': re.compile(r'"([^"\r\n]
|
||||||
Section = re.compile(r"\[([^\r\n\]]+)\][ \f\t]*")
|
Section = re.compile(r"\[([^\r\n\]]+)\][ \f\t]*")
|
||||||
Setting = re.compile(r"(\w+)\s*=\s*")
|
Setting = re.compile(r"(\w+)\s*=\s*")
|
||||||
|
|
||||||
Colorvalue = re.compile(r'(#[0-9a-fA-F]{6}|#[0-9a-fA-F]{3})' + Whitespace + maybe(Comment))
|
PaletteColours = '(?:#[0-9a-fA-F]{12}:){15}#[0-9a-fA-F]{12}'
|
||||||
Barevalue = re.compile(r'([^\r\n#]+)' + Whitespace + maybe(Comment))
|
SingleColour = '#[0-9a-fA-F]{6}|#[0-9a-fA-F]{3}'
|
||||||
|
|
||||||
|
Colourvalue = re.compile(group(PaletteColours, SingleColour))
|
||||||
|
Barevalue = re.compile(r'((?:[^\r\n# \f\t]+|[^\r\n#]+(?!' + Ignore.pattern +'))+)')
|
||||||
|
|
||||||
Tabsize = 8
|
Tabsize = 8
|
||||||
|
|
||||||
|
@ -106,12 +109,12 @@ class ConfigFile:
|
||||||
# "quoted value"
|
# "quoted value"
|
||||||
if not self._call_if_quoted_string(self._value):
|
if not self._call_if_quoted_string(self._value):
|
||||||
# #000000 # colour that would otherwise be a comment
|
# #000000 # colour that would otherwise be a comment
|
||||||
if not self._call_if_match(Colorvalue, 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):
|
||||||
raise ConfigSyntaxError("Setting without a value", self)
|
raise ConfigSyntaxError("Setting without a value", self)
|
||||||
|
|
||||||
self._call_if_match(Ignore, None)
|
self._call_if_match(Ignore, lambda junk: dbg("Ignoring: %s" % junk))
|
||||||
|
|
||||||
if self._line[self._pos:] != '':
|
if self._line[self._pos:] != '':
|
||||||
raise ConfigSyntaxError("Unexpected token", self)
|
raise ConfigSyntaxError("Unexpected token", self)
|
||||||
|
|
Loading…
Reference in New Issue