stevedlawrence commented on a change in pull request #332: Refactor isHidden
URL: https://github.com/apache/incubator-daffodil/pull/332#discussion_r392964299
##########
File path:
daffodil-core/src/main/scala/org/apache/daffodil/grammar/primitives/ChoiceCombinator.scala
##########
@@ -217,46 +217,58 @@ case class ChoiceCombinator(ch: ChoiceTermBase,
alternatives: Seq[Gram])
}
override lazy val unparser: Unparser = {
- if (!ch.isHidden) {
- val eventRDMap = ch.choiceBranchMap
- val eventUnparserMap = eventRDMap.flatMap {
- case (cbe, rd) =>
- // if we don't find a matching RD for a term that's probably
- // because the term is an empty sequence or empty choice (which do
happen
- // and we even have tests for them). Since those can never be chosen
by
- // means of an element event, they don't appear in the map.
- val altGram = alternatives.find { alt =>
- val crd = alt.context.runtimeData
- val found = crd =:= rd
- found
+ /*
+ * Since it's impossible to know the hiddenness for terms at this level
(unless
+ * they're a hiddenGroupRef), we always attempt to find a defaultable
unparser.
+ * If we find one, and at runtime, we're in a hidden state, we can use
that. If we
+ * are not in a hidden state, it doesn't get used. If we don't find one,
and we encounter
+ * a hidden group ref here, we know we'll run into that issue at runtime,
so we SDE.
+ */
+ val optDefaultableBranchUnparser = {
+ val defaultableBranches = ch.groupMembers.find {
_.isFullyDefaultableOrOVC }
+ if (defaultableBranches.nonEmpty) {
+ val defaultableBranchRD = defaultableBranches.get.runtimeData
+
+ // Choices inside a hidden group ref are slightly different because we
+ // will never see events for any of the branches. Instead, we will just
+ // always pick the branch in which every thing is defaultble or OVC.
+ val defaultableBranchUnparser =
alternatives.find(_.context.runtimeData =:= defaultableBranchRD).get.unparser
+ Some(defaultableBranchUnparser)
+ } else {
+ ch match {
+ case cgr: GroupRef if cgr.isHidden => {
+ /*
+ * This is a requirement for terms inside a hidden group. If we're
a hidden group ref, we know
+ * our descendants need this requirements, so it's a SDE if they
don't meet it.
+ */
+ cgr.SDE("Element(s) of hidden group must be fully defaultable or
define dfdl:outputValueCalc:\n%s",
Review comment:
This is a choice, so only one branch needs to be unparsable if hidden. The
error message sortof implies all need to be unparsable. Also, this comment
doesn't mention optionality, but maybe that's not necessary, since if someone
hits this the solution is probabl to add a default or OVC.
Also, if we got here, that means no branches were unparseable, so we can
just print them all, e.g. ``ch.groupMembers.mkString("\n")``
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services