diff --git a/programs/tests/fixtures/Rocky_ext/array_ext/array_slicing.rock b/programs/tests/fixtures/Rocky_ext/array_ext/array_slicing.rock new file mode 100644 index 0000000..e76c06f --- /dev/null +++ b/programs/tests/fixtures/Rocky_ext/array_ext/array_slicing.rock @@ -0,0 +1,18 @@ +cut "ABCDEFGHIJ" into letters + +sliced = letters till 3 +join sliced +say sliced + +sliced = letters since 3 +join sliced +say sliced + +sliced = letters since 3 till 6 +join sliced +say sliced + +sliced = letters till 8 since 6 +join sliced +say sliced + diff --git a/programs/tests/fixtures/Rocky_ext/array_ext/array_slicing.rock.out b/programs/tests/fixtures/Rocky_ext/array_ext/array_slicing.rock.out new file mode 100644 index 0000000..592d5e9 --- /dev/null +++ b/programs/tests/fixtures/Rocky_ext/array_ext/array_slicing.rock.out @@ -0,0 +1,4 @@ +ABC +DEFGHIJ +DEF +GH diff --git a/rocky.jar b/rocky.jar index af1608b..d309d2d 100644 Binary files a/rocky.jar and b/rocky.jar differ diff --git a/src/rockstar/expression/SliceExpression.java b/src/rockstar/expression/SliceExpression.java index 2ae496c..6c2d3d5 100644 --- a/src/rockstar/expression/SliceExpression.java +++ b/src/rockstar/expression/SliceExpression.java @@ -36,7 +36,7 @@ public Type getType() { @Override public String getFormat() { - return "(%s" + (type != Type.SLICE_TO ? " from %s" : "") + (type != Type.SLICE_FROM ? " till %s" : "") + ")"; + return "(%s" + (type != Type.SLICE_TO ? " since %s" : "") + (type != Type.SLICE_FROM ? " till %s" : "") + ")"; } @Override @@ -79,10 +79,10 @@ public Value evaluate(BlockContext ctx) { Value retValue = Value.MYSTERIOUS; if (baseVal.isArray()) { List baseList = baseVal.asListArray(); - List newList = baseList.subList(fromVal == null ? 0 : fromVal, toVal == null ? baseList.size() : toVal + 1); + List newList = baseList.subList(fromVal == null ? 0 : fromVal, toVal == null ? baseList.size() : toVal); retValue = Value.getValue(newList); } else { - throw new RockstarRuntimeException("Invalid argument for from/till operation: " + baseVal.getType()); + throw new RockstarRuntimeException("Invalid argument for since/till operation: " + baseVal.getType()); } return ctx.afterExpression(this, retValue); diff --git a/src/rockstar/parser/ExpressionParser.java b/src/rockstar/parser/ExpressionParser.java index 80f4a05..0a60ef8 100644 --- a/src/rockstar/parser/ExpressionParser.java +++ b/src/rockstar/parser/ExpressionParser.java @@ -488,7 +488,7 @@ public CompoundExpression getOperator(boolean isAfterOperator) { next(); return (CompoundExpression) new RollExpression().withTokens(list, startIdx, idx); } - if (checkCurrent(Keyword.FROM)) { + if (checkCurrent(Keyword.SINCE)) { next(); return (CompoundExpression) new SliceExpression(SliceExpression.Type.SLICE_FROM).withTokens(list, startIdx, idx); diff --git a/src/rockstar/parser/Keyword.java b/src/rockstar/parser/Keyword.java index cbbdb4b..1007a72 100644 --- a/src/rockstar/parser/Keyword.java +++ b/src/rockstar/parser/Keyword.java @@ -44,7 +44,7 @@ public enum Keyword { ROCK(), ROLL("roll", "pop"), INTO("into", "in"), - FROM("+from"), + SINCE("+since"), TILL("+till"), TAKING("taking"), SORTED("+sorted"),