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

 ##########
 File path: 
daffodil-core/src/main/scala/org/apache/daffodil/grammar/ChoiceGrammarMixin.scala
 ##########
 @@ -19,12 +19,28 @@ package org.apache.daffodil.grammar
 
 import org.apache.daffodil.dsom.ChoiceTermBase
 import org.apache.daffodil.grammar.primitives.ChoiceCombinator
+import org.apache.daffodil.schema.annotation.props.gen.ChoiceLengthKind
+import org.apache.daffodil.processors.parsers.NadaParser
+import org.apache.daffodil.processors.unparsers.Unparser
+import org.apache.daffodil.processors.unparsers.ChoiceUnusedUnparser
+import org.apache.daffodil.util.Maybe
 
 trait ChoiceGrammarMixin extends GrammarMixin { self: ChoiceTermBase =>
 
   override lazy val groupContent = prod("choiceContent") {
-    ChoiceCombinator(this, alternatives)
+    ChoiceCombinator(this, alternatives) ~
+    ChoiceUnused(this)
   }
 
   private lazy val alternatives = groupMembersWithImpliedSequences.map{ 
_.termContentBody }
 }
+
+case class ChoiceUnused(ctxt: ChoiceTermBase)
+  extends Terminal (ctxt, ctxt.choiceLengthKind eq ChoiceLengthKind.Explicit) {
+
+  override def parser = new NadaParser(ctxt.termRuntimeData)
+
+  override lazy val unparser: Unparser = new ChoiceUnusedUnparser(
+    ctxt.termRuntimeData,
+    ctxt.choiceLength * 8)
 
 Review comment:
   I think this correctly assumes that choiceLength is always in units of 
bytes, might be worth adding a comment to make it clear where the 8 magic 
number is coming from, and maybe why lengthUnits isn't use as one might expect?

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