stevedlawrence commented on a change in pull request #262: Unordered sequences
URL: https://github.com/apache/incubator-daffodil/pull/262#discussion_r324001890
 
 

 ##########
 File path: 
daffodil-runtime1/src/main/scala/org/apache/daffodil/processors/parsers/SequenceParserBases.scala
 ##########
 @@ -30,24 +36,58 @@ import org.apache.daffodil.processors.TermRuntimeData
 import org.apache.daffodil.processors.Failure
 import org.apache.daffodil.processors.ModelGroupRuntimeData
 
+abstract class UnorderedSequenceParserBase(
+  srd: SequenceRuntimeData,
+  choiceParser: ChoiceParser)
+  extends SequenceParserBase(srd, Vector(choiceParser)) {
+
+  override protected def parse(pstate: PState) = {
+
+    var isDone = false
+
+    while (!isDone && (pstate.processorStatus eq Success)) {
+      val priorPos = pstate.bitPos0b
+      choiceParser.parse(pstate)
+      val currentPos = pstate.bitPos0b
+
+      if ((pstate.processorStatus eq Success) && (currentPos <= priorPos)) {
+        isDone = true
+      }
+    }
+
+    pstate.setSuccess()
+    val erds = 
pstate.infoset.asInstanceOf[DIComplex].flattenAndValidateChildNodes()
+    pstate.infoset.asInstanceOf[DIComplex].sortChildNodesByPosition()
+
+    // We have encountered a min/maxOccurs validation error
+    if (erds.isDefined) {
+      erds.get.foreach(e => {
+        val min = e.minOccurs
+        val max = e.maxOccurs
+        val isUnbounded = max == -1
+
+        if (isUnbounded)
+          pstate.validationError("Element %s failed check of minOccurs='%s' 
and maxOccurs='UNBOUNDED", e.diagnosticDebugName, min)
+        else
+          pstate.validationError("Element %s failed check of minOccurs='%s' 
and maxOccurs='%s'", e.diagnosticDebugName, min, max)
+      })
 
 Review comment:
   WOuld be nice to include the number of occurrences in the validation 
message. Also should "UNBOUNDED" be lowercase? If this logic could be moved to 
the infoset you would have the num of occurrences too.

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