diff --git a/core/src/main/java/io/parsingdata/metal/Shorthand.java b/core/src/main/java/io/parsingdata/metal/Shorthand.java index a92b99cf..750df57a 100644 --- a/core/src/main/java/io/parsingdata/metal/Shorthand.java +++ b/core/src/main/java/io/parsingdata/metal/Shorthand.java @@ -44,6 +44,7 @@ import io.parsingdata.metal.expression.value.Cat; import io.parsingdata.metal.expression.value.Const; import io.parsingdata.metal.expression.value.ConstantFactory; +import io.parsingdata.metal.expression.value.OneToManyValueExpression; import io.parsingdata.metal.expression.value.reference.CurrentIteration; import io.parsingdata.metal.expression.value.Elvis; import io.parsingdata.metal.expression.value.Expand; @@ -51,7 +52,6 @@ import io.parsingdata.metal.expression.value.FoldRight; import io.parsingdata.metal.expression.value.FoldCat; import io.parsingdata.metal.expression.value.Reverse; -import io.parsingdata.metal.expression.value.UnaryValueExpression; import io.parsingdata.metal.expression.value.Value; import io.parsingdata.metal.expression.value.ValueExpression; import io.parsingdata.metal.expression.value.arithmetic.Add; @@ -164,10 +164,10 @@ private Shorthand() {} public static BinaryValueExpression mul(final ValueExpression left, final ValueExpression right) { return new Mul(left, right); } public static BinaryValueExpression sub(final ValueExpression left, final ValueExpression right) { return new Sub(left, right); } public static BinaryValueExpression mod(final ValueExpression left, final ValueExpression right) { return new Mod(left, right); } - public static UnaryValueExpression neg(final ValueExpression operand) { return new Neg(operand); } + public static OneToManyValueExpression neg(final ValueExpression operand) { return new Neg(operand); } public static BinaryValueExpression and(final ValueExpression left, final ValueExpression right) { return new io.parsingdata.metal.expression.value.bitwise.And(left, right); } public static BinaryValueExpression or(final ValueExpression left, final ValueExpression right) { return new io.parsingdata.metal.expression.value.bitwise.Or(left, right); } - public static UnaryValueExpression not(final ValueExpression operand) { return new io.parsingdata.metal.expression.value.bitwise.Not(operand); } + public static OneToManyValueExpression not(final ValueExpression operand) { return new io.parsingdata.metal.expression.value.bitwise.Not(operand); } public static BinaryValueExpression shl(final ValueExpression left, final ValueExpression right) { return new ShiftLeft(left, right); } public static BinaryValueExpression shr(final ValueExpression left, final ValueExpression right) { return new ShiftRight(left, right); } public static ValueExpression con(final long value) { return con(value, new Encoding()); } diff --git a/core/src/main/java/io/parsingdata/metal/Util.java b/core/src/main/java/io/parsingdata/metal/Util.java index c8100a34..29e77168 100644 --- a/core/src/main/java/io/parsingdata/metal/Util.java +++ b/core/src/main/java/io/parsingdata/metal/Util.java @@ -27,7 +27,7 @@ import io.parsingdata.metal.data.ParseState; import io.parsingdata.metal.data.Slice; import io.parsingdata.metal.encoding.Encoding; -import io.parsingdata.metal.expression.value.UnaryValueExpression; +import io.parsingdata.metal.expression.value.OneToManyValueExpression; import io.parsingdata.metal.expression.value.Value; import io.parsingdata.metal.expression.value.ValueExpression; @@ -85,7 +85,7 @@ public static String bytesToHexString(final byte[] bytes) { } public static ValueExpression inflate(final ValueExpression target) { - return new UnaryValueExpression(target) { + return new OneToManyValueExpression(target) { @Override public Optional eval(final Value value, final ParseState parseState, final Encoding encoding) { final Inflater inf = new Inflater(true); diff --git a/core/src/main/java/io/parsingdata/metal/expression/value/BinaryValueExpression.java b/core/src/main/java/io/parsingdata/metal/expression/value/BinaryValueExpression.java index 24fc71ad..c8c7c75c 100644 --- a/core/src/main/java/io/parsingdata/metal/expression/value/BinaryValueExpression.java +++ b/core/src/main/java/io/parsingdata/metal/expression/value/BinaryValueExpression.java @@ -49,7 +49,7 @@ * handling the case of evaluating two values. This base class takes care of * evaluating the operands and handling list semantics. * - * @see UnaryValueExpression + * @see OneToManyValueExpression */ public abstract class BinaryValueExpression implements ValueExpression { diff --git a/core/src/main/java/io/parsingdata/metal/expression/value/FoldCat.java b/core/src/main/java/io/parsingdata/metal/expression/value/FoldCat.java index defc5806..ae5a1fad 100644 --- a/core/src/main/java/io/parsingdata/metal/expression/value/FoldCat.java +++ b/core/src/main/java/io/parsingdata/metal/expression/value/FoldCat.java @@ -20,10 +20,8 @@ import static io.parsingdata.metal.data.Slice.createFromSource; -import java.util.Objects; import java.util.Optional; -import io.parsingdata.metal.Util; import io.parsingdata.metal.data.ConcatenatedValueSource; import io.parsingdata.metal.data.ImmutableList; import io.parsingdata.metal.data.ParseState; @@ -36,36 +34,17 @@ * @see FoldLeft * @see Cat */ -public class FoldCat implements ValueExpression { - - public final ValueExpression operand; +public class FoldCat extends OneToOneValueExpression { public FoldCat(final ValueExpression operand) { - this.operand = operand; - } - - @Override - public ImmutableList> eval(final ParseState parseState, final Encoding encoding) { - return ConcatenatedValueSource.create(operand.eval(parseState, encoding)) - .flatMap(source -> createFromSource(source, ZERO, source.length)) - .map(slice -> new ImmutableList>().add(Optional.of(new Value(slice, encoding)))) - .orElseGet(() -> ImmutableList.create(Optional.empty())); - } - - @Override - public String toString() { - return getClass().getSimpleName() + "(" + operand + ")"; - } - - @Override - public boolean equals(final Object obj) { - return Util.notNullAndSameClass(this, obj) - && Objects.equals(operand, ((FoldCat)obj).operand); + super(operand); } @Override - public int hashCode() { - return Objects.hash(getClass(), operand); + public Optional eval(final ImmutableList> list, final ParseState parseState, final Encoding encoding) { + return ConcatenatedValueSource.create(list) + .flatMap(source -> createFromSource(source, ZERO, source.length)) + .map(slice -> new Value(slice, encoding)); } } diff --git a/core/src/main/java/io/parsingdata/metal/expression/value/UnaryValueExpression.java b/core/src/main/java/io/parsingdata/metal/expression/value/OneToManyValueExpression.java similarity index 86% rename from core/src/main/java/io/parsingdata/metal/expression/value/UnaryValueExpression.java rename to core/src/main/java/io/parsingdata/metal/expression/value/OneToManyValueExpression.java index 5f32053c..f3552397 100644 --- a/core/src/main/java/io/parsingdata/metal/expression/value/UnaryValueExpression.java +++ b/core/src/main/java/io/parsingdata/metal/expression/value/OneToManyValueExpression.java @@ -31,25 +31,26 @@ import io.parsingdata.metal.encoding.Encoding; /** - * Base class for {@link ValueExpression}s with one operand. + * Base class for {@link ValueExpression}s with one operand that evaluates + * to multiple values. *

- * A UnaryValueExpression implements a ValueExpression that has one + * A OneToManyValueExpression implements a ValueExpression that has one * operand (a {@link ValueExpression}). The operand is first * evaluated. If it evaluates to {@link Optional#empty()}, the result of the * ValueExpression itself will be that as well. *

- * To implement a UnaryValueExpression, only the + * To implement a OneToManyValueExpression, only the * {@link #eval(Value, ParseState, Encoding)} must be implemented, handling * the case of evaluating one value. This base class takes care of evaluating * the operand and handling list semantics. * * @see BinaryValueExpression */ -public abstract class UnaryValueExpression implements ValueExpression { +public abstract class OneToManyValueExpression implements ValueExpression { public final ValueExpression operand; - public UnaryValueExpression(final ValueExpression operand) { + public OneToManyValueExpression(final ValueExpression operand) { this.operand = checkNotNull(operand, "operand"); } @@ -75,7 +76,7 @@ public String toString() { @Override public boolean equals(final Object obj) { return Util.notNullAndSameClass(this, obj) - && Objects.equals(operand, ((UnaryValueExpression)obj).operand); + && Objects.equals(operand, ((OneToManyValueExpression)obj).operand); } @Override diff --git a/core/src/main/java/io/parsingdata/metal/expression/value/OneToOneValueExpression.java b/core/src/main/java/io/parsingdata/metal/expression/value/OneToOneValueExpression.java new file mode 100644 index 00000000..56208d4b --- /dev/null +++ b/core/src/main/java/io/parsingdata/metal/expression/value/OneToOneValueExpression.java @@ -0,0 +1,77 @@ +/* + * Copyright 2013-2016 Netherlands Forensic Institute + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.parsingdata.metal.expression.value; + +import static io.parsingdata.metal.Util.checkNotNull; + +import java.util.Objects; +import java.util.Optional; + +import io.parsingdata.metal.Util; +import io.parsingdata.metal.data.ImmutableList; +import io.parsingdata.metal.data.ParseState; +import io.parsingdata.metal.encoding.Encoding; + +/** + * Base class for {@link ValueExpression}s with one operand that evaluates + * to a single value. + *

+ * A OneToOneValueExpression implements a ValueExpression that has one + * operand (a {@link ValueExpression}). The operand is first + * evaluated. If it evaluates to {@link Optional#empty()}, the result of the + * ValueExpression itself will be that as well. + *

+ * To implement a OneToOneValueExpression, only the + * {@link #eval(ImmutableList, ParseState, Encoding)} must + * be implemented, handling the case of evaluating a list of values. This + * base class takes care of evaluating the operand and handling list + * semantics. + * + * @see BinaryValueExpression + */ +public abstract class OneToOneValueExpression implements ValueExpression { + + public final ValueExpression operand; + + public OneToOneValueExpression(final ValueExpression operand) { + this.operand = checkNotNull(operand, "operand"); + } + + @Override + public ImmutableList> eval(final ParseState parseState, final Encoding encoding) { + return ImmutableList.create(eval(operand.eval(parseState, encoding), parseState, encoding)); + } + + public abstract Optional eval(final ImmutableList> list, final ParseState parseState, final Encoding encoding); + + @Override + public String toString() { + return getClass().getSimpleName() + "(" + operand + ")"; + } + + @Override + public boolean equals(final Object obj) { + return Util.notNullAndSameClass(this, obj) + && Objects.equals(operand, ((OneToOneValueExpression)obj).operand); + } + + @Override + public int hashCode() { + return Objects.hash(getClass(), operand); + } + +} diff --git a/core/src/main/java/io/parsingdata/metal/expression/value/arithmetic/Neg.java b/core/src/main/java/io/parsingdata/metal/expression/value/arithmetic/Neg.java index 1b0a886d..8b0e392a 100644 --- a/core/src/main/java/io/parsingdata/metal/expression/value/arithmetic/Neg.java +++ b/core/src/main/java/io/parsingdata/metal/expression/value/arithmetic/Neg.java @@ -21,14 +21,14 @@ import io.parsingdata.metal.data.ParseState; import io.parsingdata.metal.encoding.Encoding; import io.parsingdata.metal.expression.value.ConstantFactory; -import io.parsingdata.metal.expression.value.UnaryValueExpression; +import io.parsingdata.metal.expression.value.OneToManyValueExpression; import io.parsingdata.metal.expression.value.Value; import io.parsingdata.metal.expression.value.ValueExpression; /** - * A {@link UnaryValueExpression} that implements integer negation. + * A {@link OneToManyValueExpression} that implements integer negation. */ -public class Neg extends UnaryValueExpression { +public class Neg extends OneToManyValueExpression { public Neg(final ValueExpression operand) { super(operand); diff --git a/core/src/main/java/io/parsingdata/metal/expression/value/bitwise/Not.java b/core/src/main/java/io/parsingdata/metal/expression/value/bitwise/Not.java index 4da8f734..95480a43 100644 --- a/core/src/main/java/io/parsingdata/metal/expression/value/bitwise/Not.java +++ b/core/src/main/java/io/parsingdata/metal/expression/value/bitwise/Not.java @@ -22,14 +22,14 @@ import io.parsingdata.metal.data.ParseState; import io.parsingdata.metal.encoding.Encoding; import io.parsingdata.metal.expression.value.ConstantFactory; -import io.parsingdata.metal.expression.value.UnaryValueExpression; +import io.parsingdata.metal.expression.value.OneToManyValueExpression; import io.parsingdata.metal.expression.value.Value; import io.parsingdata.metal.expression.value.ValueExpression; /** - * A {@link UnaryValueExpression} that implements the bitwise NOT operator. + * A {@link OneToManyValueExpression} that implements the bitwise NOT operator. */ -public class Not extends UnaryValueExpression { +public class Not extends OneToManyValueExpression { public Not(final ValueExpression operand) { super(operand); diff --git a/core/src/main/java/io/parsingdata/metal/expression/value/reference/Count.java b/core/src/main/java/io/parsingdata/metal/expression/value/reference/Count.java index 19c8adf7..9d0ee29b 100644 --- a/core/src/main/java/io/parsingdata/metal/expression/value/reference/Count.java +++ b/core/src/main/java/io/parsingdata/metal/expression/value/reference/Count.java @@ -16,17 +16,14 @@ package io.parsingdata.metal.expression.value.reference; -import static io.parsingdata.metal.Util.checkNotNull; - -import java.util.Objects; import java.util.Optional; -import io.parsingdata.metal.Util; import io.parsingdata.metal.data.ImmutableList; import io.parsingdata.metal.data.ParseState; import io.parsingdata.metal.encoding.Encoding; import io.parsingdata.metal.encoding.Sign; import io.parsingdata.metal.expression.value.ConstantFactory; +import io.parsingdata.metal.expression.value.OneToOneValueExpression; import io.parsingdata.metal.expression.value.Value; import io.parsingdata.metal.expression.value.ValueExpression; @@ -34,38 +31,19 @@ * A {@link ValueExpression} that represents the amount of {@link Value}s * returned by evaluating its operand. */ -public class Count implements ValueExpression { - - public final ValueExpression operand; +public class Count extends OneToOneValueExpression { public Count(final ValueExpression operand) { - this.operand = checkNotNull(operand, "operand"); + super(operand); } @Override - public ImmutableList> eval(final ParseState parseState, final Encoding encoding) { - final ImmutableList> values = operand.eval(parseState, encoding); - return ImmutableList.create(Optional.of(fromNumeric(values.size))); + public Optional eval(final ImmutableList> list, final ParseState parseState, final Encoding encoding) { + return Optional.of(fromNumeric(list.size)); } private static Value fromNumeric(final long length) { return ConstantFactory.createFromNumeric(length, new Encoding(Sign.SIGNED)); } - @Override - public String toString() { - return getClass().getSimpleName() + "(" + operand + ")"; - } - - @Override - public boolean equals(final Object obj) { - return Util.notNullAndSameClass(this, obj) - && Objects.equals(operand, ((Count)obj).operand); - } - - @Override - public int hashCode() { - return Objects.hash(getClass(), operand); - } - } diff --git a/core/src/main/java/io/parsingdata/metal/expression/value/reference/First.java b/core/src/main/java/io/parsingdata/metal/expression/value/reference/First.java index c3031f92..abbbdffc 100644 --- a/core/src/main/java/io/parsingdata/metal/expression/value/reference/First.java +++ b/core/src/main/java/io/parsingdata/metal/expression/value/reference/First.java @@ -18,16 +18,14 @@ import static io.parsingdata.metal.Trampoline.complete; import static io.parsingdata.metal.Trampoline.intermediate; -import static io.parsingdata.metal.Util.checkNotNull; -import java.util.Objects; import java.util.Optional; import io.parsingdata.metal.Trampoline; -import io.parsingdata.metal.Util; import io.parsingdata.metal.data.ImmutableList; import io.parsingdata.metal.data.ParseState; import io.parsingdata.metal.encoding.Encoding; +import io.parsingdata.metal.expression.value.OneToOneValueExpression; import io.parsingdata.metal.expression.value.Value; import io.parsingdata.metal.expression.value.ValueExpression; @@ -35,38 +33,19 @@ * A {@link ValueExpression} that represents the first {@link Value} returned * by evaluating its operand. */ -public class First implements ValueExpression { - - public final ValueExpression operand; +public class First extends OneToOneValueExpression { public First(final ValueExpression operand) { - this.operand = checkNotNull(operand, "operand"); + super(operand); } @Override - public ImmutableList> eval(final ParseState parseState, final Encoding encoding) { - final ImmutableList> list = operand.eval(parseState, encoding); - return list.isEmpty() ? list : ImmutableList.create(getFirst(list).computeResult()); + public Optional eval(final ImmutableList> list, final ParseState parseState, final Encoding encoding) { + return list.isEmpty() ? Optional.empty() : getFirst(list).computeResult(); } private Trampoline> getFirst(final ImmutableList> values) { return values.tail.isEmpty() ? complete(() -> values.head) : intermediate(() -> getFirst(values.tail)); } - @Override - public String toString() { - return getClass().getSimpleName() + "(" + operand + ")"; - } - - @Override - public boolean equals(final Object obj) { - return Util.notNullAndSameClass(this, obj) - && Objects.equals(operand, ((First)obj).operand); - } - - @Override - public int hashCode() { - return Objects.hash(getClass(), operand); - } - } diff --git a/core/src/main/java/io/parsingdata/metal/expression/value/reference/Last.java b/core/src/main/java/io/parsingdata/metal/expression/value/reference/Last.java index 6d023051..f11e2f1c 100644 --- a/core/src/main/java/io/parsingdata/metal/expression/value/reference/Last.java +++ b/core/src/main/java/io/parsingdata/metal/expression/value/reference/Last.java @@ -16,15 +16,12 @@ package io.parsingdata.metal.expression.value.reference; -import static io.parsingdata.metal.Util.checkNotNull; - -import java.util.Objects; import java.util.Optional; -import io.parsingdata.metal.Util; import io.parsingdata.metal.data.ImmutableList; import io.parsingdata.metal.data.ParseState; import io.parsingdata.metal.encoding.Encoding; +import io.parsingdata.metal.expression.value.OneToOneValueExpression; import io.parsingdata.metal.expression.value.Value; import io.parsingdata.metal.expression.value.ValueExpression; @@ -32,34 +29,15 @@ * A {@link ValueExpression} that represents the last {@link Value} returned * by evaluating its operand. */ -public class Last implements ValueExpression { - - public final ValueExpression operand; +public class Last extends OneToOneValueExpression { public Last(final ValueExpression operand) { - this.operand = checkNotNull(operand, "operand"); - } - - @Override - public ImmutableList> eval(final ParseState parseState, final Encoding encoding) { - final ImmutableList> list = operand.eval(parseState, encoding); - return list.isEmpty() ? list : ImmutableList.create(list.head); - } - - @Override - public String toString() { - return getClass().getSimpleName() + "(" + operand + ")"; - } - - @Override - public boolean equals(final Object obj) { - return Util.notNullAndSameClass(this, obj) - && Objects.equals(operand, ((Last)obj).operand); + super(operand); } @Override - public int hashCode() { - return Objects.hash(getClass(), operand); + public Optional eval(final ImmutableList> list, final ParseState parseState, final Encoding encoding) { + return list.isEmpty() ? Optional.empty() : list.head; } } diff --git a/core/src/main/java/io/parsingdata/metal/expression/value/reference/Len.java b/core/src/main/java/io/parsingdata/metal/expression/value/reference/Len.java index d76e8f1f..ae292d49 100644 --- a/core/src/main/java/io/parsingdata/metal/expression/value/reference/Len.java +++ b/core/src/main/java/io/parsingdata/metal/expression/value/reference/Len.java @@ -23,15 +23,15 @@ import io.parsingdata.metal.encoding.Encoding; import io.parsingdata.metal.encoding.Sign; import io.parsingdata.metal.expression.value.ConstantFactory; -import io.parsingdata.metal.expression.value.UnaryValueExpression; +import io.parsingdata.metal.expression.value.OneToManyValueExpression; import io.parsingdata.metal.expression.value.Value; import io.parsingdata.metal.expression.value.ValueExpression; /** - * A {@link UnaryValueExpression} that represents the sizes (in bytes) of all + * A {@link OneToManyValueExpression} that represents the sizes (in bytes) of all * {@link Value}s returned by evaluating its operand. */ -public class Len extends UnaryValueExpression { +public class Len extends OneToManyValueExpression { public Len(final ValueExpression operand) { super(operand); diff --git a/core/src/main/java/io/parsingdata/metal/expression/value/reference/Offset.java b/core/src/main/java/io/parsingdata/metal/expression/value/reference/Offset.java index cc7646c2..fea19efc 100644 --- a/core/src/main/java/io/parsingdata/metal/expression/value/reference/Offset.java +++ b/core/src/main/java/io/parsingdata/metal/expression/value/reference/Offset.java @@ -22,7 +22,7 @@ import io.parsingdata.metal.data.ParseValue; import io.parsingdata.metal.encoding.Encoding; import io.parsingdata.metal.expression.value.ConstantFactory; -import io.parsingdata.metal.expression.value.UnaryValueExpression; +import io.parsingdata.metal.expression.value.OneToManyValueExpression; import io.parsingdata.metal.expression.value.Value; import io.parsingdata.metal.expression.value.ValueExpression; @@ -34,7 +34,7 @@ * If a result does not have an offset (such as the {@link Value}s returned by * {@link io.parsingdata.metal.expression.value.Const}), empty is returned. */ -public class Offset extends UnaryValueExpression { +public class Offset extends OneToManyValueExpression { public Offset(final ValueExpression operand) { super(operand); } diff --git a/core/src/test/java/io/parsingdata/metal/ArgumentsTest.java b/core/src/test/java/io/parsingdata/metal/ArgumentsTest.java index a456a704..36d40ea9 100644 --- a/core/src/test/java/io/parsingdata/metal/ArgumentsTest.java +++ b/core/src/test/java/io/parsingdata/metal/ArgumentsTest.java @@ -101,7 +101,7 @@ public static Collection arguments() { // Derived from BinaryValueExpression { Cat.class, new Object[] { VALID_VE, null } }, { Cat.class, new Object[] { null, VALID_VE } }, - // Derived from UnaryValueExpression + // Derived from OneToManyValueExpression { Neg.class, new Object[] { null } }, { Len.class, new Object[] { null } }, // Derived from BinaryLogicalExpression diff --git a/core/src/test/java/io/parsingdata/metal/ArithmeticValueExpressionSemanticsTest.java b/core/src/test/java/io/parsingdata/metal/ArithmeticValueExpressionSemanticsTest.java index f0125dfd..28d8aacd 100644 --- a/core/src/test/java/io/parsingdata/metal/ArithmeticValueExpressionSemanticsTest.java +++ b/core/src/test/java/io/parsingdata/metal/ArithmeticValueExpressionSemanticsTest.java @@ -39,7 +39,7 @@ import org.junit.runners.Parameterized.Parameters; import io.parsingdata.metal.expression.value.BinaryValueExpression; -import io.parsingdata.metal.expression.value.UnaryValueExpression; +import io.parsingdata.metal.expression.value.OneToManyValueExpression; import io.parsingdata.metal.expression.value.ValueExpression; import io.parsingdata.metal.token.Token; import io.parsingdata.metal.util.ParameterizedParse; @@ -102,7 +102,7 @@ public static Collection data() { private static final Token mul2 = binaryValueExpressionToken(mul(ref("a"), ref("b")), 2); private static final Token sub = binaryValueExpressionToken(sub(ref("a"), ref("b")), 1); private static final Token mod = binaryValueExpressionToken(mod(ref("a"), ref("b")), 1); - private static final Token neg = unaryValueExpressionToken(neg(ref("a"))); + private static final Token neg = oneToManyValueExpression(neg(ref("a"))); private static Token singleToken(final String firstName, final String secondName, final int resultSize, final ValueExpression valueExpression) { return seq(any(firstName), @@ -114,7 +114,7 @@ private static Token binaryValueExpressionToken(final BinaryValueExpression bina singleToken("b", "c", resultSize, binaryValueExpression)); } - private static Token unaryValueExpressionToken(final UnaryValueExpression unaryValueExpression) { + private static Token oneToManyValueExpression(final OneToManyValueExpression unaryValueExpression) { return singleToken("a", "b", 1, unaryValueExpression); } diff --git a/core/src/test/java/io/parsingdata/metal/ValueExpressionSemanticsTest.java b/core/src/test/java/io/parsingdata/metal/ValueExpressionSemanticsTest.java index 04f0e550..1c14d04d 100644 --- a/core/src/test/java/io/parsingdata/metal/ValueExpressionSemanticsTest.java +++ b/core/src/test/java/io/parsingdata/metal/ValueExpressionSemanticsTest.java @@ -39,7 +39,7 @@ import io.parsingdata.metal.data.ParseState; import io.parsingdata.metal.encoding.Encoding; -import io.parsingdata.metal.expression.value.UnaryValueExpression; +import io.parsingdata.metal.expression.value.OneToManyValueExpression; import io.parsingdata.metal.expression.value.Value; import io.parsingdata.metal.token.Token; @@ -63,7 +63,7 @@ public void CatNoMatch() throws IOException { @Test public void callback() throws IOException { final ParseState data = stream(1, 2, 3, 4); - def("a", 4, eq(new UnaryValueExpression(ref("a")) { + def("a", 4, eq(new OneToManyValueExpression(ref("a")) { @Override public Optional eval(Value value, ParseState parseState, Encoding encoding) { return Optional.of(value); diff --git a/formats/src/main/java/io/parsingdata/metal/format/Callback.java b/formats/src/main/java/io/parsingdata/metal/format/Callback.java index 00924789..c40162d1 100644 --- a/formats/src/main/java/io/parsingdata/metal/format/Callback.java +++ b/formats/src/main/java/io/parsingdata/metal/format/Callback.java @@ -23,7 +23,7 @@ import io.parsingdata.metal.data.ParseState; import io.parsingdata.metal.encoding.Encoding; -import io.parsingdata.metal.expression.value.UnaryValueExpression; +import io.parsingdata.metal.expression.value.OneToManyValueExpression; import io.parsingdata.metal.expression.value.Value; import io.parsingdata.metal.expression.value.ValueExpression; @@ -32,7 +32,7 @@ public final class Callback { private Callback() {} public static ValueExpression crc32(final ValueExpression target) { - return new UnaryValueExpression(target) { + return new OneToManyValueExpression(target) { @Override public Optional eval(final Value value, final ParseState parseState, final Encoding encoding) { final CRC32 crc = new CRC32();