From d59a4ba4597bfeb50f6b135bb3ec594cbee2da67 Mon Sep 17 00:00:00 2001 From: gnembon Date: Sat, 12 Oct 2019 00:41:07 -0300 Subject: [PATCH] changed to ':' --- src/main/java/carpet/script/Expression.java | 25 ++++++++++++++------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/src/main/java/carpet/script/Expression.java b/src/main/java/carpet/script/Expression.java index e55ac1f2..2695f85b 100644 --- a/src/main/java/carpet/script/Expression.java +++ b/src/main/java/carpet/script/Expression.java @@ -23,7 +23,6 @@ import carpet.script.value.MapValue; import carpet.script.value.NumericValue; import carpet.script.value.StringValue; import carpet.script.value.Value; -import com.sun.xml.internal.fastinfoset.algorithm.IntEncodingAlgorithm; import org.apache.commons.lang3.text.WordUtils; import java.math.BigInteger; @@ -338,7 +337,7 @@ import static java.lang.Math.min; public class Expression implements Cloneable { private static final Map precedence = new HashMap() {{ - put("attribute~.", 80); + put("attribute~:", 80); put("unary+-!", 60); put("exponent^", 40); put("multiplication*/%", 30); @@ -1073,7 +1072,7 @@ public class Expression implements Cloneable * even if they look like them: *

*
    - *
  • Match, Get ~ .
  • + *
  • Match, Get ~ :
  • *
  • Unary + - !
  • *
  • Exponent ^
  • *
  • Multiplication * / %
  • @@ -1088,7 +1087,7 @@ public class Expression implements Cloneable *
  • Bracket ( )
  • *
* - *

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.

+ * container elements, use 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), '.' operator

+ *

get(container, address), ':' operator

*

Returns 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

@@ -2036,7 +2045,7 @@ public class Expression implements Cloneable * get(l(range(10)), 5) => 5 * get(l(range(10)), -1) => 9 * get(l(range(10)), 10) => 0 - * l(range(10)).93 => 3 + * l(range(10)):93 => 3 * * get(player() ~ 'nbt', 'Health') => 20 // inefficient way to get player health, use player() ~ 'health' instead *