Parse every configuration entry without crossing assignment lines

This commit is contained in:
Andras Schmelczer 2026-10-27 20:02:11 +00:00
commit eba404bc96

View file

@ -2,19 +2,16 @@ import re
pattern = re.compile(
r"""
(?:^|\n) # new key-value pairs must start on a new line
\s* # leading whitespace is allowed
(?!\#) # the key cannot start with a `#` symbol
(\w+?) # then comes the key
\s*=\s* # the key and value are separated by an equal sign
(?: # then comes the value
"([^"]*)" # the value can be surrounded by quotes: "value"
| '([^']*)' # the value can be surrounded by quotes: 'value'
| `([^`]*)` # the value can be surrounded by quotes: `value`
| ([^#\n]*?) # or it is bare, in that case, the trailing whitespace is ignored
[\t ]*(?P<key>\w+)[\t ]*=[\t ]*
(?:
"(?P<double>[^"]*)"
| '(?P<single>[^']*)'
| `(?P<backtick>[^`]*)`
| (?!["'`])(?P<bare>[^\#\r\n]*?)
)
\s*(?:\#.*)? # comments can be added with the `#` symbol
(?=\n|$) # a key-value pairs are separated by new lines
[\t ]*(?:\#[^\r\n]*)?(?:\r?\n|$)
""",
flags=re.UNICODE | re.VERBOSE,
)
ignored_line = re.compile(r"[\t ]*(?:\#[^\r\n]*)?(?:\r?\n|$)")