From d59a4ba4597bfeb50f6b135bb3ec594cbee2da67 Mon Sep 17 00:00:00 2001
From: gnembon
~ .~ :+ - !^* / %( )Get, Accessor Operator .Get, Accessor Operator :Operator version of the get(...) function to access elements of lists, maps, and potentially other
* containers (i.e. NBTs). It is important to distinguish from ~ operator, which is a matching operator,
* which is expected to perform some extra computations to retrieve the result, while . should be
@@ -1096,7 +1095,7 @@ public class Expression implements Cloneable
* API, meaning get(...), put(...), delete(...),
* and has(...) functions
WARNING: Unlike for some languages, where item access operator can be an L-value, to assign new values to
- * container elements, use put function instead, i.e. a.1='foo' won't work.
put function instead, i.e. a:1='foo' won't work.
*
* Matching Operator ~This operator should be understood as 'matches', 'contains', 'is_in', @@ -1244,9 +1243,19 @@ public class Expression implements Cloneable */ public void Operators() { - addLazyBinaryOperator(".", precedence.get("attribute~."),true, (c, t, container_lv, key_lv) -> + addLazyBinaryOperator(":", precedence.get("attribute~:"),true, (c, t, container_lv, key_lv) -> { Value container = container_lv.evalValue(c); + if (container instanceof LContainerValue) + { + ContainerValueInterface outerContainer = ((LContainerValue) container).getContainer(); + Value outerAddress = ((LContainerValue) container).getAddress(); + Value innerContainer = outerContainer.get(outerAddress); + if (!(innerContainer instanceof ContainerValueInterface)) + throw new InternalExpressionException("Cannot access elements of a non-container"); + Value innerLValue = new LContainerValue((ContainerValueInterface) innerContainer, key_lv.evalValue(c)); + return (cc, tt) -> innerLValue; + } if (!(container instanceof ContainerValueInterface)) throw new InternalExpressionException("Cannot access elements of a non-container"); Value address = key_lv.evalValue(c); @@ -2023,7 +2032,7 @@ public class Expression implements Cloneable *
Here is a list of operations that work on all types of containers: lists, maps, as well as other Minecraft * specific modifyable containers, like NBTs
* - *get(container, address), '.' operatorget(container, address), ':' operatorReturns the value at address element from the value.
* For lists it indicates an index, use negative numbers to reach elements from the end of the list. get
* call will always be able to find the index. In case there is few items, it will loop over