-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Change return value of ValueExpression.eval(...) to ImmutableList<Value> #281
Conversation
…<Value>> instead of ImmutableList<Optional<Value>>. First pass to resolve compiler errors. Errors in test code still remain.
…yValueExpression.
…e> on ValueExpression's eval(). 19 compile errors remain.
Codecov Report
@@ Coverage Diff @@
## master #281 +/- ##
=======================================
Coverage 100% 100%
- Complexity 1032 1048 +16
=======================================
Files 92 94 +2
Lines 1394 1406 +12
Branches 146 150 +4
=======================================
+ Hits 1394 1406 +12
Continue to review full report at Codecov.
|
…ther (CodeFactor).
Issues identified by tools are resolved. Only remaining one that we can ignore for now is the issues that BetterCodeHub raises, since those issues mostly relate to the introduction of |
…f Def to SingleValueExpression, along with all dependencies.
…h all dependencies.
…and Self to SingleValueExpression.
…ons to SingleValueExpression.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pretty big PR, but it looks pretty good to me!
core/src/main/java/io/parsingdata/metal/data/ConcatenatedValueSource.java
Outdated
Show resolved
Hide resolved
core/src/main/java/io/parsingdata/metal/data/ConcatenatedValueSource.java
Outdated
Show resolved
Hide resolved
core/src/main/java/io/parsingdata/metal/data/DataExpressionSource.java
Outdated
Show resolved
Hide resolved
core/src/main/java/io/parsingdata/metal/data/DataExpressionSource.java
Outdated
Show resolved
Hide resolved
core/src/main/java/io/parsingdata/metal/expression/value/Value.java
Outdated
Show resolved
Hide resolved
core/src/main/java/io/parsingdata/metal/expression/value/Expand.java
Outdated
Show resolved
Hide resolved
core/src/main/java/io/parsingdata/metal/expression/value/Fold.java
Outdated
Show resolved
Hide resolved
core/src/main/java/io/parsingdata/metal/expression/value/UnaryValueExpression.java
Outdated
Show resolved
Hide resolved
core/src/main/java/io/parsingdata/metal/expression/value/reference/CurrentIteration.java
Outdated
Show resolved
Hide resolved
core/src/main/java/io/parsingdata/metal/expression/value/reference/Ref.java
Show resolved
Hide resolved
core/src/main/java/io/parsingdata/metal/data/ConcatenatedValueSource.java
Outdated
Show resolved
Hide resolved
core/src/main/java/io/parsingdata/metal/data/DataExpressionSource.java
Outdated
Show resolved
Hide resolved
core/src/main/java/io/parsingdata/metal/expression/comparison/ComparisonExpression.java
Outdated
Show resolved
Hide resolved
core/src/main/java/io/parsingdata/metal/expression/value/BinaryValueExpression.java
Outdated
Show resolved
Hide resolved
core/src/main/java/io/parsingdata/metal/expression/value/Fold.java
Outdated
Show resolved
Hide resolved
core/src/main/java/io/parsingdata/metal/expression/value/Fold.java
Outdated
Show resolved
Hide resolved
core/src/main/java/io/parsingdata/metal/expression/value/UnaryValueExpression.java
Outdated
Show resolved
Hide resolved
core/src/main/java/io/parsingdata/metal/expression/value/ValueExpression.java
Outdated
Show resolved
Hide resolved
core/src/main/java/io/parsingdata/metal/expression/value/arithmetic/Div.java
Show resolved
Hide resolved
core/src/main/java/io/parsingdata/metal/expression/value/FoldCat.java
Outdated
Show resolved
Hide resolved
core/src/main/java/io/parsingdata/metal/expression/value/reference/Self.java
Outdated
Show resolved
Hide resolved
Add SingleValueExpression to type ValueExpressions that always return a single value
Convert Value to interface, extract functionality to CoreValue and create a NotAValue class
…s multiple lines. Comment by @mvanaken.
I have checked the BetterCodeHub-results. They seem to indicate some worsening of their metrics but everything still seems quite well within their own quality parameters (still scoring 9/10). |
This refactoring changes the return value of
ValueExpression.eval(...)
fromImmutableList<Optional<Value>>
toImmutableList<Value>
. Putting optionals in a list doesn't really make sense, instead, there is now aNOT_A_VALUE
constant to express results that have no value, such as the result of a division-by-zero.In the earliest commits (not visible in the full diff now) the return value was changed to
Optional<ImmutableList<Value>>
however since the original interface already required a non-null return value, wrapping the new return value into an optional appeared unnecessary. Furthermore, it becomes quite tricky to distinguish between return values such asOptional.empty()
, an emptyImmutableList
, a list containing a singleNOT_A_VALUE
, etc.The current semantics should be that:
ref("a")
when no values with name "a" exist) returns an empty list.NOT_A_VALUE
. In the context of processing lists, only the specific computation that results inNOT_A_VALUE
will do so, not the surrounding ones. For example, the result of div([1, 1, 1], [1, 0, 1]) will evaluate to [1, NOT_A_VALUE, 1].NOT_A_VALUE
results in false, soeq(con(NOT_A_VALUE), con(NOT_A_VALUE))
evaluates tofalse
. This is in line with behaviour defined by IEEE-754.Some other points to consider:
SingleValueExpression
is required, sometimes an exception is thrown upon encountering aNOT_A_VALUE
, but not always (e.g.,CurrentIteration
andExpand
do it, butRef
doesn't). Let's unify this when we implement Add type mechanism for single value list expressions #70.NOT_A_VALUE
. This is currently by design to simplify the size of the diff this issue generates and will be fixed in Create a clean implementation for NOT_A_VALUE #280.Finally, I've come across some things to consider and perhaps change:
Sub
(theToken
) orTie
is invoked with an empty list ofValueExpressions
(for theoffset
s anddataExpression
s respectively) that doesn't fail the parse, which makes sense, but it does insert an emptyParseGraph
. I'm not sure that's a good idea.CurrentIteration
returns an empty list when a nonsensicallevel
is provided such as a negative number. It also does this when the requested level does not exist (e.g., 5 when there are only 3 levels). Perhaps it makes more sense to returnNOT_A_VALUE
for a negative number (i.e., impossible) and 0 for a too high number (i.e., we are technically in iteration 0 for everything above the current high level)?If we decide to change behaviour, let's make new issues so they don't make this diff larger. Additionally, I will pick up any issues resulting from the analysis tools on this PR.
This PR resolves #279.