olabusayoT commented on code in PR #1652:
URL: https://github.com/apache/daffodil/pull/1652#discussion_r3357222888


##########
daffodil-core/src/main/scala/org/apache/daffodil/core/grammar/TermGrammarMixin.scala:
##########
@@ -84,4 +96,181 @@ trait TermGrammarMixin extends AlignedMixin with 
BitOrderMixin with TermRuntime1
     MandatoryTextAlignment(this, knownEncodingAlignmentInBits, true)
   }
 
+  def myEffectiveLengthUnits(optLastNonEOPLU: Option[LengthUnits]): 
Option[LengthUnits] = {
+    val elu = this match {
+      case e: ElementBase =>
+        e.lengthKind match {
+          case LengthKind.EndOfParent => optLastNonEOPLU
+          case LengthKind.Explicit | LengthKind.Prefixed => Some(e.lengthUnits)
+          case LengthKind.Pattern => Some(LengthUnits.Characters)
+          case _ => None
+        }
+      case c: ChoiceTermBase if c.choiceLengthKind == 
ChoiceLengthKind.Explicit =>
+        Some(LengthUnits.Bytes)
+      // the spec doesn't actually account for this case, but logically it 
makes
+      // sense that ELU of a sequence is the ELU of its parent that 
technically is the
+      // last non-EndOfParent ELU.
+      case s: SequenceTermBase => optLastNonEOPLU
+      case _ => None
+    }
+    elu
+  }
+
+  final lazy val childrenEndOfParent: Seq[Term] = 
LV(Symbol("childrenEndOfParent")) {
+    val gms = termChildren
+    val chls = gms.flatMap {
+      case eb: ElementBase if eb.lengthKind == LengthKind.EndOfParent => 
Seq(eb)
+      case eb: ElementBase => Nil
+      case c: ChoiceTermBase => Nil
+      case mg: ModelGroup => mg.childrenEndOfParent
+    }
+    chls
+  }.value
+
+  def checkEndOfParentRestrictions(optLastNonEOPLU: Option[LengthUnits]): Unit 
= {
+    val term = this
+    lazy val eopChildren = this.childrenEndOfParent
+    // checks
+    term match {
+      case rootElem: Root if rootElem.lengthKind == LengthKind.EndOfParent => {
+        
rootElem.checkEndOfParentRestrictionsOnCurrentElement(Some(LengthUnits.Characters))
+        eopChildren.foreach {
+          case e: ElementBase => {
+            rootElem.checkChildrenForSiblingsAfterEOPElement(e)
+            Assert.invariant(
+              optLastNonEOPLU.isDefined,
+              "Effective Length Units of parent should not be None"
+            )
+            e.checkEndOfParentRestrictionsOnCurrentElement(optLastNonEOPLU)
+          }
+          case _ => // do nothing
+        }
+      }
+      case parent: ElementBase if eopChildren.nonEmpty => {

Review Comment:
   I don't think this can be done cleanly as the two cases answer different 
questions:
     - Case 1: "this term is itself EOP, and it's a Root (special: no parent 
element will check it) and it may or may not have child to check"
     - Case 2: "this term is a box that encloses EOP children, check those 
children, but not the parent itself"
    



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