dont be lazy refactor
This commit is contained in:
1 parent
a65d16c9ba
commit
74bd0bb81e
31 files changed
+1078
-1383
No files matched your search
@@ -95,6 +95,7 @@ public class DataStructures {
|
||||
return ListValue.wrap(toSort);
|
||||
});
|
||||
|
||||
// needs lazy cause sort function is reused
|
||||
expression.addLazyFunction("sort_key", -1, (c, t, lv) -> //get working with iterators
|
||||
{
|
||||
if (lv.size() == 0)
|
||||
@@ -121,7 +122,8 @@ public class DataStructures {
|
||||
});
|
||||
//revering scope
|
||||
c.setVariable("_", __);
|
||||
return (cc, tt) -> ListValue.wrap(toSort);
|
||||
Value ret = ListValue.wrap(toSort);
|
||||
return (cc, tt) -> ret;
|
||||
});
|
||||
|
||||
expression.addFunction("range", (lv) ->
|
||||
@@ -147,18 +149,14 @@ public class DataStructures {
|
||||
: LazyListValue.rangeDouble(from.getDouble(), to.getDouble(), step.getDouble());
|
||||
});
|
||||
|
||||
expression.addLazyFunction("m", -1, (c, t, llv) ->
|
||||
expression.addTypedContextFunction("m", -1, Context.MAPDEF, (c, t, lv) ->
|
||||
{
|
||||
List<Value> lv = new ArrayList<>();
|
||||
for (LazyValue lazyParam : llv) {
|
||||
lv.add(lazyParam.evalValue(c, Context.MAPDEF)); // none type default by design
|
||||
}
|
||||
Value ret;
|
||||
if (lv.size() == 1 && lv.get(0) instanceof LazyListValue)
|
||||
ret = new MapValue(((LazyListValue) lv.get(0)).unroll());
|
||||
else
|
||||
ret = new MapValue(lv);
|
||||
return (cc, tt) -> ret;
|
||||
return ret;
|
||||
});
|
||||
|
||||
expression.addUnaryFunction("keys", v ->
|
||||
@@ -184,41 +182,23 @@ public class DataStructures {
|
||||
return Value.NULL;
|
||||
});
|
||||
|
||||
expression.addLazyBinaryOperator(":", Operators.precedence.get("attribute~:"),true, (c, t, container_lv, key_lv) ->
|
||||
expression.addBinaryContextOperator(":", Operators.precedence.get("attribute~:"),true, (c, t, container, address) ->
|
||||
{
|
||||
Value container = container_lv.evalValue(c);
|
||||
if (container instanceof LContainerValue)
|
||||
{
|
||||
ContainerValueInterface outerContainer = ((LContainerValue) container).getContainer();
|
||||
if (outerContainer == null)
|
||||
{
|
||||
Value innerLValue = new LContainerValue(null, null);
|
||||
return (cc, tt) -> innerLValue;
|
||||
}
|
||||
if (outerContainer == null) return LContainerValue.NULL_CONTAINER;
|
||||
Value innerContainer = outerContainer.get(((LContainerValue) container).getAddress());
|
||||
if (!(innerContainer instanceof ContainerValueInterface))
|
||||
{
|
||||
Value innerLValue = new LContainerValue(null, null);
|
||||
return (cc, tt) -> innerLValue;
|
||||
}
|
||||
Value innerLValue = new LContainerValue((ContainerValueInterface) innerContainer, key_lv.evalValue(c));
|
||||
return (cc, tt) -> innerLValue;
|
||||
if (!(innerContainer instanceof ContainerValueInterface)) return LContainerValue.NULL_CONTAINER;
|
||||
return new LContainerValue((ContainerValueInterface) innerContainer, address);
|
||||
}
|
||||
if (!(container instanceof ContainerValueInterface))
|
||||
if (t == Context.LVALUE)
|
||||
return (cc, tt) -> new LContainerValue(null, null);
|
||||
else
|
||||
return (cc, tt) -> Value.NULL;
|
||||
Value address = key_lv.evalValue(c);
|
||||
if (t != Context.LVALUE)
|
||||
{
|
||||
Value retVal = ((ContainerValueInterface) container).get(address);
|
||||
return (cc, ct) -> retVal;
|
||||
}
|
||||
Value retVal = new LContainerValue((ContainerValueInterface) container, address);
|
||||
return (cc, ct) -> retVal;
|
||||
return t == Context.LVALUE ? LContainerValue.NULL_CONTAINER : Value.NULL;
|
||||
if (t != Context.LVALUE) return ((ContainerValueInterface) container).get(address);
|
||||
return new LContainerValue((ContainerValueInterface) container, address);
|
||||
});
|
||||
|
||||
// lazy cause conditional typing - questionable
|
||||
expression.addLazyFunction("get", -1, (c, t, lv) ->
|
||||
{
|
||||
if (lv.size() == 0)
|
||||
@@ -227,10 +207,10 @@ public class DataStructures {
|
||||
{
|
||||
Value v = lv.get(0).evalValue(c, Context.LVALUE);
|
||||
if (!(v instanceof LContainerValue))
|
||||
return (cc, tt) -> Value.NULL;
|
||||
return LazyValue.NULL;
|
||||
ContainerValueInterface container = ((LContainerValue) v).getContainer();
|
||||
if (container == null)
|
||||
return (cc, tt) -> Value.NULL;
|
||||
return LazyValue.NULL;
|
||||
Value ret = container.get(((LContainerValue) v).getAddress());
|
||||
return (cc, tt) -> ret;
|
||||
}
|
||||
@@ -246,6 +226,7 @@ public class DataStructures {
|
||||
return (cc, tt) -> finalContainer;
|
||||
});
|
||||
|
||||
// same as `get`
|
||||
expression.addLazyFunction("has", -1, (c, t, lv) ->
|
||||
{
|
||||
if (lv.size() == 0)
|
||||
@@ -254,25 +235,26 @@ public class DataStructures {
|
||||
{
|
||||
Value v = lv.get(0).evalValue(c, Context.LVALUE);
|
||||
if (!(v instanceof LContainerValue))
|
||||
return (cc, tt) -> Value.NULL;
|
||||
return LazyValue.NULL;
|
||||
ContainerValueInterface container = ((LContainerValue) v).getContainer();
|
||||
if (container == null)
|
||||
return (cc, tt) -> Value.NULL;
|
||||
return LazyValue.NULL;
|
||||
Value ret = new NumericValue(container.has(((LContainerValue) v).getAddress()));
|
||||
return (cc, tt) -> ret;
|
||||
}
|
||||
Value container = lv.get(0).evalValue(c);
|
||||
for (int i = 1; i < lv.size()-1; i++)
|
||||
{
|
||||
if (!(container instanceof ContainerValueInterface)) return (cc, tt) -> Value.NULL;
|
||||
if (!(container instanceof ContainerValueInterface)) return LazyValue.NULL;
|
||||
container = ((ContainerValueInterface) container).get(lv.get(i).evalValue(c));
|
||||
}
|
||||
if (!(container instanceof ContainerValueInterface))
|
||||
return (cc, tt) -> Value.NULL;
|
||||
return LazyValue.NULL;
|
||||
Value ret = new NumericValue(((ContainerValueInterface) container).has(lv.get(lv.size()-1).evalValue(c)));
|
||||
return (cc, tt) -> ret;
|
||||
});
|
||||
|
||||
// same as `get`
|
||||
expression.addLazyFunction("put", -1, (c, t, lv) ->
|
||||
{
|
||||
if(lv.size()<2)
|
||||
@@ -285,7 +267,7 @@ public class DataStructures {
|
||||
ContainerValueInterface internalContainer = ((LContainerValue) container).getContainer();
|
||||
if (internalContainer == null)
|
||||
{
|
||||
return (cc, tt) -> Value.NULL;
|
||||
return LazyValue.NULL;
|
||||
}
|
||||
Value address = ((LContainerValue) container).getAddress();
|
||||
Value what = lv.get(1).evalValue(c);
|
||||
@@ -301,7 +283,7 @@ public class DataStructures {
|
||||
}
|
||||
if (!(container instanceof ContainerValueInterface))
|
||||
{
|
||||
return (cc, tt) -> Value.NULL;
|
||||
return LazyValue.NULL;
|
||||
}
|
||||
Value where = lv.get(1).evalValue(c);
|
||||
Value what = lv.get(2).evalValue(c);
|
||||
@@ -311,6 +293,7 @@ public class DataStructures {
|
||||
return (cc, tt) -> retVal;
|
||||
});
|
||||
|
||||
// same as `get`
|
||||
expression.addLazyFunction("delete", -1, (c, t, lv) ->
|
||||
{
|
||||
if (lv.size() == 0)
|
||||
@@ -319,21 +302,21 @@ public class DataStructures {
|
||||
{
|
||||
Value v = lv.get(0).evalValue(c, Context.LVALUE);
|
||||
if (!(v instanceof LContainerValue))
|
||||
return (cc, tt) -> Value.NULL;
|
||||
return LazyValue.NULL;
|
||||
ContainerValueInterface container = ((LContainerValue) v).getContainer();
|
||||
if (container == null)
|
||||
return (cc, tt) -> Value.NULL;
|
||||
return LazyValue.NULL;
|
||||
Value ret = new NumericValue(container.delete(((LContainerValue) v).getAddress()));
|
||||
return (cc, tt) -> ret;
|
||||
}
|
||||
Value container = lv.get(0).evalValue(c);
|
||||
for (int i = 1; i < lv.size()-1; i++)
|
||||
{
|
||||
if (!(container instanceof ContainerValueInterface)) return (cc, tt) -> Value.NULL;
|
||||
if (!(container instanceof ContainerValueInterface)) return LazyValue.NULL;
|
||||
container = ((ContainerValueInterface) container).get(lv.get(i).evalValue(c));
|
||||
}
|
||||
if (!(container instanceof ContainerValueInterface))
|
||||
return (cc, tt) -> Value.NULL;
|
||||
return LazyValue.NULL;
|
||||
Value ret = new NumericValue(((ContainerValueInterface) container).delete(lv.get(lv.size()-1).evalValue(c)));
|
||||
return (cc, tt) -> ret;
|
||||
});
|
||||
|
||||
Reference in new issue
Block a user