aboutsummaryrefslogtreecommitdiff
path: root/lib/python/qmk/c_parse.py
diff options
context:
space:
mode:
Diffstat (limited to 'lib/python/qmk/c_parse.py')
-rw-r--r--lib/python/qmk/c_parse.py26
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"""
3from pathlib import Path 3from pathlib import Path
4import re
4 5
5from milc import cli 6from milc import cli
6 7
7from qmk.comment_remover import comment_remover 8from qmk.comment_remover import comment_remover
8 9
9default_key_entry = {'x': -1, 'y': 0, 'w': 1} 10default_key_entry = {'x': -1, 'y': 0, 'w': 1}
11single_comment_regex = re.compile(r' */[/*].*$')
12multi_comment_regex = re.compile(r'/\*(.|\n)*\*/', re.MULTILINE)
13
14
15def strip_line_comment(string):
16 """Removes comments from a single line string.
17 """
18 return single_comment_regex.sub('', string)
19
20
21def strip_multiline_comment(string):
22 """Removes comments from a single line string.
23 """
24 return multi_comment_regex.sub('', string)
10 25
11 26
12def c_source_files(dir_names): 27def 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