summaryrefslogtreecommitdiff
path: root/lib/python
diff options
context:
space:
mode:
authorErovia <erovia@users.noreply.github.com>2019-10-14 18:35:12 +0200
committerskullydazed <skullydazed@users.noreply.github.com>2020-02-15 15:19:03 -0800
commitd257a98cb80a90f116072c882753039b10a5e042 (patch)
treec6635d64ad97562998e863a8a3c19e3958e54123 /lib/python
parentf8002828cac83272e5804bf705e20d07ac64e7a0 (diff)
Fix regex for parsing rules.mk files
I don't know why it couldn't put it together before... ¯\_(ツ)_/¯
Diffstat (limited to 'lib/python')
-rw-r--r--lib/python/qmk/makefile.py11
1 files changed, 3 insertions, 8 deletions
diff --git a/lib/python/qmk/makefile.py b/lib/python/qmk/makefile.py
index ce64431f96..dc498adc8f 100644
--- a/lib/python/qmk/makefile.py
+++ b/lib/python/qmk/makefile.py
@@ -16,20 +16,15 @@ def parse_rules_mk(file_path):
Returns:
a dictionary with the file's content
"""
- # regex to match lines with comment at the end
+ # regex to match lines uncommented lines and get the data
# group(1) = option's name
# group(2) = operator (eg.: '=', '+=')
# group(3) = value(s)
- commented_regex = re.compile(r"^\s*(\w+)\s*([\:\+\-]?=)\s*(.*?)(?=\s*\#)")
- # regex to match lines without comment at the end
- # group(1) = option's name
- # group(2) = operator (eg.: '=', '+=')
- # group(3) = value(s)
- uncommented_regex = re.compile(r"^\s*(\w+)\s*([\:\+\-]?=)\s*(.*?)(?=\s*$)")
+ rules_mk_regex = re.compile(r"^\s*(\w+)\s*([\?\:\+\-]?=)\s*(\S.*?)(?=\s*(\#|$))")
mk_content = qmk.path.unicode_lines(file_path)
parsed_file = dict()
for line in mk_content:
- found = commented_regex.search(line) if "#" in line else uncommented_regex.search(line)
+ found = rules_mk_regex.search(line)
if found:
parsed_file[found.group(1)] = dict(operator = found.group(2), value = found.group(3))
return parsed_file