stevedlawrence commented on a change in pull request #74: Daffodil trailing sep
URL: https://github.com/apache/incubator-daffodil/pull/74#discussion_r195068212
##########
File path:
daffodil-core/src/main/scala/org/apache/daffodil/grammar/SequenceGrammarMixin.scala
##########
@@ -17,36 +17,113 @@
package org.apache.daffodil.grammar
import org.apache.daffodil.schema.annotation.props.gen._
-import org.apache.daffodil.grammar.primitives.SequenceCombinator
-import org.apache.daffodil.dsom.SequenceTermBase
-import org.apache.daffodil.grammar.primitives.LayeredSequence
+import org.apache.daffodil.schema.annotation.props.SeparatorSuppressionPolicy
+import org.apache.daffodil.dsom._
+import org.apache.daffodil.exceptions.Assert
+import org.apache.daffodil.grammar.primitives._
+import org.apache.daffodil.grammar.primitives.OrderedSequence
trait SequenceGrammarMixin extends GrammarMixin { self: SequenceTermBase =>
final override lazy val groupContent = prod("groupContent") {
- if (isLayered) layeredSequenceContent
- else {
- self.sequenceKind match {
- case SequenceKind.Ordered => orderedSequenceContent
- case SequenceKind.Unordered => subsetError("Unordered sequences are
not supported.") // unorderedSequenceContent
- }
+ if (isLayered) layerContent
+ else sequenceContent
+ }
+
+ final lazy val sequenceContent = {
+ import columnConstants._
+ self.sequenceKind match {
+ case Ordered__ => orderedSequence
+ case Unordered => subsetError("Unordered sequences are not supported.")
// unorderedSequenceContent
}
}
- private lazy val layeredSequenceContent = {
+ private lazy val layerContent = {
schemaDefinitionUnless(groupMembers.length == 1, "Layered sequence can
have only 1 child term. %s were found: %s", groupMembers.length,
groupMembers.mkString(", "))
val term = groupMembers(0)
schemaDefinitionWhen(term.isArray, "Layered sequence body cannot be an
array.")
- val termGram = term.termContentBody
- LayeredSequence(this, termGram)
+ LayeredSequence(this, new ScalarOrderedRequiredSequenceChild(this, term,
1))
+ }
+
+ private lazy val seqChildren = (groupMembers zip Stream.from(1)).map {
+ case (gm, i) =>
+ sequenceChild(gm, i)
+ }
+
+ private lazy val orderedSequence = {
+ val res = new OrderedSequence(this, seqChildren)
+ res
}
- private lazy val orderedSequenceContent = prod("sequenceContent") {
- SequenceCombinator(this, terms)
+ /**
+ * Constants to make the lookup tables below more readable without using
fragile whitespace
+ */
+ private object columnConstants {
+ val UNB = -1 // UNBOUNDED
+ val ZER = 0
+ val ONE = 1
+
+ val Sep__ = true
+ val NoSep = false
+
+ val Ordered__ = SequenceKind.Ordered
+ val Unordered = SequenceKind.Unordered
+
+ val Never______ : SeparatorSuppressionPolicy =
SeparatorSuppressionPolicy.Never
+ val Trailing___ : SeparatorSuppressionPolicy =
SeparatorSuppressionPolicy.TrailingEmpty
+ val TrailingStr: SeparatorSuppressionPolicy =
SeparatorSuppressionPolicy.TrailingEmptyStrict
+ val Always_____ : SeparatorSuppressionPolicy =
SeparatorSuppressionPolicy.AnyEmpty
+
+ val StopValue_ = OccursCountKind.StopValue
+ val Implicit__ = OccursCountKind.Implicit
+ val Parsed____ = OccursCountKind.Parsed
+ val Fixed_____ = OccursCountKind.Fixed
+ val Expression = OccursCountKind.Expression
+
+ type EB = ElementBase
+ type MG = ModelGroup
+ type SG = SequenceTermBase
+ type CG = ChoiceTermBase
}
- protected lazy val terms = groupMembers.map { _.asTermInSequence }
+ /**
+ * Produces the right kind of SequenceChild object for this particular child
+ * for the role it must play within this sequence's behavior.
+ *
+ * A SequenceChild object is effectively generator for part of the
Sequence's parse/unparse
+ * algorithm. For arrays these SequenceChild objects enable processing
exactly one array instance at
+ * a time, orchestrated by the surrounding sequence's processor.
+ */
+ private def sequenceChild(child: Term, groupIndex: Int): SequenceChild = {
+ import columnConstants._
+ val (max, min, ock) = child match {
+ case e: EB => (e.maxOccurs, e.minOccurs, e.occursCountKind)
+ case _ => (1, 1, null)
+ }
+ val ssp = separatorSuppressionPolicy
+ val res = (child, sequenceKind, hasSeparator, ssp, ock, min, max) match {
Review comment:
Looks like hasSeparator is never used in any of the match cases. Is that
intentional?
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on 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