mbeckerle commented on a change in pull request #88: Daffodil 1919 separators
URL: https://github.com/apache/incubator-daffodil/pull/88#discussion_r206570698
 
 

 ##########
 File path: 
daffodil-runtime1-unparser/src/main/scala/org/apache/daffodil/processors/unparsers/SeparatedSequenceUnparsers.scala
 ##########
 @@ -0,0 +1,423 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.daffodil.processors.unparsers
+
+import org.apache.daffodil.equality.TypeEqual
+import org.apache.daffodil.exceptions.Assert
+import org.apache.daffodil.processors.{ ElementRuntimeData, 
SequenceRuntimeData, TermRuntimeData }
+import org.apache.daffodil.schema.annotation.props.SeparatorSuppressionPolicy
+import org.apache.daffodil.schema.annotation.props.gen.{ SeparatorPosition }
+import org.apache.daffodil.infoset.DIElement
+
+/**
+ * DFDL Spec. section 14.2.3 specifies only a few different behaviors
+ * for separator suppression. Each has an algorithm.
+ */
+sealed trait SeparatorSuppressionAlgorithm extends Serializable {
+
+  /**
+   * Determines if we should suppress a zero length element and
+   * separator.
+   *
+   * Checks if the length is zero if necessary to decide.
+   *
+   * Returns Suppress or IfTrailing when the element is, in fact, zero length,
+   * and the algorithm wants those to be suppressed.
+   * Returns DoNotSuppress otherwise.
+   */
+  def shouldSuppressIfZeroLength(state: UState, infosetElement: DIElement): 
SeparatorSuppressionAction
+
+  def shouldDoExtraSeparators = false
+
+  def checkArrayPos(state: UState, maxRepeats: Long): Boolean = true
+
+}
+
+object SeparatorSuppressionAlgorithm {
+  type Type = SeparatorSuppressionAlgorithm
+  import SeparatorSuppressionAction._
+
+  object None extends Type {
+    def shouldSuppressIfZeroLength(state: UState, infosetElement: DIElement) = 
Assert.usageError("not to be called.")
+  }
+  object FixedOrExpression extends Type {
+    def shouldSuppressIfZeroLength(state: UState, infosetElement: DIElement) = 
DoNotSuppress
+  }
+
+  class SuppressAnyEmpty(zeroLengthDetector: ZeroLengthDetector) extends Type {
+    def shouldSuppressIfZeroLength(state: UState, infosetElement: DIElement) = 
{
+      val isZL = zeroLengthDetector.isZeroLength(infosetElement)
+      if (isZL) Suppress
+      else DoNotSuppress
+    }
+  }
+
+  trait CheckArrayPosMixin { self: SeparatorSuppressionAlgorithm =>
+    override def checkArrayPos(state: UState, maxRepeats: Long): Boolean = {
+      state.arrayPos <= maxRepeats
+    }
+  }
+
+  class ImplicitSuppressAnyEmpty(zeroLengthDetector: ZeroLengthDetector)
+    extends SuppressAnyEmpty(zeroLengthDetector)
+    with CheckArrayPosMixin
+
+  object ImplicitNeverOrNotPotentiallyTrailing extends Type
+    with CheckArrayPosMixin {
+    def shouldSuppressIfZeroLength(state: UState, infosetElement: DIElement) = 
DoNotSuppress
+
+    override def shouldDoExtraSeparators = true
+
+  }
+
+  class ImplicitPotentiallyTrailing(zeroLengthDetector: ZeroLengthDetector) 
extends Type
+    with CheckArrayPosMixin {
+    def shouldSuppressIfZeroLength(state: UState, infosetElement: DIElement) = 
{
+      val isZL = zeroLengthDetector.isZeroLength(infosetElement)
+      if (isZL) IfTrailing
+      else DoNotSuppress
+    }
+  }
+}
+
+sealed trait SeparatorSuppressionAction extends Serializable
 
 Review comment:
   scaladoc

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

Reply via email to