stevedlawrence commented on code in PR #1652:
URL: https://github.com/apache/daffodil/pull/1652#discussion_r3167841090
##########
daffodil-core/src/main/scala/org/apache/daffodil/core/grammar/ElementBaseGrammarMixin.scala:
##########
@@ -252,6 +257,134 @@ trait ElementBaseGrammarMixin
}
final lazy val prefixedLengthBody = prefixedLengthElementDecl.parsedValue
+ final lazy val parentEffectiveLengthUnits: LengthUnits =
+ immediatelyEnclosingElementParent match {
+ case Some(parent: ElementBase) => {
+ parent.lengthKind match {
+ case LengthKind.Explicit | LengthKind.Prefixed => parent.lengthUnits
+ case LengthKind.Pattern => LengthUnits.Characters
+ case _
+ if parent.isInstanceOf[ChoiceTermBase] && (parent
+ .asInstanceOf[ChoiceTermBase]
+ .choiceLengthKind == ChoiceLengthKind.Explicit) =>
+ LengthUnits.Bytes
+ case LengthKind.EndOfParent => parent.parentEffectiveLengthUnits
+ case _ =>
+ Assert.invariantFailed(
+ s"Could not figure effective length unit of parents of
${context}"
+ )
+ }
+ }
+ case None if this.isInstanceOf[Root] => LengthUnits.Characters
+ case _ =>
+ Assert.invariantFailed(
+ s"Could not figure effective length unit of parents of ${context}"
+ )
+ }
+ final lazy val checkEndOfParentElem: Unit = {
+ if (lengthKind != LengthKind.EndOfParent) ()
+ else {
+ schemaDefinitionWhen(
+ hasTerminator,
+ "%s is specified as dfdl:lengthKind=\"endOfParent\", but specifies a
dfdl:terminator.",
+ context
+ )
+ schemaDefinitionWhen(
+ trailingSkip != 0,
+ "%s is specified as dfdl:lengthKind=\"endOfParent\", but specifies a
non-zero dfdl:trailingSkip.",
+ context
+ )
+ schemaDefinitionWhen(
+ maxOccurs > 1,
+ "%s is specified as dfdl:lengthKind=\"endOfParent\", but specifies a
maxOccurs greater than 1.",
+ context
+ )
+ schemaDefinitionWhen(
+ nextSibling.isDefined && nextSibling.get.isInstanceOf[ModelGroup],
+ "%s is specified as dfdl:lengthKind=\"endOfParent\", but a model group
is defined between this element and the end of the enclosing component",
+ context
+ )
Review Comment:
What if we hae an example like this:
```xml
<group name="foo">
<sequence>
<element name="eopElement" ... />
</sequence>
</group>
<element name="bar">
<complexType>
<sequence>
<group ref="foo" />
<element name="laterSibling" ... />
</sequence>
</complexType>
</element>
```
In this case there effectively a sibling after eopELement, but I'm not sure
we would detect that since I'm not sure optLeixcalParent sees past the
globalGroupDef. Though, maybe we have logic to allow group refs to have
parents? I seem to remember something where we copy groups, but I might be
thinking of something else.
--
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]