From 466e0b82189352ee931916b22494f638fabc9aa3 Mon Sep 17 00:00:00 2001 From: Jules Aguillon Date: Thu, 27 Feb 2025 23:53:42 +0100 Subject: KeyValue: Don't wrap keys into a macro when possible Many kind of KeyValues don't need to be wrapped into a Macro to show a specific symbol. This is especially useful as Macro keys are not affected by modifiers. The parser is changed to have a fast-path when a key value is not a macro. --- srcs/juloo.keyboard2/KeyValueParser.java | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'srcs/juloo.keyboard2/KeyValueParser.java') diff --git a/srcs/juloo.keyboard2/KeyValueParser.java b/srcs/juloo.keyboard2/KeyValueParser.java index 488f5d3..92d1ee5 100644 --- a/srcs/juloo.keyboard2/KeyValueParser.java +++ b/srcs/juloo.keyboard2/KeyValueParser.java @@ -41,15 +41,17 @@ public final class KeyValueParser if (symbol_ends == input_len) // String key return KeyValue.makeStringKey(input); String symbol = input.substring(0, symbol_ends); - ArrayList keydefs = new ArrayList(); init(); Matcher m = KEYDEF_TOKEN.matcher(input); m.region(symbol_ends + 1, input_len); + KeyValue first_key = parse_key_def(m); + if (!parse_comma(m)) // Input is a single key def with a specified symbol + return first_key.withSymbol(symbol); + // Input is a macro + ArrayList keydefs = new ArrayList(); + keydefs.add(first_key); do { keydefs.add(parse_key_def(m)); } while (parse_comma(m)); - for (KeyValue k : keydefs) - if (k == null) - parseError("Contains null key", m); return KeyValue.makeMacro(symbol, keydefs.toArray(new KeyValue[]{}), 0); } -- cgit v1.2.3