From 71e1acf2ea02b4ee29e80a12d41a486da7ac70f8 Mon Sep 17 00:00:00 2001 From: nirenjan Date: Wed, 14 Oct 2026 08:52:43 -0700 Subject: [PATCH] fix: Rework layout compiler to avoid backtracking This change swaps out the Unicode lines to use a mix of whitespace and non-whitespace characters so that it avoids backtracking. The name and description lines no longer use regexes, but simple string splitting and comparision, as a regex is overkill in this scenario. --- tools/x52compile_layout.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/tools/x52compile_layout.py b/tools/x52compile_layout.py index 26b5daa..e5223ab 100755 --- a/tools/x52compile_layout.py +++ b/tools/x52compile_layout.py @@ -212,9 +212,9 @@ def parse_chord( return mod & 0xFF, usage & 0xFF -_U_LINE = re.compile(r"^[Uu]\+([0-9A-Fa-f]{1,6})\s+(.+)$") -_META_NAME = re.compile(r"(?i)^name:\s*(.*)$") -_META_DESC = re.compile(r"(?i)^description:\s*(.*)$") +_U_LINE = re.compile(r"^[Uu]\+([0-9A-Fa-f]{1,6})\s+(\S+)$") +_META_NAME = 'name:' +_META_DESC = 'description:' def _parse_layout_source( @@ -229,13 +229,13 @@ def _parse_layout_source( stripped = line.strip() if not stripped or stripped.startswith("#"): continue - mn = _META_NAME.match(stripped) - if mn: - name = mn.group(1).strip() + + key, data = stripped.split(maxsplit=1) + if key == _META_NAME: + name = data continue - md = _META_DESC.match(stripped) - if md: - description = md.group(1).strip() + if key == _META_DESC: + description = data continue cp, chord = _parse_mapping_line(path, lineno, stripped) raw_maps.append((cp, lineno, chord))