diff options
| -rw-r--r-- | srcs/juloo.keyboard2/KeyValue.java | 31 | ||||
| -rw-r--r-- | srcs/juloo.keyboard2/KeyValueParser.java | 10 | ||||
| -rw-r--r-- | test/juloo.keyboard2/KeyValueParserTest.java | 11 |
3 files changed, 41 insertions, 11 deletions
diff --git a/srcs/juloo.keyboard2/KeyValue.java b/srcs/juloo.keyboard2/KeyValue.java index b2ef5db..7cad9eb 100644 --- a/srcs/juloo.keyboard2/KeyValue.java +++ b/srcs/juloo.keyboard2/KeyValue.java @@ -250,7 +250,26 @@ public final class KeyValue implements Comparable<KeyValue> public KeyValue withFlags(int f) { - return new KeyValue(_payload, (_code & KIND_BITS), (_code & VALUE_BITS), f); + return new KeyValue(_payload, (_code & ~FLAGS_BITS) | (f & FLAGS_BITS)); + } + + public KeyValue withSymbol(String symbol) + { + switch (getKind()) + { + case Char: + case Keyevent: + case Event: + case Compose_pending: + case Hangul_initial: + case Hangul_medial: + case Modifier: + case Editing: + case Placeholder: + return new KeyValue(symbol, _code); + default: + return makeMacro(symbol, new KeyValue[]{ this }, 0); + } } @Override @@ -294,13 +313,17 @@ public final class KeyValue implements Comparable<KeyValue> return "[KeyValue " + getKind().toString() + "+" + getFlags() + "+" + value + " \"" + getString() + "\"]"; } - /** [value] is an unsigned integer. */ - private KeyValue(Comparable p, int kind, int value, int flags) + private KeyValue(Comparable p, int code) { if (p == null) throw new NullPointerException("KeyValue payload cannot be null"); _payload = p; - _code = (kind & KIND_BITS) | (flags & FLAGS_BITS) | (value & VALUE_BITS); + _code = code; + } + + private KeyValue(Comparable p, int kind, int value, int flags) + { + this(p, (kind & KIND_BITS) | (flags & FLAGS_BITS) | (value & VALUE_BITS)); } public KeyValue(Comparable p, Kind k, int v, int f) 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); } diff --git a/test/juloo.keyboard2/KeyValueParserTest.java b/test/juloo.keyboard2/KeyValueParserTest.java index a041e8a..7ece1a7 100644 --- a/test/juloo.keyboard2/KeyValueParserTest.java +++ b/test/juloo.keyboard2/KeyValueParserTest.java @@ -55,6 +55,13 @@ public class KeyValueParserTest } @Test + /* Using the [symbol:..] syntax but not resulting in a macro. */ + public void parse_non_macro() throws Exception + { + Utils.parse("a:b", KeyValue.makeCharKey('b', "a", 0)); + } + + @Test public void parse_string_key() throws Exception { Utils.parse("symbol:'str'", KeyValue.makeMacro("symbol", new KeyValue[]{ @@ -87,9 +94,7 @@ public class KeyValueParserTest @Test public void parse_key_event() throws Exception { - Utils.parse("symbol:keyevent:85", KeyValue.makeMacro("symbol", new KeyValue[]{ - KeyValue.keyeventKey("", 85, 0) - }, 0)); + Utils.parse("symbol:keyevent:85", KeyValue.keyeventKey("symbol", 85, 0)); Utils.parse("macro:keyevent:85,abc", KeyValue.makeMacro("macro", new KeyValue[]{ KeyValue.keyeventKey("", 85, 0), KeyValue.makeStringKey("abc") |
