This is an automated email from the ASF dual-hosted git repository.

slawrence pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/daffodil.git


The following commit(s) were added to refs/heads/main by this push:
     new dc558743c Allow inputValueCalc to be defined in a hidden group
dc558743c is described below

commit dc558743c067270cfe062943ea0cbfa69fea410b
Author: Steve Lawrence <[email protected]>
AuthorDate: Fri May 17 14:27:39 2024 -0400

    Allow inputValueCalc to be defined in a hidden group
    
    An inputValueCalc inside a hidden group behaves very similar to a
    variable, but is useful in cases where you don't want to use a variable.
    
    For example, a common pattern is two have groups pairs of elements of
    original data and transformed value. In a subset of cases we may want to
    hide the original/transformed pair and use an non-hidden IVC that
    references the transformed value. By allowing hidden IVC's, we do not
    need change the pattern to use variables.
    
    Only minimal changes are needed because this does not change parse
    behavior and IVC elements are already skipped during unparsing.
    
    DAFFODIL-2903
---
 .../scala/org/apache/daffodil/core/dsom/Term.scala |  2 +-
 .../grammar/primitives/SequenceCombinator.scala    |  4 +--
 .../core/runtime1/ChoiceTermRuntime1Mixin.scala    |  2 +-
 .../section14/sequence_groups/SequenceGroup.tdml   | 35 ++++++++++++++++++++++
 .../sequence_groups/TestSequenceGroups.scala       |  2 ++
 5 files changed, 41 insertions(+), 4 deletions(-)

diff --git 
a/daffodil-core/src/main/scala/org/apache/daffodil/core/dsom/Term.scala 
b/daffodil-core/src/main/scala/org/apache/daffodil/core/dsom/Term.scala
index 63b3870a9..95ce0d04a 100644
--- a/daffodil-core/src/main/scala/org/apache/daffodil/core/dsom/Term.scala
+++ b/daffodil-core/src/main/scala/org/apache/daffodil/core/dsom/Term.scala
@@ -527,7 +527,7 @@ trait Term
         e.complexType.group.canUnparseIfHidden
       }
       case e: ElementBase => {
-        e.canBeAbsentFromUnparseInfoset
+        !e.isRepresented || e.canBeAbsentFromUnparseInfoset
       }
     }
     res
diff --git 
a/daffodil-core/src/main/scala/org/apache/daffodil/core/grammar/primitives/SequenceCombinator.scala
 
b/daffodil-core/src/main/scala/org/apache/daffodil/core/grammar/primitives/SequenceCombinator.scala
index 6a43d7a1b..8a7c59a6b 100644
--- 
a/daffodil-core/src/main/scala/org/apache/daffodil/core/grammar/primitives/SequenceCombinator.scala
+++ 
b/daffodil-core/src/main/scala/org/apache/daffodil/core/grammar/primitives/SequenceCombinator.scala
@@ -97,7 +97,7 @@ class OrderedSequence(sq: SequenceTermBase, 
sequenceChildrenArg: Seq[SequenceChi
         val nonUnparseableIfHidden = 
sq.groupMembers.filter(!_.canUnparseIfHidden)
         if (nonUnparseableIfHidden.nonEmpty) {
           SDE(
-            "Element(s) of hidden group must define dfdl:outputValueCalc, be 
defaultable or be optional:\n%s",
+            "Element(s) of hidden group must define dfdl:outputValueCalc, 
dfdl:inputValueCalc, be defaultable or be optional:\n%s",
             nonUnparseableIfHidden.mkString("\n")
           )
         }
@@ -189,7 +189,7 @@ class UnorderedSequence(
         val nonUnparseableIfHidden = 
sq.groupMembers.filter(!_.canUnparseIfHidden)
         if (nonUnparseableIfHidden.nonEmpty) {
           SDE(
-            "Element(s) of hidden group must define dfdl:outputValueCalc, be 
defaultable or be optional:\n%s",
+            "Element(s) of hidden group must define dfdl:outputValueCalc, 
dfdl:inputValueCalc, be defaultable or be optional:\n%s",
             nonUnparseableIfHidden.mkString("\n")
           )
         }
diff --git 
a/daffodil-core/src/main/scala/org/apache/daffodil/core/runtime1/ChoiceTermRuntime1Mixin.scala
 
b/daffodil-core/src/main/scala/org/apache/daffodil/core/runtime1/ChoiceTermRuntime1Mixin.scala
index 6d73297fd..890688812 100644
--- 
a/daffodil-core/src/main/scala/org/apache/daffodil/core/runtime1/ChoiceTermRuntime1Mixin.scala
+++ 
b/daffodil-core/src/main/scala/org/apache/daffodil/core/runtime1/ChoiceTermRuntime1Mixin.scala
@@ -115,7 +115,7 @@ trait ChoiceTermRuntime1Mixin { self: ChoiceTermBase =>
         optOpen.orElse {
           groupMembers.find {
             _.canUnparseIfHidden
-          } // optional, defaultable or OVC
+          } // optional, defaultable, OVC, or IVC
         }
       optDefault
     }
diff --git 
a/daffodil-test/src/test/resources/org/apache/daffodil/section14/sequence_groups/SequenceGroup.tdml
 
b/daffodil-test/src/test/resources/org/apache/daffodil/section14/sequence_groups/SequenceGroup.tdml
index e78be2727..b4b8d7552 100644
--- 
a/daffodil-test/src/test/resources/org/apache/daffodil/section14/sequence_groups/SequenceGroup.tdml
+++ 
b/daffodil-test/src/test/resources/org/apache/daffodil/section14/sequence_groups/SequenceGroup.tdml
@@ -1501,4 +1501,39 @@
     </tdml:infoset>
   </tdml:parserTestCase>
 
+  <tdml:defineSchema name="hiddenGroupIVC">
+    <xs:include 
schemaLocation="/org/apache/daffodil/xsd/DFDLGeneralFormat.dfdl.xsd"/>
+    <dfdl:format ref="ex:GeneralFormat" lengthKind="delimited" />
+
+    <xs:group name="hg">
+      <xs:sequence>
+        <xs:element name="original" type="xs:int" dfdl:outputValueCalc="{ 
(../ex:value - 1) div 2 }" />
+        <xs:element name="transformed" type="xs:int" dfdl:inputValueCalc="{ 
../ex:original * 2 }" />
+      </xs:sequence>
+    </xs:group>
+
+    <xs:element name="e" dfdl:lengthKind="delimited">
+      <xs:complexType>
+        <xs:sequence>
+          <xs:sequence dfdl:hiddenGroupRef="ex:hg" />
+          <xs:element name="value" type="xs:int" dfdl:inputValueCalc="{ 
../ex:transformed + 1 }" />
+        </xs:sequence>
+      </xs:complexType>
+    </xs:element>
+  </tdml:defineSchema>
+
+  <tdml:parserTestCase name="hiddenGroupIVC" root="e"
+    model="hiddenGroupIVC" description="Section 14 - Groups - DFDL-14-042R">
+    <tdml:document>
+      <tdml:documentPart type="text"><![CDATA[3]]></tdml:documentPart>
+    </tdml:document>
+    <tdml:infoset>
+      <tdml:dfdlInfoset>
+        <e>
+          <value>7</value>
+        </e>
+      </tdml:dfdlInfoset>
+    </tdml:infoset>
+  </tdml:parserTestCase>
+
 </tdml:testSuite>
diff --git 
a/daffodil-test/src/test/scala/org/apache/daffodil/section14/sequence_groups/TestSequenceGroups.scala
 
b/daffodil-test/src/test/scala/org/apache/daffodil/section14/sequence_groups/TestSequenceGroups.scala
index 9bdeb771f..819d0fc2e 100644
--- 
a/daffodil-test/src/test/scala/org/apache/daffodil/section14/sequence_groups/TestSequenceGroups.scala
+++ 
b/daffodil-test/src/test/scala/org/apache/daffodil/section14/sequence_groups/TestSequenceGroups.scala
@@ -142,4 +142,6 @@ class TestSequenceGroups {
   @Test def test_delimiterScanning_01(): Unit = { 
runner_01.runOneTest("delimiterScanning_01") }
   @Test def test_delimiterScanning_02(): Unit = { 
runner_01.runOneTest("delimiterScanning_02") }
   // @Test def test_delimiterScanning_03() { 
runner_01.runOneTest("delimiterScanning_03") }
+
+  @Test def test_hiddenGroupIVC(): Unit = { 
runner_02.runOneTest("hiddenGroupIVC") }
 }

Reply via email to