You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@daffodil.apache.org by GitBox <gi...@apache.org> on 2018/12/07 17:44:21 UTC

[GitHub] mbeckerle commented on a change in pull request #143: Support dfdl:length="prefixed"

mbeckerle commented on a change in pull request #143: Support dfdl:length="prefixed"
URL: https://github.com/apache/incubator-daffodil/pull/143#discussion_r239885864
 
 

 ##########
 File path: daffodil-core/src/main/scala/org/apache/daffodil/grammar/ElementBaseGrammarMixin.scala
 ##########
 @@ -187,6 +200,79 @@ trait ElementBaseGrammarMixin
       minLen > 0)
   }
 
+  final lazy val prefixedLengthElementDecl: DetachedElementDecl = {
+    Assert.invariant(lengthKind == LengthKind.Prefixed)
+
+    // We need to resolve the global simple type of the prefix length type
+    // 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)
+    )
+
+    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)
+      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)
+      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)
+
+    schemaDefinitionWhen(detachedElementDecl.isOutputValueCalc,
+      "%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)
+    schemaDefinitionWhen(detachedElementDecl.hasTerminator,
+      "%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)
+    schemaDefinitionWhen(detachedElementDecl.leadingSkip != 0,
+      "%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)
+
+    if (detachedElementDecl.lengthKind == LengthKind.Prefixed &&
+        detachedElementDecl.prefixedLengthElementDecl.lengthKind == LengthKind.Prefixed) {
+        schemaDefinitionError("Nesting level for dfdl:prefixLengthType exceeds 1: %s > %s > %s > %s",
+          name, prefixLengthType,
+          detachedElementDecl.prefixLengthType,
+          detachedElementDecl.prefixedLengthElementDecl.prefixLengthType)
+    }
+
+    subset(detachedElementDecl.lengthKind != LengthKind.Prefixed, "Nested dfdl:lengthKind=\"prefixed\" is not supported.")
+
+    detachedElementDecl
+  }
+  final lazy val prefixedLengthAdjustmentInUnits: Long = prefixIncludesPrefixLength match {
 
 Review comment:
   So, is this requiring the length prefix itself to be constant length? I think this needs to be an Evaluatable ultimately, since the length prefix simple type isn't necessarily of known fixed length itself.  Seems like an obscure corner case, and it *should* be that, but I think there are formats where the prefix length is a variable-length text number delimited by something. 

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services