diff options
| author | Jules Aguillon | 2025-02-27 23:53:42 +0100 |
|---|---|---|
| committer | Jules Aguillon | 2025-02-27 23:53:42 +0100 |
| commit | 466e0b82189352ee931916b22494f638fabc9aa3 (patch) | |
| tree | 8acfb89d4e53571cfa5c7b20f7cc1b6b6c9f5755 /srcs/juloo.keyboard2/KeyValueParser.java | |
| parent | 75fdc2bfa9cfe7ad5b743105c3679e2fdc3110e3 (diff) | |
| download | unexpected-keyboard-466e0b82189352ee931916b22494f638fabc9aa3.tar.gz unexpected-keyboard-466e0b82189352ee931916b22494f638fabc9aa3.zip | |
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.
Diffstat (limited to 'srcs/juloo.keyboard2/KeyValueParser.java')
| -rw-r--r-- | srcs/juloo.keyboard2/KeyValueParser.java | 10 |
1 files changed, 6 insertions, 4 deletions
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<KeyValue> keydefs = new ArrayList<KeyValue>(); 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<KeyValue> keydefs = new ArrayList<KeyValue>(); + 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); } |
