jadams-tresys commented on code in PR #1652:
URL: https://github.com/apache/daffodil/pull/1652#discussion_r3373829199


##########
daffodil-core/src/main/scala/org/apache/daffodil/core/grammar/ElementBaseGrammarMixin.scala:
##########
@@ -254,45 +254,55 @@ trait ElementBaseGrammarMixin
   final lazy val prefixedLengthBody = prefixedLengthElementDecl.parsedValue
 
   def checkEndOfParentRestrictionsOnCurrentElement(optParentELU: 
Option[LengthUnits]): Unit = {
+    Assert.invariant(optParentELU.isDefined)
+    val parentELU = optParentELU.get
     val currentElement: ElementBase = this
-    if (currentElement.lengthKind != LengthKind.EndOfParent) {} else {
-      schemaDefinitionWhen(
-        currentElement.hasTerminator,
-        "element is specified as dfdl:lengthKind=\"endOfParent\", but 
specifies a dfdl:terminator."
-      )
-      schemaDefinitionWhen(
-        currentElement.trailingSkip != 0,
-        "element is specified as dfdl:lengthKind=\"endOfParent\", but 
specifies a non-zero dfdl:trailingSkip."
-      )
-      schemaDefinitionWhen(
-        currentElement.maxOccurs > 1,
-        "element is specified as dfdl:lengthKind=\"endOfParent\", but 
specifies a maxOccurs greater than 1."
-      )
+    Assert.invariant(currentElement.lengthKind == LengthKind.EndOfParent)
+    schemaDefinitionWhen(
+      currentElement.hasTerminator,
+      "element is specified as dfdl:lengthKind=\"endOfParent\", but specifies 
a dfdl:terminator."
+    )
+    schemaDefinitionWhen(
+      currentElement.trailingSkip != 0,
+      "element is specified as dfdl:lengthKind=\"endOfParent\", but specifies 
a non-zero dfdl:trailingSkip."
+    )
+    schemaDefinitionWhen(
+      currentElement.maxOccurs > 1,
+      "element is specified as dfdl:lengthKind=\"endOfParent\", but specifies 
a maxOccurs greater than 1."
+    )
+    schemaDefinitionWhen(
+      currentElement.impliedRepresentation == Representation.Text
+        && (!currentElement.isKnownEncoding || 
!currentElement.knownEncodingIsFixedWidth || 
currentElement.knownEncodingWidthInBits != 8)
+        && (parentELU != LengthUnits.Characters),
+      "element is specified as dfdl:lengthKind=\"endOfParent\", but the 
element has text representation, and does not have a single-byte character set 
encoding, and the effective length units of the parent is not 'characters'."
+    )
+    if (currentElement.isSimpleType) {
+      val meetsSimpleTypeRestrictions = (currentElement.primType eq 
PrimType.String)
+        || (currentElement.representation == Representation.Text)
+        || (currentElement.primType eq PrimType.HexBinary)
+        || (currentElement.representation == Representation.Binary
+          && ((currentElement.binaryNumberRep match {
+            case BinaryNumberRep.Packed => true
+            case BinaryNumberRep.Bcd => true
+            case BinaryNumberRep.Ibm4690Packed => true
+            case _ => false
+          }) || (
+            currentElement.optionBinaryCalendarRep match {
+              case Some(bcr) =>
+                bcr match {
+                  case BinaryCalendarRep.Packed => true
+                  case BinaryCalendarRep.Bcd => true
+                  case BinaryCalendarRep.Ibm4690Packed => true
+                  case _ => false
+                }
+              case None =>
+                false // if no binary calendar rep, then we dont care about 
what it returns
+            }
+          )))
       schemaDefinitionWhen(

Review Comment:
   Thoughts on combining these 2 match cases to something like
   
   ```scala
   (currentElement.binaryNumberRep, 
currentElement.optionBinaryCalendarRep.getOrElse(BinaryCalendarRep.BinarySeconds))
 match {
     case (BinaryNumberRep.Packed | BinaryNumberRep.Bcd | 
BinaryNumberRep.Ibm4690Packed,  _) => true
     case (_, BinaryCalendarRep.Packed | BinaryCalendarRep.Bcd | 
BinaryCalendarRep.Ibm4690Packed) => true
     case (_, _) => false
   }
   ```



-- 
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.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to