diff options
Diffstat (limited to 'lib/python/qmk/c_parse.py')
-rw-r--r-- | lib/python/qmk/c_parse.py | 26 |
1 files changed, 20 insertions, 6 deletions
diff --git a/lib/python/qmk/c_parse.py b/lib/python/qmk/c_parse.py index e41e271a4..67e196f0e 100644 --- a/lib/python/qmk/c_parse.py +++ b/lib/python/qmk/c_parse.py | |||
@@ -1,12 +1,27 @@ | |||
1 | """Functions for working with config.h files. | 1 | """Functions for working with config.h files. |
2 | """ | 2 | """ |
3 | from pathlib import Path | 3 | from pathlib import Path |
4 | import re | ||
4 | 5 | ||
5 | from milc import cli | 6 | from milc import cli |
6 | 7 | ||
7 | from qmk.comment_remover import comment_remover | 8 | from qmk.comment_remover import comment_remover |
8 | 9 | ||
9 | default_key_entry = {'x': -1, 'y': 0, 'w': 1} | 10 | default_key_entry = {'x': -1, 'y': 0, 'w': 1} |
11 | single_comment_regex = re.compile(r' */[/*].*$') | ||
12 | multi_comment_regex = re.compile(r'/\*(.|\n)*\*/', re.MULTILINE) | ||
13 | |||
14 | |||
15 | def strip_line_comment(string): | ||
16 | """Removes comments from a single line string. | ||
17 | """ | ||
18 | return single_comment_regex.sub('', string) | ||
19 | |||
20 | |||
21 | def strip_multiline_comment(string): | ||
22 | """Removes comments from a single line string. | ||
23 | """ | ||
24 | return multi_comment_regex.sub('', string) | ||
10 | 25 | ||
11 | 26 | ||
12 | def c_source_files(dir_names): | 27 | def c_source_files(dir_names): |
@@ -53,7 +68,8 @@ def find_layouts(file): | |||
53 | parsed_layout = [_default_key(key) for key in layout.split(',')] | 68 | parsed_layout = [_default_key(key) for key in layout.split(',')] |
54 | 69 | ||
55 | for key in parsed_layout: | 70 | for key in parsed_layout: |
56 | key['matrix'] = matrix_locations.get(key['label']) | 71 | if key['label'] in matrix_locations: |
72 | key['matrix'] = matrix_locations[key['label']] | ||
57 | 73 | ||
58 | parsed_layouts[macro_name] = { | 74 | parsed_layouts[macro_name] = { |
59 | 'key_count': len(parsed_layout), | 75 | 'key_count': len(parsed_layout), |
@@ -88,12 +104,10 @@ def parse_config_h_file(config_h_file, config_h=None): | |||
88 | if config_h_file.exists(): | 104 | if config_h_file.exists(): |
89 | config_h_text = config_h_file.read_text() | 105 | config_h_text = config_h_file.read_text() |
90 | config_h_text = config_h_text.replace('\\\n', '') | 106 | config_h_text = config_h_text.replace('\\\n', '') |
107 | config_h_text = strip_multiline_comment(config_h_text) | ||
91 | 108 | ||
92 | for linenum, line in enumerate(config_h_text.split('\n')): | 109 | for linenum, line in enumerate(config_h_text.split('\n')): |
93 | line = line.strip() | 110 | line = strip_line_comment(line).strip() |
94 | |||
95 | if '//' in line: | ||
96 | line = line[:line.index('//')].strip() | ||
97 | 111 | ||
98 | if not line: | 112 | if not line: |
99 | continue | 113 | continue |
@@ -156,6 +170,6 @@ def _parse_matrix_locations(matrix, file, macro_name): | |||
156 | row = row.replace('{', '').replace('}', '') | 170 | row = row.replace('{', '').replace('}', '') |
157 | for col_num, identifier in enumerate(row.split(',')): | 171 | for col_num, identifier in enumerate(row.split(',')): |
158 | if identifier != 'KC_NO': | 172 | if identifier != 'KC_NO': |
159 | matrix_locations[identifier] = (row_num, col_num) | 173 | matrix_locations[identifier] = [row_num, col_num] |
160 | 174 | ||
161 | return matrix_locations | 175 | return matrix_locations |