stevedlawrence closed pull request #154: Allow lengthUnits to differ for 
element and its prefixed length
URL: https://github.com/apache/incubator-daffodil/pull/154
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git 
a/daffodil-core/src/main/scala/org/apache/daffodil/grammar/ElementBaseGrammarMixin.scala
 
b/daffodil-core/src/main/scala/org/apache/daffodil/grammar/ElementBaseGrammarMixin.scala
index 48b140845..553529b4c 100644
--- 
a/daffodil-core/src/main/scala/org/apache/daffodil/grammar/ElementBaseGrammarMixin.scala
+++ 
b/daffodil-core/src/main/scala/org/apache/daffodil/grammar/ElementBaseGrammarMixin.scala
@@ -207,48 +207,73 @@ trait ElementBaseGrammarMixin
     // because we need to create a detached element with the same schema
     // document/parent of the GSTD.
     val prefixLengthTypeGSTD = 
schemaSet.getGlobalSimpleTypeDef(prefixLengthType).getOrElse(
-      schemaDefinitionError("Failed to resolve dfdl:prefixLengthType=\"%s\" to 
a simpleType", prefixLengthType.toQNameString)
+      schemaDefinitionError(
+        "Failed to resolve dfdl:prefixLengthType=\"%s\" to a simpleType",
+        prefixLengthType.toQNameString)
     )
 
-    val detachedNode = <element name={ name + " (prefixLength)" } type={ 
prefixLengthType.toQNameString } />.copy(scope = prefixLengthTypeGSTD.xml.scope)
-    val detachedElementDecl = new DetachedElementDecl(this, detachedNode, 
prefixLengthTypeGSTD.parent)
+    val detachedNode =
+      <element name={ name + " (prefixLength)" } type={ 
prefixLengthType.toQNameString } />
+        .copy(scope = prefixLengthTypeGSTD.xml.scope)
+    val detachedElementDecl =
+      new DetachedElementDecl(this, detachedNode, prefixLengthTypeGSTD.parent)
 
     val prefixedLengthKind = detachedElementDecl.lengthKind
     prefixedLengthKind match {
       case LengthKind.Delimited | LengthKind.EndOfParent | LengthKind.Pattern 
=>
-        schemaDefinitionError("%s is specified as a dfdl:prefixLengthType, but 
has a dfdl:lengthKind of %s", prefixLengthType, prefixedLengthKind)
+        schemaDefinitionError(
+          "%s is specified as a dfdl:prefixLengthType, but has a 
dfdl:lengthKind of %s",
+          prefixLengthType,
+          prefixedLengthKind)
       case LengthKind.Explicit if 
detachedElementDecl.optLengthConstant.isEmpty =>
-        schemaDefinitionError("%s is specified as a dfdl:prefixLengthType, but 
has an expression for dfdl:length", prefixLengthType)
-      case LengthKind.Implicit | LengthKind.Explicit if lengthUnits != 
detachedElementDecl.lengthUnits =>
-        schemaDefinitionError("%s is specified as a dfdl:prefixLengthType with 
dfdl:lengthKind %s, but has different dfdl:lengthUnits than the element", 
prefixLengthType, prefixedLengthKind)
+        schemaDefinitionError(
+          "%s is specified as a dfdl:prefixLengthType, but has an expression 
for dfdl:length",
+          prefixLengthType)
+      case LengthKind.Implicit | LengthKind.Explicit if 
prefixIncludesPrefixLength == YesNo.Yes &&
+        lengthUnits != detachedElementDecl.lengthUnits =>
+          schemaDefinitionError(
+            "%s is specified as a dfdl:prefixLengthType where 
dfdl:prefixIncludesPrefixLength=\"yes\" " +
+            "with dfdl:lengthKind %s, but has different dfdl:lengthUnits than 
the element",
+            prefixLengthType,
+            prefixedLengthKind)
       case _ =>
     }
 
     
schemaDefinitionUnless(detachedElementDecl.primType.isSubtypeOf(NodeInfo.Integer),
-      "%s is specified as a dfdl:prefixLengthType, but its type xs:%s is not a 
subtype of xs:integer", prefixLengthType, 
detachedElementDecl.primType.toString.toLowerCase)
+      "%s is specified as a dfdl:prefixLengthType, but its type xs:%s is not a 
subtype of xs:integer",
+      prefixLengthType,
+      detachedElementDecl.primType.toString.toLowerCase)
 
     schemaDefinitionWhen(detachedElementDecl.isOutputValueCalc,
-      "%s is specified as a dfdl:prefixLengthType, but specifies 
dfdl:outputValueCalc", prefixLengthType)
+      "%s is specified as a dfdl:prefixLengthType, but specifies 
dfdl:outputValueCalc",
+      prefixLengthType)
     schemaDefinitionWhen(detachedElementDecl.hasInitiator,
-      "%s is specified as a dfdl:prefixLengthType, but specifies a 
dfdl:initiator", prefixLengthType)
+      "%s is specified as a dfdl:prefixLengthType, but specifies a 
dfdl:initiator",
+      prefixLengthType)
     schemaDefinitionWhen(detachedElementDecl.hasTerminator,
-      "%s is specified as a dfdl:prefixLengthType, but specifies a 
dfdl:terminator", prefixLengthType)
+      "%s is specified as a dfdl:prefixLengthType, but specifies a 
dfdl:terminator",
+      prefixLengthType)
     schemaDefinitionWhen(detachedElementDecl.alignment != 1,
-      "%s is specified as a dfdl:prefixLengthType, but specifies a 
dfdl:alignment other than 1", prefixLengthType)
+      "%s is specified as a dfdl:prefixLengthType, but specifies a 
dfdl:alignment other than 1",
+      prefixLengthType)
     schemaDefinitionWhen(detachedElementDecl.leadingSkip != 0,
-      "%s is specified as a dfdl:prefixLengthType, but specifies a 
dfdl:leadingSkip other than 0", prefixLengthType)
+      "%s is specified as a dfdl:prefixLengthType, but specifies a 
dfdl:leadingSkip other than 0",
+      prefixLengthType)
     schemaDefinitionWhen(detachedElementDecl.trailingSkip != 0,
-      "%s is specified as a dfdl:prefixLengthType, but specifies a 
dfdl:trailingSkip other than 0", prefixLengthType)
+      "%s is specified as a dfdl:prefixLengthType, but specifies a 
dfdl:trailingSkip other than 0",
+      prefixLengthType)
 
     if (detachedElementDecl.lengthKind == LengthKind.Prefixed &&
         detachedElementDecl.prefixedLengthElementDecl.lengthKind == 
LengthKind.Prefixed) {
         schemaDefinitionError("Nesting level for dfdl:prefixLengthType exceeds 
1: %s > %s > %s > %s",
-          name, prefixLengthType,
+          name,
+          prefixLengthType,
           detachedElementDecl.prefixLengthType,
           detachedElementDecl.prefixedLengthElementDecl.prefixLengthType)
     }
 
-    subset(detachedElementDecl.lengthKind != LengthKind.Prefixed, "Nested 
dfdl:lengthKind=\"prefixed\" is not supported.")
+    subset(detachedElementDecl.lengthKind != LengthKind.Prefixed,
+      "Nested dfdl:lengthKind=\"prefixed\" is not supported.")
 
     detachedElementDecl
   }
diff --git 
a/daffodil-test/src/test/resources/org/apache/daffodil/section12/lengthKind/PrefixedTests.tdml
 
b/daffodil-test/src/test/resources/org/apache/daffodil/section12/lengthKind/PrefixedTests.tdml
index e451a426f..10a6f97b6 100644
--- 
a/daffodil-test/src/test/resources/org/apache/daffodil/section12/lengthKind/PrefixedTests.tdml
+++ 
b/daffodil-test/src/test/resources/org/apache/daffodil/section12/lengthKind/PrefixedTests.tdml
@@ -121,6 +121,33 @@
     <xs:element name="pl_text_int_bin_bytes" type="xs:int" 
dfdl:ref="prefixedBinByte" />
     <xs:element name="pl_text_int_bin_bits" type="xs:int" 
dfdl:ref="prefixedBinBits" />
 
+
+    <xs:element name="pl_text_int_txt_bytes_plbits" type="xs:int" 
dfdl:ref="prefixedTxtByte"
+      dfdl:prefixLengthType="ex:twentyFourBitsTextInt" />
+    <xs:element name="pl_text_int_txt_bytes_plchars" type="xs:int" 
dfdl:ref="prefixedTxtByte"
+      dfdl:prefixLengthType="ex:threeCharTextInt" />
+
+    <xs:element name="pl_text_int_txt_bits_plbytes" type="xs:int" 
dfdl:ref="prefixedTxtBits"
+      dfdl:prefixLengthType="ex:threeByteTextInt" />
+    <xs:element name="pl_text_int_txt_bits_plchars" type="xs:int" 
dfdl:ref="prefixedTxtBits"
+      dfdl:prefixLengthType="ex:threeCharTextInt" />
+
+    <xs:element name="pl_text_int_txt_chars_plbits" type="xs:int" 
dfdl:ref="prefixedTxtChar"
+      dfdl:prefixLengthType="ex:twentyFourBitsTextInt"
+      daf:parseUnparsePolicy="parseOnly" />
+    <xs:element name="pl_text_int_txt_chars_plbytes" type="xs:int" 
dfdl:ref="prefixedTxtChar"
+      dfdl:prefixLengthType="ex:threeCharTextInt"
+      daf:parseUnparsePolicy="parseOnly" />
+
+    <xs:element name="pl_text_int_bin_bytes_plbits" type="xs:int" 
dfdl:ref="prefixedBinByte"
+      dfdl:prefixLengthType="ex:twentyFourBitsBinInt" />
+    <xs:element name="pl_text_int_bin_bytes_plchars" type="xs:int" 
dfdl:ref="prefixedBinByte"
+      dfdl:prefixLengthType="ex:threeCharTextInt" />
+    <xs:element name="pl_text_int_bin_bits_plbytes" type="xs:int" 
dfdl:ref="prefixedBinBits"
+      dfdl:prefixLengthType="ex:threeByteBinInt" />
+    <xs:element name="pl_text_int_bin_bits_plchars" type="xs:int" 
dfdl:ref="prefixedBinBits"
+      dfdl:prefixLengthType="ex:threeCharTextInt" />
+
     <xs:element name="pl_text_int_txt_bytes_includes" type="xs:int" 
dfdl:ref="prefixedTxtByte"
       dfdl:prefixIncludesPrefixLength="yes" />
     <xs:element name="pl_text_int_txt_bits_includes" type="xs:int" 
dfdl:ref="prefixedTxtBits"
@@ -495,7 +522,7 @@
     <xs:element name="pl_trailingskip" type="xs:string" 
dfdl:lengthKind="prefixed"
       dfdl:prefixLengthType="ex:prefixTrailingSkip" />
     <xs:element name="pl_lengthunits" type="xs:string" 
dfdl:lengthKind="prefixed"
-      dfdl:prefixLengthType="ex:prefixLengthUnits" />
+      dfdl:prefixLengthType="ex:prefixLengthUnits" 
dfdl:prefixIncludesPrefixLength="yes" />
     <xs:element name="pl_nest" type="xs:string" dfdl:lengthKind="prefixed"
       dfdl:prefixLengthType="ex:prefixLengthNest1" />
     <xs:element name="pl_decimal" type="xs:string" dfdl:lengthKind="prefixed"
@@ -847,6 +874,154 @@
     </tdml:infoset>
   </tdml:parserTestCase>
 
+  <tdml:parserTestCase name="pl_text_int_txt_bytes_plbits" roundTrip="twoPass"
+    root="pl_text_int_txt_bytes_plbits"
+    model="lengthKindPrefixed-text.dfdl.xsd">
+    <tdml:document>
+      <tdml:documentPart type="text">002</tdml:documentPart>
+      <tdml:documentPart type="text">12</tdml:documentPart>
+    </tdml:document>
+    <tdml:infoset>
+      <tdml:dfdlInfoset>
+        <pl_text_int_txt_bytes_plbits>12</pl_text_int_txt_bytes_plbits>
+      </tdml:dfdlInfoset>
+    </tdml:infoset>
+  </tdml:parserTestCase>
+
+  <tdml:parserTestCase name="pl_text_int_txt_bytes_plchars" roundTrip="twoPass"
+    root="pl_text_int_txt_bytes_plchars"
+    model="lengthKindPrefixed-text.dfdl.xsd">
+    <tdml:document>
+      <tdml:documentPart type="text">002</tdml:documentPart>
+      <tdml:documentPart type="text">12</tdml:documentPart>
+    </tdml:document>
+    <tdml:infoset>
+      <tdml:dfdlInfoset>
+        <pl_text_int_txt_bytes_plchars>12</pl_text_int_txt_bytes_plchars>
+      </tdml:dfdlInfoset>
+    </tdml:infoset>
+  </tdml:parserTestCase>
+
+  <tdml:parserTestCase name="pl_text_int_txt_bits_plbytes" roundTrip="twoPass"
+    root="pl_text_int_txt_bits_plbytes"
+    model="lengthKindPrefixed-text.dfdl.xsd">
+    <tdml:document>
+      <tdml:documentPart type="text">016</tdml:documentPart>
+      <tdml:documentPart type="text">12</tdml:documentPart>
+    </tdml:document>
+    <tdml:infoset>
+      <tdml:dfdlInfoset>
+        <pl_text_int_txt_bits_plbytes>12</pl_text_int_txt_bits_plbytes>
+      </tdml:dfdlInfoset>
+    </tdml:infoset>
+  </tdml:parserTestCase>
+
+  <tdml:parserTestCase name="pl_text_int_txt_bits_plchars" roundTrip="twoPass"
+    root="pl_text_int_txt_bits_plchars"
+    model="lengthKindPrefixed-text.dfdl.xsd">
+    <tdml:document>
+      <tdml:documentPart type="text">016</tdml:documentPart>
+      <tdml:documentPart type="text">12</tdml:documentPart>
+    </tdml:document>
+    <tdml:infoset>
+      <tdml:dfdlInfoset>
+        <pl_text_int_txt_bits_plchars>12</pl_text_int_txt_bits_plchars>
+      </tdml:dfdlInfoset>
+    </tdml:infoset>
+  </tdml:parserTestCase>
+
+  <!--
+    DAFFODIL-2029: Cannot roundTrip due to unimplemented unparsing with
+    dfdl:lengthKind="prefixed" and dfdl:lengthUnits="characters"
+  -->
+  <tdml:parserTestCase name="pl_text_int_txt_chars_plbits" roundTrip="false"
+    root="pl_text_int_txt_chars_plbits"
+    model="lengthKindPrefixed-text.dfdl.xsd">
+    <tdml:document>
+      <tdml:documentPart type="text">002</tdml:documentPart>
+      <tdml:documentPart type="text">12</tdml:documentPart>
+    </tdml:document>
+    <tdml:infoset>
+      <tdml:dfdlInfoset>
+        <pl_text_int_txt_chars_plbits>12</pl_text_int_txt_chars_plbits>
+      </tdml:dfdlInfoset>
+    </tdml:infoset>
+  </tdml:parserTestCase>
+
+  <!--
+    DAFFODIL-2029: Cannot roundTrip due to unimplemented unparsing with
+    dfdl:lengthKind="prefixed" and dfdl:lengthUnits="characters"
+  -->
+  <tdml:parserTestCase name="pl_text_int_txt_chars_plbytes" roundTrip="false"
+    root="pl_text_int_txt_chars_plbytes"
+    model="lengthKindPrefixed-text.dfdl.xsd">
+    <tdml:document>
+      <tdml:documentPart type="text">002</tdml:documentPart>
+      <tdml:documentPart type="text">12</tdml:documentPart>
+    </tdml:document>
+    <tdml:infoset>
+      <tdml:dfdlInfoset>
+        <pl_text_int_txt_chars_plbytes>12</pl_text_int_txt_chars_plbytes>
+      </tdml:dfdlInfoset>
+    </tdml:infoset>
+  </tdml:parserTestCase>
+
+  <tdml:parserTestCase name="pl_text_int_bin_bytes_plbits"
+    root="pl_text_int_bin_bytes_plbits"
+    model="lengthKindPrefixed-text.dfdl.xsd">
+    <tdml:document>
+      <tdml:documentPart type="byte">00 00 02</tdml:documentPart>
+      <tdml:documentPart type="text">12</tdml:documentPart>
+    </tdml:document>
+    <tdml:infoset>
+      <tdml:dfdlInfoset>
+        <pl_text_int_bin_bytes_plbits>12</pl_text_int_bin_bytes_plbits>
+      </tdml:dfdlInfoset>
+    </tdml:infoset>
+  </tdml:parserTestCase>
+
+  <tdml:parserTestCase name="pl_text_int_bin_bytes_plchars" roundTrip="twoPass"
+    root="pl_text_int_bin_bytes_plchars"
+    model="lengthKindPrefixed-text.dfdl.xsd">
+    <tdml:document>
+      <tdml:documentPart type="text">002</tdml:documentPart>
+      <tdml:documentPart type="text">12</tdml:documentPart>
+    </tdml:document>
+    <tdml:infoset>
+      <tdml:dfdlInfoset>
+        <pl_text_int_bin_bytes_plchars>12</pl_text_int_bin_bytes_plchars>
+      </tdml:dfdlInfoset>
+    </tdml:infoset>
+  </tdml:parserTestCase>
+
+  <tdml:parserTestCase name="pl_text_int_bin_bits_plbytes"
+    root="pl_text_int_bin_bits_plbytes"
+    model="lengthKindPrefixed-text.dfdl.xsd">
+    <tdml:document>
+      <tdml:documentPart type="byte">00 00 10</tdml:documentPart>
+      <tdml:documentPart type="text">12</tdml:documentPart>
+    </tdml:document>
+    <tdml:infoset>
+      <tdml:dfdlInfoset>
+        <pl_text_int_bin_bits_plbytes>12</pl_text_int_bin_bits_plbytes>
+      </tdml:dfdlInfoset>
+    </tdml:infoset>
+  </tdml:parserTestCase>
+
+  <tdml:parserTestCase name="pl_text_int_bin_bits_plchars" roundTrip="twoPass"
+    root="pl_text_int_bin_bits_plchars"
+    model="lengthKindPrefixed-text.dfdl.xsd">
+    <tdml:document>
+      <tdml:documentPart type="text">016</tdml:documentPart>
+      <tdml:documentPart type="text">12</tdml:documentPart>
+    </tdml:document>
+    <tdml:infoset>
+      <tdml:dfdlInfoset>
+        <pl_text_int_bin_bits_plchars>12</pl_text_int_bin_bits_plchars>
+      </tdml:dfdlInfoset>
+    </tdml:infoset>
+  </tdml:parserTestCase>
+
   <tdml:parserTestCase name="pl_text_int_txt_bytes_includes" 
roundTrip="twoPass"
     root="pl_text_int_txt_bytes_includes"
     model="lengthKindPrefixed-text.dfdl.xsd">
@@ -1947,6 +2122,7 @@
     <tdml:errors>
       <tdml:error>Schema Definition Error</tdml:error>
       <tdml:error>ex:prefixLengthUnits</tdml:error>
+      <tdml:error>dfdl:prefixIncludesPrefixLength="yes"</tdml:error>
       <tdml:error>dfdl:prefixLengthType</tdml:error>
       <tdml:error>dfdl:lengthUnits</tdml:error>
     </tdml:errors>
diff --git 
a/daffodil-test/src/test/scala/org/apache/daffodil/section12/lengthKind/TestLengthKindPrefixed.scala
 
b/daffodil-test/src/test/scala/org/apache/daffodil/section12/lengthKind/TestLengthKindPrefixed.scala
index c9d210293..aba09215c 100644
--- 
a/daffodil-test/src/test/scala/org/apache/daffodil/section12/lengthKind/TestLengthKindPrefixed.scala
+++ 
b/daffodil-test/src/test/scala/org/apache/daffodil/section12/lengthKind/TestLengthKindPrefixed.scala
@@ -81,6 +81,17 @@ class TestLengthKindPrefixed {
   @Test def test_pl_text_bool_bin_bytes() = { 
runner.runOneTest("pl_text_bool_bin_bytes") }
   @Test def test_pl_text_bool_bin_bits() = { 
runner.runOneTest("pl_text_bool_bin_bits") }
 
+  @Test def test_pl_text_int_txt_bytes_plbits() = { 
runner.runOneTest("pl_text_int_txt_bytes_plbits") }
+  @Test def test_pl_text_int_txt_bytes_plchars() = { 
runner.runOneTest("pl_text_int_txt_bytes_plchars") }
+  @Test def test_pl_text_int_txt_bits_plbytes() = { 
runner.runOneTest("pl_text_int_txt_bits_plbytes") }
+  @Test def test_pl_text_int_txt_bits_plchars() = { 
runner.runOneTest("pl_text_int_txt_bits_plchars") }
+  @Test def test_pl_text_int_txt_chars_plbits() = { 
runner.runOneTest("pl_text_int_txt_chars_plbits") }
+  @Test def test_pl_text_int_txt_chars_plbytes() = { 
runner.runOneTest("pl_text_int_txt_chars_plbytes") }
+  @Test def test_pl_text_int_bin_bytes_plbits() = { 
runner.runOneTest("pl_text_int_bin_bytes_plbits") }
+  @Test def test_pl_text_int_bin_bytes_plchars() = { 
runner.runOneTest("pl_text_int_bin_bytes_plchars") }
+  @Test def test_pl_text_int_bin_bits_plbytes() = { 
runner.runOneTest("pl_text_int_bin_bits_plbytes") }
+  @Test def test_pl_text_int_bin_bits_plchars() = { 
runner.runOneTest("pl_text_int_bin_bits_plchars") }
+
   @Test def test_pl_complex_bin_bytes() = { 
runner.runOneTest("pl_complex_bin_bytes") }
   @Test def test_pl_complex_bin_bits() = { 
runner.runOneTest("pl_complex_bin_bits") }
   @Test def test_pl_complex_bin_bytes_suspension() = { 
runner.runOneTest("pl_complex_bin_bytes_suspension") }


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on 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

Reply via email to