stevedlawrence commented on a change in pull request #218: Implement 
dfdl:choiceLength='explicit'
URL: https://github.com/apache/incubator-daffodil/pull/218#discussion_r286253011
 
 

 ##########
 File path: 
daffodil-core/src/main/scala/org/apache/daffodil/grammar/primitives/ChoiceCombinator.scala
 ##########
 @@ -48,9 +50,22 @@ case class ChoiceCombinator(ch: ChoiceTermBase, 
rawAlternatives: Seq[Gram])
 
   override def isEmpty = super.isEmpty || alternatives.isEmpty
 
+  private lazy val bitsMultiplier = ch.lengthUnits match {
+    case LengthUnits.Bits => 1
+    case LengthUnits.Bytes => 8
+    case LengthUnits.Characters if ch.knownEncodingIsFixedWidth => 
ch.knownEncodingWidthInBits
+    case _ => 0 // zero means can't multiply to get width in bits.
+  }
+
   lazy val parser: Parser = {
     if (!ch.isDirectDispatch) {
-      new ChoiceParser(ch.termRuntimeData, parsers.toVector)
+      ch.choiceLengthKind match {
+        case ChoiceLengthKind.Implicit => new ChoiceParser(ch.termRuntimeData, 
parsers.toVector)
+        case ChoiceLengthKind.Explicit => {
+          val cp = new ChoiceParser(ch.termRuntimeData, parsers.toVector)
+          new SpecifiedLengthChoiceParser(cp, ch.termRuntimeData, 
ch.choiceLength, bitsMultiplier)
+        }
 
 Review comment:
   Thoughts on reducing code duplication with something like this?
   ```scala
   val cp = new ChoiceParser(...)
   ch.choiceLengthKind match {
     case ChoiceLengthKind.Implicit => cp
     case ChoiceLengthKind.Explicit => new SpecifiedLengthChoicePaser(cp, ...)
   }
   ```
   Something similar could be done below 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