|
@@ -140,6 +140,7 @@ public class SnuviParser
|
|
|
// -------------------------------------------------------------------------------
|
|
|
registerFunction("%", (args, sc) ->
|
|
|
new Fraction(getInt(args[0]) % getInt(args[1])));
|
|
|
+ registerAlias("math.mod", "%");
|
|
|
registerFunction("math.abs", (args, sc) ->
|
|
|
((Fraction) args[0]).abs());
|
|
|
registerFunction("math.pow", (args, sc) ->
|
|
@@ -213,9 +214,10 @@ public class SnuviParser
|
|
|
// arrays
|
|
|
// -------------------------------------------------------------------------------
|
|
|
registerConsumer("array.new", (args, sc) ->
|
|
|
- sc.setVar(args[0].toString(), new Object[ScriptUtils.getInt(args[1])]));
|
|
|
+ sc.setVar(args[0].toString(), new Object[ScriptUtils.getInt(args[1])]));
|
|
|
registerConsumer("array.=", (args, sc) ->
|
|
|
((Object[]) sc.getVar(args[0].toString()))[ScriptUtils.getInt(args[1])] = args[2]);
|
|
|
+ registerAlias("array.set", "array.=");
|
|
|
registerFunction("array.get", (args, sc) ->
|
|
|
((Object[]) sc.getVar(args[0].toString()))[ScriptUtils.getInt(args[1])]);
|
|
|
registerFunction("array.++", (args, sc) ->
|
|
@@ -272,6 +274,42 @@ public class SnuviParser
|
|
|
int i = ScriptUtils.getInt(args[1]);
|
|
|
o[i] = ((Fraction) o[i]).div((Fraction) args[2]);
|
|
|
});
|
|
|
+ registerConsumer("array.%=", (args, sc) ->
|
|
|
+ {
|
|
|
+ Object[] o = (Object[]) sc.getVar(args[0].toString());
|
|
|
+ int i = ScriptUtils.getInt(args[1]);
|
|
|
+ o[i] = ScriptUtils.getInt(o[i]) % ScriptUtils.getInt(args[2]);
|
|
|
+ });
|
|
|
+ registerConsumer("array.<<=", (args, sc) ->
|
|
|
+ {
|
|
|
+ Object[] o = (Object[]) sc.getVar(args[0].toString());
|
|
|
+ int i = ScriptUtils.getInt(args[1]);
|
|
|
+ o[i] = ((Fraction) o[i]).leftShift(ScriptUtils.getInt(args[2]));
|
|
|
+ });
|
|
|
+ registerConsumer("array.>>=", (args, sc) ->
|
|
|
+ {
|
|
|
+ Object[] o = (Object[]) sc.getVar(args[0].toString());
|
|
|
+ int i = ScriptUtils.getInt(args[1]);
|
|
|
+ o[i] = ((Fraction) o[i]).rightShift(ScriptUtils.getInt(args[2]));
|
|
|
+ });
|
|
|
+ registerConsumer("array.&=", (args, sc) ->
|
|
|
+ {
|
|
|
+ Object[] o = (Object[]) sc.getVar(args[0].toString());
|
|
|
+ int i = ScriptUtils.getInt(args[1]);
|
|
|
+ o[i] = ((Fraction) o[i]).and((Fraction) args[2]);
|
|
|
+ });
|
|
|
+ registerConsumer("array.^=", (args, sc) ->
|
|
|
+ {
|
|
|
+ Object[] o = (Object[]) sc.getVar(args[0].toString());
|
|
|
+ int i = ScriptUtils.getInt(args[1]);
|
|
|
+ o[i] = ((Fraction) o[i]).xor((Fraction) args[2]);
|
|
|
+ });
|
|
|
+ registerConsumer("array.|=", (args, sc) ->
|
|
|
+ {
|
|
|
+ Object[] o = (Object[]) sc.getVar(args[0].toString());
|
|
|
+ int i = ScriptUtils.getInt(args[1]);
|
|
|
+ o[i] = ((Fraction) o[i]).or((Fraction) args[2]);
|
|
|
+ });
|
|
|
registerFunction("array.getsize", (args, sc) ->
|
|
|
((Object[]) args[0]).length);
|
|
|
registerConsumer("array.swap", (args, sc) ->
|
|
@@ -448,7 +486,7 @@ public class SnuviParser
|
|
|
((File) args[0]).delete());
|
|
|
registerFunction("file.getname", (args, sc) ->
|
|
|
((File) args[0]).getName());
|
|
|
- registerFunction("file.", (args, sc) ->
|
|
|
+ registerFunction("file.rename", (args, sc) ->
|
|
|
((File) args[0]).renameTo(new File(args[1].toString())));
|
|
|
registerConsumer("file.getlist", (args, sc) ->
|
|
|
sc.setVar(args[0].toString(), Arrays.asList(((File) args[0]).listFiles())));
|
|
@@ -462,8 +500,10 @@ public class SnuviParser
|
|
|
// -------------------------------------------------------------------------------
|
|
|
registerFunction("+", (args, sc) ->
|
|
|
((Fraction) args[0]).add((Fraction) args[1]));
|
|
|
+ registerAlias("add", "+");
|
|
|
registerFunction("-", (args, sc) ->
|
|
|
((Fraction) args[0]).sub((Fraction) args[1]));
|
|
|
+ registerAlias("sub", "-");
|
|
|
registerConsumer("+=", (args, sc) ->
|
|
|
{
|
|
|
String s = args[0].toString();
|
|
@@ -484,6 +524,36 @@ public class SnuviParser
|
|
|
String s = args[0].toString();
|
|
|
sc.setVar(s, ((Fraction) sc.getVar(s)).div((Fraction) args[1]));
|
|
|
});
|
|
|
+ registerConsumer("%=", (args, sc) ->
|
|
|
+ {
|
|
|
+ String s = args[0].toString();
|
|
|
+ sc.setVar(s, ScriptUtils.getInt(sc.getVar(s)) % ScriptUtils.getInt(args[1]));
|
|
|
+ });
|
|
|
+ registerConsumer("<<=", (args, sc) ->
|
|
|
+ {
|
|
|
+ String s = args[0].toString();
|
|
|
+ sc.setVar(s, ((Fraction) sc.getVar(s)).leftShift(ScriptUtils.getInt(args[1])));
|
|
|
+ });
|
|
|
+ registerConsumer(">>=", (args, sc) ->
|
|
|
+ {
|
|
|
+ String s = args[0].toString();
|
|
|
+ sc.setVar(s, ((Fraction) sc.getVar(s)).rightShift(ScriptUtils.getInt(args[1])));
|
|
|
+ });
|
|
|
+ registerConsumer("&=", (args, sc) ->
|
|
|
+ {
|
|
|
+ String s = args[0].toString();
|
|
|
+ sc.setVar(s, ((Fraction) sc.getVar(s)).and((Fraction) args[1]));
|
|
|
+ });
|
|
|
+ registerConsumer("^=", (args, sc) ->
|
|
|
+ {
|
|
|
+ String s = args[0].toString();
|
|
|
+ sc.setVar(s, ((Fraction) sc.getVar(s)).xor((Fraction) args[1]));
|
|
|
+ });
|
|
|
+ registerConsumer("|=", (args, sc) ->
|
|
|
+ {
|
|
|
+ String s = args[0].toString();
|
|
|
+ sc.setVar(s, ((Fraction) sc.getVar(s)).or((Fraction) args[1]));
|
|
|
+ });
|
|
|
registerFunction("inc", (args, sc) ->
|
|
|
{
|
|
|
String s = args[0].toString();
|
|
@@ -500,26 +570,26 @@ public class SnuviParser
|
|
|
return n;
|
|
|
});
|
|
|
registerAlias("--", "dec");
|
|
|
- registerFunction("postinc", (args, sc) ->
|
|
|
+ registerFunction("p+", (args, sc) ->
|
|
|
{
|
|
|
String s = args[0].toString();
|
|
|
Fraction n = (Fraction) sc.getVar(s);
|
|
|
sc.setVar(s, n.add(new Fraction(1)));
|
|
|
return n;
|
|
|
});
|
|
|
- registerAlias("p+", "postinc");
|
|
|
- registerFunction("postdec", (args, sc) ->
|
|
|
+ registerFunction("p-", (args, sc) ->
|
|
|
{
|
|
|
String s = args[0].toString();
|
|
|
Fraction n = (Fraction) sc.getVar(s);
|
|
|
sc.setVar(s, n.add(new Fraction(-1)));
|
|
|
return n;
|
|
|
});
|
|
|
- registerAlias("p-", "postdec");
|
|
|
registerFunction("*", (args, sc) ->
|
|
|
((Fraction) args[0]).mul((Fraction) args[1]));
|
|
|
+ registerAlias("mul", "*");
|
|
|
registerFunction("/", (args, sc) ->
|
|
|
((Fraction) args[0]).div((Fraction) args[1]));
|
|
|
+ registerAlias("div", "/");
|
|
|
registerFunction("getvar", (args, sc) ->
|
|
|
sc.getVar(args[0].toString()));
|
|
|
registerConsumer("setvar", (args, sc) ->
|
|
@@ -586,22 +656,32 @@ public class SnuviParser
|
|
|
sc.jump());
|
|
|
registerFunction("==", (args, sc) ->
|
|
|
isEqual(args));
|
|
|
+ registerAlias("equal", "==");
|
|
|
+ registerAlias("equals", "==");
|
|
|
registerFunction("<", (args, sc) ->
|
|
|
((Fraction) args[0]).compareTo((Fraction) args[1]) < 0);
|
|
|
+ registerAlias("less", "<");
|
|
|
registerFunction(">", (args, sc) ->
|
|
|
((Fraction) args[0]).compareTo((Fraction) args[1]) > 0);
|
|
|
+ registerAlias("greater", ">");
|
|
|
registerFunction("!=", (args, sc) ->
|
|
|
!isEqual(args));
|
|
|
+ registerAlias("notequal", "!=");
|
|
|
registerFunction("<=", (args, sc) ->
|
|
|
((Fraction) args[0]).compareTo((Fraction) args[1]) <= 0);
|
|
|
+ registerAlias("lessequal", "<=");
|
|
|
registerFunction(">=", (args, sc) ->
|
|
|
((Fraction) args[0]).compareTo((Fraction) args[1]) >= 0);
|
|
|
+ registerAlias("greaterequal", ">=");
|
|
|
registerFunction("!", (args, sc) ->
|
|
|
!((boolean) args[0]));
|
|
|
+ registerAlias("invert", "!");
|
|
|
registerFunction("&&", (args, sc) ->
|
|
|
Arrays.stream(args).allMatch(s -> s.equals(true)));
|
|
|
+ registerAlias("and", "&&");
|
|
|
registerFunction("||", (args, sc) ->
|
|
|
Arrays.stream(args).anyMatch(s -> s.equals(true)));
|
|
|
+ registerAlias("or", "||");
|
|
|
registerConsumer("waitfor", (args, sc) ->
|
|
|
waitFor(args, sc));
|
|
|
registerConsumer("term", (args, sc) ->
|