summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/python/qmk/c_parse.py21
-rw-r--r--lib/python/qmk/cli/generate/keycodes.py2
2 files changed, 16 insertions, 7 deletions
diff --git a/lib/python/qmk/c_parse.py b/lib/python/qmk/c_parse.py
index 83ab1d1e6d..501c41972f 100644
--- a/lib/python/qmk/c_parse.py
+++ b/lib/python/qmk/c_parse.py
@@ -213,10 +213,13 @@ def _coerce_led_token(_type, value):
return value_map[value]
-def _validate_led_config(matrix, matrix_rows, matrix_indexes, position, position_raw, flags):
+def _validate_led_config(matrix, matrix_rows, matrix_cols, matrix_indexes, position, position_raw, flags):
# TODO: Improve crude parsing/validation
if len(matrix) != matrix_rows and len(matrix) != (matrix_rows / 2):
raise ValueError("Unable to parse g_led_config matrix data")
+ for index, row in enumerate(matrix):
+ if len(row) != matrix_cols:
+ raise ValueError(f"Number of columns in row {index} ({len(row)}) does not match matrix ({matrix_cols})")
if len(position) != len(flags):
raise ValueError(f"Number of g_led_config physical positions ({len(position)}) does not match number of flags ({len(flags)})")
if len(matrix_indexes) and (max(matrix_indexes) >= len(flags)):
@@ -230,13 +233,16 @@ def _validate_led_config(matrix, matrix_rows, matrix_indexes, position, position
def _parse_led_config(file, matrix_cols, matrix_rows):
"""Return any 'raw' led/rgb matrix config
"""
- matrix_raw = []
+ matrix = []
position_raw = []
flags = []
found_led_config = False
bracket_count = 0
section = 0
+ current_row_index = 0
+ current_row = []
+
for _type, value in lex(_preprocess_c_file(file), CLexer()):
# Assume g_led_config..stuff..;
if value == 'g_led_config':
@@ -250,12 +256,16 @@ def _parse_led_config(file, matrix_cols, matrix_rows):
if bracket_count == 2:
section += 1
elif value == '}':
+ if section == 1 and bracket_count == 3:
+ matrix.append(current_row)
+ current_row = []
+ current_row_index += 1
bracket_count -= 1
else:
# Assume any non whitespace value here is important enough to stash
if _type in [Token.Literal.Number.Integer, Token.Literal.Number.Float, Token.Literal.Number.Hex, Token.Name]:
if section == 1 and bracket_count == 3:
- matrix_raw.append(_coerce_led_token(_type, value))
+ current_row.append(_coerce_led_token(_type, value))
if section == 2 and bracket_count == 3:
position_raw.append(_coerce_led_token(_type, value))
if section == 3 and bracket_count == 2:
@@ -265,16 +275,15 @@ def _parse_led_config(file, matrix_cols, matrix_rows):
return None
# Slightly better intrim format
- matrix = list(_get_chunks(matrix_raw, matrix_cols))
position = list(_get_chunks(position_raw, 2))
- matrix_indexes = list(filter(lambda x: x is not None, matrix_raw))
+ matrix_indexes = list(filter(lambda x: x is not None, sum(matrix, [])))
# If we have not found anything - bail with no error
if not section:
return None
# Throw any validation errors
- _validate_led_config(matrix, matrix_rows, matrix_indexes, position, position_raw, flags)
+ _validate_led_config(matrix, matrix_rows, matrix_cols, matrix_indexes, position, position_raw, flags)
return (matrix, position, flags)
diff --git a/lib/python/qmk/cli/generate/keycodes.py b/lib/python/qmk/cli/generate/keycodes.py
index 17503bac63..3b69b17ed1 100644
--- a/lib/python/qmk/cli/generate/keycodes.py
+++ b/lib/python/qmk/cli/generate/keycodes.py
@@ -143,7 +143,7 @@ def generate_keycode_extras(cli):
"""
# Build the header file.
- keycodes_h_lines = [GPL2_HEADER_C_LIKE, GENERATED_HEADER_C_LIKE, '#pragma once', '#include "keymap.h"', '// clang-format off']
+ keycodes_h_lines = [GPL2_HEADER_C_LIKE, GENERATED_HEADER_C_LIKE, '#pragma once', '#include "keycodes.h"', '// clang-format off']
keycodes = load_spec(cli.args.version, cli.args.lang)