You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@daffodil.apache.org by "olabusayoT (via GitHub)" <gi...@apache.org> on 2025/10/03 19:57:17 UTC

[PR] Fix test for trailingEmptyStrict policy validation [daffodil]

olabusayoT opened a new pull request, #1569:
URL: https://github.com/apache/daffodil/pull/1569

   - Resolved issues with trailingEmptyStrict violation when maxOccurs is '3' by improving checks for empty trailing optional elements.
   - Refactored code to introduce helper functions for error generation and condition checks.
   
   DAFFODIL-2217


-- 
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: commits-unsubscribe@daffodil.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Fix test for trailingEmptyStrict policy validation [daffodil]

Posted by "olabusayoT (via GitHub)" <gi...@apache.org>.
olabusayoT merged PR #1569:
URL: https://github.com/apache/daffodil/pull/1569


-- 
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: commits-unsubscribe@daffodil.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Fix test for trailingEmptyStrict policy validation [daffodil]

Posted by "mbeckerle (via GitHub)" <gi...@apache.org>.
mbeckerle commented on code in PR #1569:
URL: https://github.com/apache/daffodil/pull/1569#discussion_r2403239955


##########
daffodil-core/src/main/scala/org/apache/daffodil/runtime1/processors/parsers/SeparatedSequenceChildParseResultHelper.scala:
##########
@@ -126,17 +126,35 @@ trait SeparatedSequenceChildParseResultHelper extends SequenceChildParseResultHe
   ): Unit = {
 
     if ((sscb eq PositionalTrailingStrict)) {
-      val resultToTest = priorResultOfTry
-      resultToTest match {
-        case ParseAttemptStatus.AbsentRep | ParseAttemptStatus.EmptyRep =>
-          parser.PE(
-            pstate,
-            "Empty trailing optional elements are not allowed when dfdl:separatorSuppressionPolicy='trailingEmptyStrict'"
-          )
-        case _ => // ok
+      if (checkTrailingOptionalElements(resultOfTry)) {

Review Comment:
   Add comments to explain why you need to check first resultOfTry and then priorResultOfTry. Capture some of the reasoning from our debug session. 



-- 
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: commits-unsubscribe@daffodil.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Fix test for trailingEmptyStrict policy validation [daffodil]

Posted by "stevedlawrence (via GitHub)" <gi...@apache.org>.
stevedlawrence commented on code in PR #1569:
URL: https://github.com/apache/daffodil/pull/1569#discussion_r2406185613


##########
daffodil-core/src/main/scala/org/apache/daffodil/runtime1/processors/parsers/SeparatedSequenceChildParseResultHelper.scala:
##########
@@ -126,17 +126,35 @@ trait SeparatedSequenceChildParseResultHelper extends SequenceChildParseResultHe
   ): Unit = {
 
     if ((sscb eq PositionalTrailingStrict)) {
-      val resultToTest = priorResultOfTry
-      resultToTest match {
-        case ParseAttemptStatus.AbsentRep | ParseAttemptStatus.EmptyRep =>
-          parser.PE(
-            pstate,
-            "Empty trailing optional elements are not allowed when dfdl:separatorSuppressionPolicy='trailingEmptyStrict'"
-          )
-        case _ => // ok
+      if (checkTrailingOptionalElements(resultOfTry)) {
+        ParseErrorEmptyTrailingStrict(parser, pstate)
+      } else if (checkTrailingOptionalElements(priorResultOfTry)) {
+        ParseErrorEmptyTrailingStrict(parser, pstate)

Review Comment:
   The blocks of these two if statements are the same, I would suggest just doing something like:
   
   ```scala
   if (checkTrailingOptionalElements(resultOfTry) || checkTrailingOptionalElements(priorResultOfTry) {
     parser.PE(...)
   }
   ```



##########
daffodil-core/src/main/scala/org/apache/daffodil/runtime1/processors/parsers/SeparatedSequenceChildParseResultHelper.scala:
##########
@@ -126,17 +126,35 @@ trait SeparatedSequenceChildParseResultHelper extends SequenceChildParseResultHe
   ): Unit = {
 
     if ((sscb eq PositionalTrailingStrict)) {
-      val resultToTest = priorResultOfTry
-      resultToTest match {
-        case ParseAttemptStatus.AbsentRep | ParseAttemptStatus.EmptyRep =>
-          parser.PE(
-            pstate,
-            "Empty trailing optional elements are not allowed when dfdl:separatorSuppressionPolicy='trailingEmptyStrict'"
-          )
-        case _ => // ok
+      if (checkTrailingOptionalElements(resultOfTry)) {
+        ParseErrorEmptyTrailingStrict(parser, pstate)
+      } else if (checkTrailingOptionalElements(priorResultOfTry)) {
+        ParseErrorEmptyTrailingStrict(parser, pstate)
+      } else {
+        // ok
       }
     }
   }
+
+  private def ParseErrorEmptyTrailingStrict(

Review Comment:
   I'm not sure this should be capitalized, it make its usage look like it's calling an object apply method.



##########
daffodil-core/src/main/scala/org/apache/daffodil/runtime1/processors/parsers/SeparatedSequenceChildParseResultHelper.scala:
##########
@@ -126,17 +126,35 @@ trait SeparatedSequenceChildParseResultHelper extends SequenceChildParseResultHe
   ): Unit = {
 
     if ((sscb eq PositionalTrailingStrict)) {
-      val resultToTest = priorResultOfTry
-      resultToTest match {
-        case ParseAttemptStatus.AbsentRep | ParseAttemptStatus.EmptyRep =>
-          parser.PE(
-            pstate,
-            "Empty trailing optional elements are not allowed when dfdl:separatorSuppressionPolicy='trailingEmptyStrict'"
-          )
-        case _ => // ok
+      if (checkTrailingOptionalElements(resultOfTry)) {
+        ParseErrorEmptyTrailingStrict(parser, pstate)
+      } else if (checkTrailingOptionalElements(priorResultOfTry)) {
+        ParseErrorEmptyTrailingStrict(parser, pstate)
+      } else {
+        // ok
       }
     }
   }
+
+  private def ParseErrorEmptyTrailingStrict(
+    parser: SequenceChildParser,
+    pstate: PState
+  ): Unit = {
+    parser.PE(
+      pstate,
+      "Empty trailing optional elements are not allowed when dfdl:separatorSuppressionPolicy='trailingEmptyStrict'"
+    )
+  }
+
+  private def checkTrailingOptionalElements(
+    resultToTest: ParseAttemptStatus
+  ): Boolean = {
+    Seq(
+      ParseAttemptStatus.MissingItem,
+      ParseAttemptStatus.AbsentRep,
+      ParseAttemptStatus.EmptyRep
+    ).contains(resultToTest)
+  }

Review Comment:
   Having a comment here would be helpful to. MIssing and Absent are both types of Failure parse status, so I would think that indicates error. But I guess because these are optional trailing elements those are not considered errors?



##########
daffodil-core/src/main/scala/org/apache/daffodil/runtime1/processors/parsers/SeparatedSequenceChildParseResultHelper.scala:
##########
@@ -126,17 +126,35 @@ trait SeparatedSequenceChildParseResultHelper extends SequenceChildParseResultHe
   ): Unit = {
 
     if ((sscb eq PositionalTrailingStrict)) {
-      val resultToTest = priorResultOfTry
-      resultToTest match {
-        case ParseAttemptStatus.AbsentRep | ParseAttemptStatus.EmptyRep =>
-          parser.PE(
-            pstate,
-            "Empty trailing optional elements are not allowed when dfdl:separatorSuppressionPolicy='trailingEmptyStrict'"
-          )
-        case _ => // ok
+      if (checkTrailingOptionalElements(resultOfTry)) {

Review Comment:
   Yeah, I think a comment explaining this is really important.
   
   For example, why do we need to check both resultOfTry *AND* priorResultOfTry? My intuition is only the most recently parsed thing should matter for trailing empty since we only care about the trailing thing.
   
   Also, why is this only checked for trailingEmptyStrict? Why do we not need to check for other thingslike PositionTrailingLax? 



-- 
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: commits-unsubscribe@daffodil.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org