stevedlawrence commented on a change in pull request #214: Sequences and 
Separators Refactoring and Rewrite
URL: https://github.com/apache/incubator-daffodil/pull/214#discussion_r285125748
 
 

 ##########
 File path: 
daffodil-core/src/main/scala/org/apache/daffodil/dsom/LocalElementMixin.scala
 ##########
 @@ -74,20 +74,42 @@ trait LocalElementMixin
     res
   }.value
 
-  final override def hasKnownRequiredSyntax: Boolean = 
LV('hasKnownRequiredSyntax) {
-    !couldBeMissing
-  }.value
+  final override def hasKnownRequiredSyntax: Boolean = !couldBeMissing
 
-  final def couldBeMissing: Boolean = LV('couldBeMissing) {
+  final lazy val couldBeMissing: Boolean = LV('couldBeMissing) {
     val res =
       if (minOccurs == 0) true
       else if (isNillable && !hasNilValueRequiredSyntax) true
       else if (isDefaultable && emptyValueDelimiterPolicy =:= 
EmptyValueDelimiterPolicy.None) true
       else if (isDefaultable && !hasInitiator && emptyValueDelimiterPolicy =:= 
EmptyValueDelimiterPolicy.Initiator) true
       else if (isDefaultable && !hasTerminator && emptyValueDelimiterPolicy 
=:= EmptyValueDelimiterPolicy.Terminator) true
-      else if (hasInitiator) false
-      else if (hasTerminator) false
-      else if (isSimpleType) {
+      else if (hasInitiator) {
+        //
+        // TODO: It is possible that this constant expression cannot match 
zero length
+        // or that it can match zero length. We don't really know without 
analyzing it.
+        // The easiest way may be at compile time to try matching it against 
an empty string.
+        // That would tell us whether it requires input or not.
+        //
+        // For now we just assume if it has an initiator, then it can't be 
missing.
+        false
+      } else if (hasTerminator) {
+        // If the lengthKind is NOT delimited, then the terminator is 
potentially redundant and
+        // there are real formats (mil-std-2045) where the terminator is an 
expression, but that expression
+        // returns %WSP*; or %ES;, meaning the terminator can match zero 
length.
+        if (!terminatorExpr.isConstant && (lengthKind ne 
LengthKind.Delimited)) {
+          //
+          // It seems like we could do better here if we actually looked at 
the expression to see
+          // if it can be zero length. But we don't necessarily know because 
the expression could
+          // refer to other infoset contents
+          true // this is in fact the case for mil-std-2045 tString32 type. It 
uses the length of another element to decide
 
 Review comment:
   Weird to have true in the middle of a comment.

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

Reply via email to