Use an empty sequence for the xml of implied choice branch sequences#1219
Merged
stevedlawrence merged 1 commit intoapache:mainfrom Jun 4, 2024
Merged
Conversation
When we need to add an implied sequence for a choice branch (like when the branch is an array), we wrap the branch Term in a ChoiceBranchImpliedSequence, which is essentially a Sequence that passes logic through to the underlying Term. This allows us to use existing sequence logic such as creating repetition parsers for arrays. However, when we create this ChoiceBranchImpliedSequence we set its xml parameter to the xml of the Term it wraps. And because it extends Sequence, it does all the normal sequence logic of parsing that xml, even though much of it is never used because most logic passes through to the underlying Term. In most cases, this works fine (although its wasted effort) since all that extra work is simply ignored. But, if that XML contains any expressions, things can quickly go off the rails as it tries to compile expressions with the context of this implied sequence. To fix this, instead of passing in the XML of the underlying Term, we just pass in an empty sequence XML. This means there is no longer any real work for the ChoiceBranchImpliedSequence to do, except for be a tool to create the necessary repetition parsers to wrap around the Term. Not only does this avoid issues with incorrect contexts, but it avoids unnecessary work that is just ignored. DAFFODIL-2887
stevedlawrence
commented
Apr 18, 2024
daffodil-core/src/main/scala/org/apache/daffodil/core/dsom/SequenceGroup.scala
Show resolved
Hide resolved
tuxji
approved these changes
Apr 18, 2024
daffodil-core/src/main/scala/org/apache/daffodil/core/dsom/SequenceGroup.scala
Show resolved
Hide resolved
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When we need to add an implied sequence for a choice branch (like when the branch is an array), we wrap the branch Term in a ChoiceBranchImpliedSequence, which is essentially a Sequence that passes logic through to the underlying Term. This allows us to use existing sequence logic such as creating repetition parsers for arrays.
However, when we create this ChoiceBranchImpliedSequence we set its xml parameter to the xml of the Term it wraps. And because it extends Sequence, it does all the normal sequence logic of parsing that xml, even though much of it is never used because most logic passes through to the underlying Term.
In most cases, this works fine (although its wasted effort) since all that extra work is simply ignored. But, if that XML contains any expressions, things can quickly go off the rails as it tries to compile expressions with the context of this implied sequence.
To fix this, instead of passing in the XML of the underlying Term, we just pass in an empty sequence XML. This means there is no longer any real work for the ChoiceBranchImpliedSequence to do, except for be a tool to create the necessary repetition parsers to wrap around the Term. Not only does this avoid issues with incorrect contexts, but it avoids unnecessary work that is just ignored.
DAFFODIL-2887