mirror of
https://github.com/Julow/Unexpected-Keyboard.git
synced 2025-06-27 13:12:02 +02:00
Revert the old syntax parser to before macros
The macro syntax in the old parser is not needed.
This commit is contained in:
parent
8d90e3c4d2
commit
47d7250b90
@ -141,51 +141,18 @@ public final class KeyValueParser
|
||||
static Pattern QUOTED_PAT;
|
||||
static Pattern PAYLOAD_START_PAT;
|
||||
static Pattern WORD_PAT;
|
||||
static Pattern COMMA_PAT;
|
||||
static Pattern END_OF_INPUT_PAT;
|
||||
|
||||
static public KeyValue parse(String str) throws ParseError
|
||||
{
|
||||
init();
|
||||
Matcher m = START_PAT.matcher(str);
|
||||
KeyValue k = parseKeyValue(m);
|
||||
if (!match(m, END_OF_INPUT_PAT))
|
||||
parseError("Unexpected character", m);
|
||||
return k;
|
||||
}
|
||||
|
||||
static void init()
|
||||
{
|
||||
if (START_PAT != null)
|
||||
return;
|
||||
START_PAT = Pattern.compile(":(\\w+)");
|
||||
ATTR_PAT = Pattern.compile("\\s*(\\w+)\\s*=");
|
||||
QUOTED_PAT = Pattern.compile("'(([^'\\\\]+|\\\\')*)'");
|
||||
PAYLOAD_START_PAT = Pattern.compile("\\s*:");
|
||||
WORD_PAT = Pattern.compile("[a-zA-Z0-9_]+|.");
|
||||
COMMA_PAT = Pattern.compile(",");
|
||||
END_OF_INPUT_PAT = Pattern.compile("$");
|
||||
}
|
||||
|
||||
static KeyValue parseKeyValue(Matcher m) throws ParseError
|
||||
{
|
||||
if (match(m, START_PAT))
|
||||
return parseComplexKeyValue(m, m.group(1));
|
||||
// Key doesn't start with ':', accept either a char key or a key name.
|
||||
if (!match(m, WORD_PAT))
|
||||
parseError("Expected key, for example \":str ...\".", m);
|
||||
String key = m.group(0);
|
||||
KeyValue k = KeyValue.getSpecialKeyByName(key);
|
||||
if (k == null)
|
||||
return KeyValue.makeStringKey(key);
|
||||
return k;
|
||||
}
|
||||
|
||||
static KeyValue parseComplexKeyValue(Matcher m, String kind) throws ParseError
|
||||
{
|
||||
// Attributes
|
||||
String symbol = null;
|
||||
int flags = 0;
|
||||
init();
|
||||
// Kind
|
||||
Matcher m = START_PAT.matcher(str);
|
||||
if (!m.lookingAt())
|
||||
parseError("Expected kind, for example \":str ...\".", m);
|
||||
String kind = m.group(1);
|
||||
// Attributes
|
||||
while (true)
|
||||
{
|
||||
if (!match(m, ATTR_PAT))
|
||||
@ -233,14 +200,6 @@ public final class KeyValueParser
|
||||
symbol = String.valueOf(eventcode);
|
||||
return KeyValue.keyeventKey(symbol, eventcode, flags);
|
||||
|
||||
case "macro":
|
||||
// :macro symbol='copy':ctrl,a,ctrl,c
|
||||
// :macro symbol='acute':compose,'
|
||||
KeyValue[] macro = parseKeyValueList(m);
|
||||
if (symbol == null)
|
||||
symbol = "macro";
|
||||
return KeyValue.makeMacro(symbol, macro, flags);
|
||||
|
||||
default: break;
|
||||
}
|
||||
parseError("Unknown kind '"+kind+"'", m, 1);
|
||||
@ -276,14 +235,22 @@ public final class KeyValueParser
|
||||
return flags;
|
||||
}
|
||||
|
||||
// Parse keys separated by comas
|
||||
static KeyValue[] parseKeyValueList(Matcher m) throws ParseError
|
||||
static boolean match(Matcher m, Pattern pat)
|
||||
{
|
||||
ArrayList<KeyValue> out = new ArrayList<KeyValue>();
|
||||
out.add(parseKeyValue(m));
|
||||
while (match(m, COMMA_PAT))
|
||||
out.add(parseKeyValue(m));
|
||||
return out.toArray(new KeyValue[]{});
|
||||
try { m.region(m.end(), m.regionEnd()); } catch (Exception _e) {}
|
||||
m.usePattern(pat);
|
||||
return m.lookingAt();
|
||||
}
|
||||
|
||||
static void init()
|
||||
{
|
||||
if (START_PAT != null)
|
||||
return;
|
||||
START_PAT = Pattern.compile(":(\\w+)");
|
||||
ATTR_PAT = Pattern.compile("\\s*(\\w+)\\s*=");
|
||||
QUOTED_PAT = Pattern.compile("'(([^'\\\\]+|\\\\')*)'");
|
||||
PAYLOAD_START_PAT = Pattern.compile("\\s*:");
|
||||
WORD_PAT = Pattern.compile("[a-zA-Z0-9_]*");
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user