This is an automated email from the ASF dual-hosted git repository.
mbeckerle pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/daffodil.git
The following commit(s) were added to refs/heads/main by this push:
new 4ebfc4d Remove dfdlx:choiceDispatchKeyKind and
dfdlx:choiceBranchKeyKind
4ebfc4d is described below
commit 4ebfc4de52a98edf59bb4821d75a0003ce8092f3
Author: Michael Beckerle <[email protected]>
AuthorDate: Mon Oct 25 15:01:26 2021 -0400
Remove dfdlx:choiceDispatchKeyKind and dfdlx:choiceBranchKeyKind
Unused by any known DFDL schema.
Removing to simplify daffodil around the enumerations/table features.
Removed corresponding ChoiceDispatchCombinatorKeyByTypeParser - no longer
used.
Cleaned up toOption.getOrElse("") to use more idiomatic scala (map
function).
DAFFODIL-2273
---
.../org/apache/daffodil/dsom/ChoiceGroup.scala | 78 +------
.../scala/org/apache/daffodil/dsom/SchemaSet.scala | 1 -
.../grammar/primitives/ChoiceCombinator.scala | 89 +++-----
.../runtime1/ChoiceTermRuntime1Mixin.scala | 2 -
.../apache/daffodil/xsd/DFDL_part2_attributes.xsd | 4 -
.../resources/org/apache/daffodil/xsd/dafext.xsd | 16 --
.../resources/org/apache/daffodil/xsd/dfdlx.xsd | 13 --
.../processors/parsers/ElementKindParsers.scala | 47 +----
.../extensions/type_calc/inputTypeCalc.tdml | 232 ---------------------
.../extensions/TestInputTypeValueCalc.scala | 12 --
10 files changed, 33 insertions(+), 461 deletions(-)
diff --git
a/daffodil-core/src/main/scala/org/apache/daffodil/dsom/ChoiceGroup.scala
b/daffodil-core/src/main/scala/org/apache/daffodil/dsom/ChoiceGroup.scala
index ab9ee32..944d7ff 100644
--- a/daffodil-core/src/main/scala/org/apache/daffodil/dsom/ChoiceGroup.scala
+++ b/daffodil-core/src/main/scala/org/apache/daffodil/dsom/ChoiceGroup.scala
@@ -23,9 +23,7 @@ import scala.xml.Node
import org.apache.daffodil.schema.annotation.props.gen.Choice_AnnotationMixin
import org.apache.daffodil.schema.annotation.props.gen.ChoiceAGMixin
import org.apache.daffodil.grammar.ChoiceGrammarMixin
-import org.apache.daffodil.exceptions.Assert
import org.apache.daffodil.schema.annotation.props.gen.YesNo
-import org.apache.daffodil.schema.annotation.props.gen.ChoiceKeyKindType
/**
*
@@ -96,8 +94,7 @@ abstract class ChoiceTermBase(
with Choice_AnnotationMixin
with RawDelimitedRuntimeValuedPropertiesMixin // initiator and terminator
(not separator)
with ChoiceGrammarMixin
- with ChoiceAGMixin
- with HasOptRepTypeMixinImpl {
+ with ChoiceAGMixin {
requiredEvaluationsIfActivated(noBranchesFound)
requiredEvaluationsIfActivated(branchesAreNonOptional)
@@ -106,83 +103,14 @@ abstract class ChoiceTermBase(
final protected lazy val optionChoiceDispatchKeyRaw =
findPropertyOption("choiceDispatchKey", expressionAllowed = true)
final protected lazy val choiceDispatchKeyRaw =
requireProperty(optionChoiceDispatchKeyRaw)
- lazy val optionChoiceDispatchKeyKindRaw =
findPropertyOption("choiceDispatchKeyKind")
- lazy val defaultableChoiceDispatchKeyKind =
- if (tunable.requireChoiceDispatchKeyKindProperty) {
- choiceDispatchKeyKind
- } else {
- val asString =
optionChoiceDispatchKeyKindRaw.toOption.getOrElse("implicit")
- ChoiceKeyKindType(asString, this)
- }
-
- lazy val optionChoiceBranchKeyKindRaw =
findPropertyOption("choiceBranchKeyKind")
- lazy val defaultableChoiceBranchKeyKind =
- if (tunable.requireChoiceBranchKeyKindProperty) {
- choiceDispatchKeyKind
- } else {
- val asString =
optionChoiceBranchKeyKindRaw.toOption.getOrElse("implicit")
- ChoiceKeyKindType(asString, this)
- }
-
- final lazy val isDirectDispatch = {
- val isDD: Boolean = defaultableChoiceDispatchKeyKind match {
- case ChoiceKeyKindType.ByType => true
- case ChoiceKeyKindType.Explicit => true
- case ChoiceKeyKindType.Implicit => optionChoiceDispatchKeyRaw.isDefined
- case ChoiceKeyKindType.Speculative => false
- }
+ final lazy val isDirectDispatch = {
+ val isDD = optionChoiceDispatchKeyRaw.isDefined
if (isDD && initiatedContent == YesNo.Yes) {
SDE("dfdl:initiatedContent must not equal 'yes' when
dfdl:choiceDispatchKey is defined")
}
isDD
}
- // If choiceDispatchKeyKind is byType, verify that all our children share a
repType,
- // and use that. Otherwise, there is no need to associate a repType with
this choice
- override final lazy val optRepType: Option[SimpleTypeDefBase] =
defaultableChoiceDispatchKeyKind match {
- case ChoiceKeyKindType.ByType => {
- val branchReptypes: Seq[SimpleTypeDefBase] = groupMembers.map(term => {
- term match {
- case e: ElementDeclMixin => e.typeDef match {
- case t: SimpleTypeDefBase => t.optRepTypeDef match {
- case None => SDE("When <xs:choice> has
choiceBranchKey=\"byType\", all branches must have a type which defines a
repType")
- case Some(x) => x
- }
- case _: SimpleTypeBase => SDE("When <xs:choice> has
choiceBranchKey=\"byType\", no branch can have a primitive xsd type")
- case _ => SDE("When <xs:choice> has choiceBranchKey=\"byType\",
all branches must be a simple type")
- }
- case _ => SDE("When <xs:choice> has choiceBranchKey=\"byType\", all
branches must be a simple element")
- }
- })
- val ans = branchReptypes.reduce((a, b) => {
- /*
- * We tolerate type objects being copies or the same object because we
compare the QNames.
- */
- if (a.namedQName != b.namedQName) {
- SDE("All children of an <xs:choice> with
choiceDispatchKeyKind=byType must have the same reptype")
- }
- a
- })
- Some(ans)
- }
- case ChoiceKeyKindType.Speculative => None
- case ChoiceKeyKindType.Explicit => None
- case ChoiceKeyKindType.Implicit => None
- }
-
- /*
- * When choiceBranchKeyKind=byType or choiceDispatchKeyKind=byType, we are
associated with one or more repTypes (corresponding to
- * the reptypes of our choices).
- * Since the repValueSet represents the set of repValues that we expect to
be able to be associated with an element, it does, in theory,
- * make sense to assign a repValueSet to an entire choiceGroup. For
instance, in the common case of choiceBranchKeyKind=byType and
choiceDispatchKeyKind=byType,
- * this would just be the union of the repValueSets of all of the individual
choices.
- * However, figuring this out becomes more complicated when we start having
to deal with choiceBranchKeyKind=explicit
- * There is no indication yet that this problem is particuarly intractable,
however it is non-trivial. Since we never
- * actually need to know the optRepValueSet of an entire choiceGroup, we can
simple avoid thinking about it until such a time that we do.
- */
-
- override final lazy val optRepValueSet = Assert.invariantFailed("We
shouldn't need to compute the optRepValueSet of a choiceGroup")
-
final override lazy val hasKnownRequiredSyntax = LV('hasKnownRequiredSyntax)
{
if (hasFraming) true
// else if (isKnownToBeAligned) true //TODO: Alignment may not occur;
hence, cannot be part of determining whether there is known syntax.
diff --git
a/daffodil-core/src/main/scala/org/apache/daffodil/dsom/SchemaSet.scala
b/daffodil-core/src/main/scala/org/apache/daffodil/dsom/SchemaSet.scala
index f4224a5..f3861e2 100644
--- a/daffodil-core/src/main/scala/org/apache/daffodil/dsom/SchemaSet.scala
+++ b/daffodil-core/src/main/scala/org/apache/daffodil/dsom/SchemaSet.scala
@@ -679,7 +679,6 @@ class TransitiveClosureSchemaComponents private() extends
TransitiveClosure[Sche
}
val misc: SSC = sc match {
case eb: ElementBase => eb.optPrefixLengthElementDecl.toSeq
- case ch: ChoiceTermBase => ch.optRepTypeElement.toSeq
case _ => Seq()
}
diff --git
a/daffodil-core/src/main/scala/org/apache/daffodil/grammar/primitives/ChoiceCombinator.scala
b/daffodil-core/src/main/scala/org/apache/daffodil/grammar/primitives/ChoiceCombinator.scala
index fa67f3a..5d5996c 100644
---
a/daffodil-core/src/main/scala/org/apache/daffodil/grammar/primitives/ChoiceCombinator.scala
+++
b/daffodil-core/src/main/scala/org/apache/daffodil/grammar/primitives/ChoiceCombinator.scala
@@ -30,7 +30,6 @@ import org.apache.daffodil.grammar.Gram
import org.apache.daffodil.grammar.Terminal
import org.apache.daffodil.processors.parsers._
import org.apache.daffodil.processors.unparsers._
-import org.apache.daffodil.schema.annotation.props.gen.ChoiceKeyKindType
import org.apache.daffodil.schema.annotation.props.gen.ChoiceLengthKind
import org.apache.daffodil.util.MaybeInt
@@ -66,14 +65,15 @@ case class ChoiceCombinator(ch: ChoiceTermBase,
alternatives: Seq[Gram])
override def isEmpty = super.isEmpty || alternatives.isEmpty
- lazy val optChoiceDispatchKeyKind = Some(ch.choiceDispatchKeyKind)
-
// dfdl:choiceLength is always specified in bytes
private lazy val choiceLengthInBits: MaybeInt = ch.choiceLengthKind match {
case ChoiceLengthKind.Explicit => MaybeInt(ch.choiceLength * 8)
case ChoiceLengthKind.Implicit => MaybeInt.Nope
}
+ private def branchKeyAttribute = "dfdl:choiceBranchKey"
+ private def branchKeyRangeAttribute = "dfdlx:choiceBranchKeyRanges"
+
lazy val parser: Parser = {
if (!ch.isDirectDispatch) {
val cp = new ChoiceParser(ch.termRuntimeData, parsers.toVector)
@@ -83,60 +83,39 @@ case class ChoiceCombinator(ch: ChoiceTermBase,
alternatives: Seq[Gram])
}
} else {
//Verify that every alternative has some form of branch key
- alternatives.map { alt =>
+ alternatives.foreach { alt =>
val keyTerm = alt.context.asInstanceOf[Term]
val hasBranchKey =
keyTerm.findPropertyOption("choiceBranchKey").isDefined
val hasBranchKeyRanges =
keyTerm.findPropertyOption("choiceBranchKeyRanges").isDefined
- if (!hasBranchKey && !hasBranchKeyRanges &&
ch.defaultableChoiceBranchKeyKind != ChoiceKeyKindType.ByType) {
+ if (!hasBranchKey && !hasBranchKeyRanges) {
keyTerm.SDE("Neither dfdl:choiceBranchKey nor
dfdlx:choiceBranchKeyRanges is defined.")
}
}
val dispatchBranchKeyValueTuples: Seq[(String, Gram)] =
alternatives.flatMap { alt =>
val keyTerm = alt.context.asInstanceOf[Term]
- val uncookedBranchKeys =
- ch.defaultableChoiceBranchKeyKind match {
- case ChoiceKeyKindType.ByType => {
- val keyTerm_ = keyTerm.asInstanceOf[ElementBase]
- val st = keyTerm_.simpleType
- val aa = st.optRepValueSet
- val repValueSet = keyTerm_.simpleType.optRepValueSet.get
- val ans =
repValueSet.valueSet.toSeq.map(_.getAnyRef.toString).mkString(" ")
- ans
- }
- case ChoiceKeyKindType.Explicit | ChoiceKeyKindType.Implicit =>
keyTerm.findPropertyOption("choiceBranchKey").toOption.getOrElse("")
- case ChoiceKeyKindType.Speculative =>
Assert.invariantFailed("Cannot have choiceKeyKind==speculative with direct
dispatch")
- }
- val cbks = {
- if (uncookedBranchKeys.isEmpty) {
- List()
- } else {
- ChoiceBranchKeyCooker.convertConstant(uncookedBranchKeys,
ch.runtimeData, forUnparse = false)
- }
- }
- cbks.map { (_, alt) }
+ val optUncooked =
+ keyTerm.findPropertyOption("choiceBranchKey").toOption
+ val cookedBranchKeys: Seq[String] = optUncooked.map{ uncooked =>
+ ChoiceBranchKeyCooker.convertConstant(uncooked, ch.runtimeData,
forUnparse = false)
+ }.toSeq.flatten
+ val tuples: Seq[(String, Gram)] = cookedBranchKeys.map { (_, alt) }
+ tuples
}
//[(minKeyValue, maxKeyValue, parser, isRepresented)]
- //Since there is not a choiceBranchKeyRanges attribute, this can only
currently be populated by repType
val dispatchBranchKeyRangeTuples: Seq[(RangeBound, RangeBound, Parser,
Boolean)] = alternatives.flatMap { alt =>
val keyTerm = alt.context.asInstanceOf[Term]
- val branchKeyRanges: Seq[(RangeBound, RangeBound)] =
ch.defaultableChoiceBranchKeyKind match {
- case ChoiceKeyKindType.ByType => {
- val keyTerm_ = keyTerm.asInstanceOf[ElementBase]
- keyTerm_.simpleType.optRepValueSet.get.valueRanges.toSeq.map(x => {
- val x_ = x.asInstanceOf[(RangeBound, RangeBound)]
- (x_._1, x_._2)
- })
- }
- case ChoiceKeyKindType.Explicit | ChoiceKeyKindType.Implicit => {
- val bounds =
IntRangeCooker.convertConstant(keyTerm.findPropertyOption("choiceBranchKeyRanges").toOption.getOrElse(""),
context, false)
- bounds.map({
- case (lowerBound, upperBound) =>
- (new RangeBound(lowerBound, true), new RangeBound(upperBound,
true))
- })
- }
- case ChoiceKeyKindType.Speculative => Assert.invariantFailed("Cannot
have choiceKeyKind==speculative with direct dispatch")
+ val branchKeyRanges: Seq[(RangeBound, RangeBound)] = {
+ val optUncooked =
keyTerm.findPropertyOption("choiceBranchKeyRanges").toOption
+ val cooked: Seq[(JBigInt, JBigInt)] =
+ optUncooked.map { uncooked =>
IntRangeCooker.convertConstant(uncooked, context, false) }.toSeq.flatten
+ val tuples = cooked.map({
+ case (lowerBound, upperBound) =>
+ (new RangeBound(lowerBound, true), new RangeBound(upperBound,
true))
+ })
+ tuples
}
+
//
// The choice alternative (aka branch) is either an element having
// the repType, or it is a computed (inputValueCalc) element that uses
the
@@ -170,11 +149,7 @@ case class ChoiceCombinator(ch: ChoiceTermBase,
alternatives: Seq[Gram])
// we don't see enough distinct ranges on a single element for this to
be an issue
// Additionally, at this point, the keys could be comming from either
the choiceBranchKey family of attributes
// or the repValue family of attributes
- val (branchKeyAttribute, branchKeyRangeAttribute) =
ch.defaultableChoiceBranchKeyKind match {
- case ChoiceKeyKindType.ByType => ("dfdlx:repValues",
"dfdlx:repValueRanges")
- case ChoiceKeyKindType.Explicit | ChoiceKeyKindType.Implicit =>
("dfdl:choiceBranchKey", "dfdlx:choiceBranchKeyRanges")
- case ChoiceKeyKindType.Speculative => Assert.invariantFailed("Cannot
have choiceKeyKind==speculative with direct dispatch")
- }
+
val groupedByKey = dispatchBranchKeyValueTuples.groupBy(_._1)
groupedByKey.foreach {
case (k, kvs) =>
@@ -188,7 +163,7 @@ case class ChoiceCombinator(ch: ChoiceTermBase,
alternatives: Seq[Gram])
case Success(v) => {
val asBigInt = JBigInt.valueOf(v)
val conflictingRanges = dispatchBranchKeyRangeTuples.filter({
case (min, max, _, _) => min.testAsLower(asBigInt) && max.testAsUpper(asBigInt)
})
- if (conflictingRanges.length > 0) {
+ if (conflictingRanges.nonEmpty) {
SDE(
"%s (%s) conflicts with %s. Offending branches are:\n%s\n%s",
branchKeyAttribute, k, branchKeyRangeAttribute,
@@ -205,7 +180,7 @@ case class ChoiceCombinator(ch: ChoiceTermBase,
alternatives: Seq[Gram])
}
}
//check for overlap in choiceBranchKeyRanges
- dispatchBranchKeyRangeTuples.map({
+ dispatchBranchKeyRangeTuples.foreach({
case (min, max, alt, isRepresented) =>
val conflictingRanges1 = dispatchBranchKeyRangeTuples.filter({ case
(min2, max2, _, _) => min.intersectsWithOtherBounds(min2, max2) })
val conflictingRanges2 = dispatchBranchKeyRangeTuples.filter({ case
(min2, max2, _, _) => max.intersectsWithOtherBounds(min2, max2) })
@@ -219,8 +194,8 @@ case class ChoiceCombinator(ch: ChoiceTermBase,
alternatives: Seq[Gram])
}
})
- val dispatchBranchKeyMap =
dispatchBranchKeyValueTuples.toMap.mapValues(gram => {
- val isRepresented = true // FIXME: Verify is ok? Was:
gram.context.enclosingTerm.get.isRepresented
+ val dispatchBranchKeyMap = dispatchBranchKeyValueTuples.toMap.mapValues
{ gram =>
+ val isRepresented = true // choice branches are, currently, always
represented (cannot have inputValueCalc).
val gramParser = gram.parser
val parser =
if (gramParser.isEmpty) {
@@ -229,17 +204,11 @@ case class ChoiceCombinator(ch: ChoiceTermBase,
alternatives: Seq[Gram])
gramParser
}
(parser, isRepresented)
- })
+ }
val serializableMap: Map[String, (Parser, Boolean)] =
dispatchBranchKeyMap.map(identity)
val serializableKeyRangeMap: Vector[(RangeBound, RangeBound, Parser,
Boolean)] = dispatchBranchKeyRangeTuples.toVector.map(identity)
- ch.defaultableChoiceDispatchKeyKind match {
- case ChoiceKeyKindType.ByType =>
- new ChoiceDispatchCombinatorKeyByTypeParser(ch.termRuntimeData,
ch.optRepTypeElement.get.enclosedElement.parser,
ch.optRepTypeElement.get.elementRuntimeData, serializableMap,
serializableKeyRangeMap)
- case ChoiceKeyKindType.Explicit | ChoiceKeyKindType.Implicit =>
- new ChoiceDispatchCombinatorParser(ch.termRuntimeData,
ch.choiceDispatchKeyEv, serializableMap, serializableKeyRangeMap)
- case ChoiceKeyKindType.Speculative =>
Assert.invariantFailed("ChoiceKeyKindType==speculative while
isDirectDispatch==true")
- }
+ new ChoiceDispatchCombinatorParser(ch.termRuntimeData,
ch.choiceDispatchKeyEv, serializableMap, serializableKeyRangeMap)
}
}
diff --git
a/daffodil-core/src/main/scala/org/apache/daffodil/runtime1/ChoiceTermRuntime1Mixin.scala
b/daffodil-core/src/main/scala/org/apache/daffodil/runtime1/ChoiceTermRuntime1Mixin.scala
index 2255dc8..411340f 100644
---
a/daffodil-core/src/main/scala/org/apache/daffodil/runtime1/ChoiceTermRuntime1Mixin.scala
+++
b/daffodil-core/src/main/scala/org/apache/daffodil/runtime1/ChoiceTermRuntime1Mixin.scala
@@ -35,8 +35,6 @@ import org.apache.daffodil.util.Delay
trait ChoiceTermRuntime1Mixin { self: ChoiceTermBase =>
- requiredEvaluationsIfActivated(optRepTypeElement.map{
_.elementRuntimeData.initialize })
-
/**
* The members of the choice group with special treatment given to some
kinds of members.
*
diff --git
a/daffodil-propgen/src/main/resources/org/apache/daffodil/xsd/DFDL_part2_attributes.xsd
b/daffodil-propgen/src/main/resources/org/apache/daffodil/xsd/DFDL_part2_attributes.xsd
index 87803ef..9eae832 100644
---
a/daffodil-propgen/src/main/resources/org/apache/daffodil/xsd/DFDL_part2_attributes.xsd
+++
b/daffodil-propgen/src/main/resources/org/apache/daffodil/xsd/DFDL_part2_attributes.xsd
@@ -448,8 +448,6 @@
<xsd:attribute name="choiceLengthKind" type="dfdl:ChoiceLengthKindEnum" />
<xsd:attribute name="choiceLength" type="dfdl:DFDLNonNegativeInteger" />
<xsd:attribute name="choiceDispatchKey" type="dfdl:DFDLExpression" />
- <xsd:attribute ref="dfdlx:choiceBranchKeyKind" />
- <xsd:attribute ref="dfdlx:choiceDispatchKeyKind" />
</xsd:attributeGroup>
<!--16 Arrays and Optional Elements: Properties for Repeating and
Variable-Occurrence
@@ -966,8 +964,6 @@
type="dfdl:DFDLNonNegativeInteger" />
<xsd:attribute form="qualified" name="choiceDispatchKey"
type="dfdl:DFDLExpression" />
- <xsd:attribute ref="dfdlx:choiceBranchKeyKind" />
- <xsd:attribute ref="dfdlx:choiceDispatchKeyKind" />
</xsd:attributeGroup>
<!--16 Arrays and Optional Elements: Properties for Repeating and
Variable-Occurrence
diff --git
a/daffodil-propgen/src/main/resources/org/apache/daffodil/xsd/dafext.xsd
b/daffodil-propgen/src/main/resources/org/apache/daffodil/xsd/dafext.xsd
index 6c591d2..c70bbb8 100644
--- a/daffodil-propgen/src/main/resources/org/apache/daffodil/xsd/dafext.xsd
+++ b/daffodil-propgen/src/main/resources/org/apache/daffodil/xsd/dafext.xsd
@@ -436,22 +436,6 @@
</xs:documentation>
</xs:annotation>
</xs:element>
- <xs:element name="requireChoiceDispatchKeyKindProperty"
type="xs:boolean" default="false" minOccurs="0">
- <xs:annotation>
- <xs:documentation>
- If true, require that the dfdl:choiceDispatchKeyKind property is
specified. If false, use a
- default value if the property is not defined in the schema.
- </xs:documentation>
- </xs:annotation>
- </xs:element>
- <xs:element name="requireChoiceBranchKeyKindProperty"
type="xs:boolean" default="false" minOccurs="0">
- <xs:annotation>
- <xs:documentation>
- If true, require that the dfdl:choiceBranchKeyKind property is
specified. If false, use a
- default value if the property is not defined in the schema.
- </xs:documentation>
- </xs:annotation>
- </xs:element>
<xs:element name="requireEmptyElementParsePolicyProperty"
type="xs:boolean" default="false" minOccurs="0">
<xs:annotation>
<xs:documentation>
diff --git
a/daffodil-propgen/src/main/resources/org/apache/daffodil/xsd/dfdlx.xsd
b/daffodil-propgen/src/main/resources/org/apache/daffodil/xsd/dfdlx.xsd
index 5fa8fd2..7cd9a80 100644
--- a/daffodil-propgen/src/main/resources/org/apache/daffodil/xsd/dfdlx.xsd
+++ b/daffodil-propgen/src/main/resources/org/apache/daffodil/xsd/dfdlx.xsd
@@ -34,9 +34,7 @@
<xs:simpleType name="PropertyNameType">
<xs:restriction base="xs:string">
- <xs:enumeration value="dfdlx:choiceBranchKeyKind" />
<xs:enumeration value="dfdlx:choiceBranchKeyRanges" />
- <xs:enumeration value="dfdlx:choiceDispatchKeyKind" />
<xs:enumeration value="dfdlx:emptyElementParsePolicy"/>
<xs:enumeration value="dfdlx:inputTypeCalc"/>
<xs:enumeration value="dfdlx:objectKind"/>
@@ -74,17 +72,6 @@
<xs:enumeration value="treatAsMissing" />
</xs:restriction>
</xs:simpleType>
-
- <xs:attribute name="choiceBranchKeyKind" type="dfdlx:ChoiceKeyKindType"/>
- <xs:attribute name="choiceDispatchKeyKind" type="dfdlx:ChoiceKeyKindType"/>
- <xs:simpleType name="ChoiceKeyKindType">
- <xs:restriction base="xs:string">
- <xs:enumeration value="byType"/>
- <xs:enumeration value="explicit"/>
- <xs:enumeration value="speculative"/>
- <xs:enumeration value="implicit"/>
- </xs:restriction>
- </xs:simpleType>
<xs:attribute name="choiceBranchKeyRanges" type="dfdl:NonEmptyListOfInteger"
/>
diff --git
a/daffodil-runtime1/src/main/scala/org/apache/daffodil/processors/parsers/ElementKindParsers.scala
b/daffodil-runtime1/src/main/scala/org/apache/daffodil/processors/parsers/ElementKindParsers.scala
index 6845952..71b5991 100644
---
a/daffodil-runtime1/src/main/scala/org/apache/daffodil/processors/parsers/ElementKindParsers.scala
+++
b/daffodil-runtime1/src/main/scala/org/apache/daffodil/processors/parsers/ElementKindParsers.scala
@@ -17,11 +17,9 @@
package org.apache.daffodil.processors.parsers
-import java.math.{ BigInteger => JBigInt }
-
+import java.math.{BigInteger => JBigInt}
import org.apache.daffodil.processors.ChoiceDispatchKeyEv
import org.apache.daffodil.processors.DelimiterParseEv
-import org.apache.daffodil.processors.ElementRuntimeData
import org.apache.daffodil.processors.EscapeSchemeParseEv
import org.apache.daffodil.processors.RangeBound
import org.apache.daffodil.processors.RuntimeData
@@ -155,31 +153,6 @@ abstract class ChoiceDispatchCombinatorParserBase(rd:
TermRuntimeData,
*/
def computeDispatchKey(pstate: PState): Maybe[String]
- /*
- * having choiceDispatchKeyKind=byType introduces some subtle problems.
- * In the basic case a naive implementation would try to parse the repType
twice:
- * once to determine the dispatchKey, and once because the resulting branch
would have the same repType
- * However, it is also possible that the branch would have an
inputValueCalc, in which case we would
- * only parse the repType when computing the dispatchKey.
- * The difficulty is that, in both the above cases, the *correct* behavior
is to parse the reptype exactly once
- *
- * Ideally, we would actually parse repType once, and pass the result into
the branch's parser
- * However, in practice, this would involve a significant amount of
reworking of Daffodil parsing subsystem.
- *
- * Instead, we simulate parsing once by saving and restoring state as
follows:
- *
- * initialState = pstate.mark()
- * dispatchKey <- repType.parse()
- * if(branch.isRepresented){
- * pstate.restore(initialState)
- * }else{
- * pstate.discard(initialState)
- * }
- * branch.parse()
- *
- *
- */
-
def parse(pstate: PState): Unit = {
pstate.withPointOfUncertainty("ChoiceDispatchCombinator", rd) { pou =>
@@ -262,21 +235,3 @@ class ChoiceDispatchCombinatorParser(rd: TermRuntimeData,
dispatchKeyEv: ChoiceD
override def computeDispatchKey(pstate: PState): Maybe[String] =
Maybe(dispatchKeyEv.evaluate(pstate))
}
-class ChoiceDispatchCombinatorKeyByTypeParser(rd: TermRuntimeData,
repTypeParser: Parser, repTypeRuntimeData: ElementRuntimeData,
- dispatchBranchKeyMap:
Map[String, (Parser, Boolean)],
dispatchKeyRangeMap:Vector[(RangeBound,RangeBound,Parser, Boolean)])
- extends ChoiceDispatchCombinatorParserBase(rd, dispatchBranchKeyMap,
dispatchKeyRangeMap)
- with WithDetachedParser {
-
-// override lazy val childProcessors =
dispatchBranchKeyMap.values.map(_._1).toVector ++ dispatchKeyRangeMap.map(_._3)
- override lazy val childProcessors = super.childProcessors ++
Vector(repTypeParser)
-
- override def computeDispatchKey(pstate: PState): Maybe[String] = {
- val ans1 = runDetachedParser(pstate, repTypeParser, repTypeRuntimeData)
- if (ans1.isDefined) {
- Maybe(ans1.getAnyRef.toString())
- } else {
- Maybe.Nope
- }
- }
-
-}
diff --git
a/daffodil-test/src/test/resources/org/apache/daffodil/extensions/type_calc/inputTypeCalc.tdml
b/daffodil-test/src/test/resources/org/apache/daffodil/extensions/type_calc/inputTypeCalc.tdml
index 1fe8f8b..74c6ec9 100644
---
a/daffodil-test/src/test/resources/org/apache/daffodil/extensions/type_calc/inputTypeCalc.tdml
+++
b/daffodil-test/src/test/resources/org/apache/daffodil/extensions/type_calc/inputTypeCalc.tdml
@@ -104,60 +104,6 @@
</xs:restriction>
</xs:simpleType>
- <xs:element name="choice_dispatchKeyByType_01">
- <xs:complexType>
- <xs:choice dfdlx:choiceBranchKeyKind="explicit"
dfdlx:choiceDispatchKeyKind="byType" >
- <xs:element name="unreachable" type="tns:unreachableRepTypeuint8"
dfdl:choiceBranchKey="-1"/>
- <xs:element name="one" type="tns:_1_to_string"
dfdl:choiceBranchKey="1"/>
- <xs:element name="two" type="tns:_2through100_to_string"
dfdl:choiceBranchKey="2"/>
- <xs:element name="three_four_five" type="tns:_2through100_to_string"
dfdl:choiceBranchKey="3 4 5"/>
- <xs:element name="_101_122" type="tns:complexSet_to_string"
dfdl:choiceBranchKey="101 122"/>
- </xs:choice>
- </xs:complexType>
- </xs:element>
-
- <xs:element name="choice_dispatchKeyByType_02">
- <xs:complexType>
- <xs:sequence>
- <xs:element name="byte" dfdl:occursCountKind="parsed"
maxOccurs="unbounded">
- <xs:complexType>
- <xs:choice dfdlx:choiceBranchKeyKind="explicit"
dfdlx:choiceDispatchKeyKind="byType" >
- <xs:element name="unreachable"
type="tns:unreachableRepTypeuint8" dfdl:choiceBranchKey="255"/>
- <xs:element name="one" type="tns:_1_to_string"
dfdl:choiceBranchKey="1"/>
- <xs:element name="two" type="tns:_2through100_to_string"
dfdl:choiceBranchKey="2"/>
- <xs:element name="three_four_five"
type="tns:_2through100_to_string" dfdl:choiceBranchKey="3 4 5"/>
- <xs:element name="_101_122" type="tns:complexSet_to_string"
dfdl:choiceBranchKey="101 122"/>
- </xs:choice>
- </xs:complexType>
- </xs:element>
- </xs:sequence>
- </xs:complexType>
- </xs:element>
-
- <xs:element name="choice_branchKeyByType_01">
- <xs:complexType>
- <xs:sequence>
- <xs:element name="byte" dfdl:occursCountKind="parsed"
maxOccurs="unbounded">
- <xs:complexType>
- <xs:sequence>
- <xs:element name="dispatchKey" type="tns:uint8">
- <xs:annotation>
- <xs:appinfo source="http://www.ogf.org/dfdl/">
- <dfdl:discriminator>{ fn:true() }</dfdl:discriminator>
- </xs:appinfo>
- </xs:annotation>
- </xs:element>
- <xs:choice dfdlx:choiceBranchKeyKind="byType"
dfdlx:choiceDispatchKeyKind="explicit" dfdl:choiceDispatchKey="{ ex:dispatchKey
}">
- <xs:element name="unreachable"
type="tns:unreachableRepTypeuint8"/>
- <xs:element name="many" type="tns:_2through100_to_int"/>
- <xs:element name="one" type="tns:_1_to_string"/>
- </xs:choice>
- </xs:sequence>
- </xs:complexType>
- </xs:element>
- </xs:sequence>
- </xs:complexType>
- </xs:element>
<xs:element name="inputTypeCalc_unionOfKeysetValueCalcs_01">
<xs:complexType>
@@ -167,21 +113,6 @@
</xs:complexType>
</xs:element>
- <xs:element name="inputTypeCalc_unionOfKeysetValueCalcs_02">
- <xs:complexType>
- <xs:sequence>
- <xs:element name="byte" maxOccurs="unbounded"
dfdl:occursCountKind="parsed">
- <xs:complexType>
- <xs:choice dfdlx:choiceBranchKeyKind="byType"
dfdlx:choiceDispatchKeyKind="byType">
- <xs:element name="a" type="tns:_1through100_union_to_string"/>
- <xs:element name="b" type="tns:complexSet_to_string"/>
- </xs:choice>
- </xs:complexType>
- </xs:element>
- </xs:sequence>
- </xs:complexType>
- </xs:element>
-
</tdml:defineSchema>
<tdml:parserTestCase name="InputTypeCalc_keysetValue_00"
@@ -305,126 +236,6 @@
</tdml:infoset>
</tdml:unparserTestCase>
- <tdml:parserTestCase name="InputTypeCalc_choiceDispatchByType_01"
- root="choice_dispatchKeyByType_01" model="inputTypeCalc-Embedded.dfdl.xsd"
description="Extensions - choiceDispatchByType with keysetValue types">
-
- <tdml:document>
- <tdml:documentPart type="byte">
- 01
- </tdml:documentPart>
- </tdml:document>
- <tdml:infoset>
- <tdml:dfdlInfoset xmlns:xs="http://www.w3.org/2001/XMLSchema"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
- <choice_dispatchKeyByType_01>
- <one>one</one>
- </choice_dispatchKeyByType_01>
- </tdml:dfdlInfoset>
- </tdml:infoset>
- </tdml:parserTestCase>
-
- <tdml:parserTestCase name="InputTypeCalc_choiceDispatchByType_02"
- root="choice_dispatchKeyByType_02" model="inputTypeCalc-Embedded.dfdl.xsd"
description="Extensions - choiceDispatchByType with keysetValue types">
-
- <tdml:document>
- <tdml:documentPart type="byte">
- 01 02 03 04 05 65 7A
- </tdml:documentPart>
- </tdml:document>
- <tdml:infoset>
- <tdml:dfdlInfoset xmlns:xs="http://www.w3.org/2001/XMLSchema"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
- <choice_dispatchKeyByType_02>
- <byte><one>one</one></byte>
- <byte><two>2-100</two></byte>
- <byte><three_four_five>2-100</three_four_five></byte>
- <byte><three_four_five>2-100</three_four_five></byte>
- <byte><three_four_five>2-100</three_four_five></byte>
- <byte><_101_122>101 103-110 115 120-125</_101_122></byte>
- <byte><_101_122>101 103-110 115 120-125</_101_122></byte>
- </choice_dispatchKeyByType_02>
- </tdml:dfdlInfoset>
- </tdml:infoset>
- </tdml:parserTestCase>
-
- <tdml:parserTestCase name="InputTypeCalc_choiceDispatchByType_03"
- root="choice_dispatchKeyByType_01" model="inputTypeCalc-Embedded.dfdl.xsd"
description="Extensions - choiceDispatchByType with keysetValue types - bad
key">
-
- <tdml:document>
- <tdml:documentPart type="byte">
- ff
- </tdml:documentPart>
- </tdml:document>
- <tdml:errors>
- <tdml:error>Parse Error</tdml:error>
- <tdml:error>Failed to match any of the branch keys</tdml:error>
- </tdml:errors>
- </tdml:parserTestCase>
-
- <tdml:unparserTestCase name="InputTypeCalc_unparse_choiceDispatchByType_01"
- root="choice_dispatchKeyByType_01" model="inputTypeCalc-Embedded.dfdl.xsd"
description="Extensions - choiceDispatchByType with keysetValue types">
-
- <tdml:document>
- <tdml:documentPart type="byte">
- 01
- </tdml:documentPart>
- </tdml:document>
- <tdml:infoset>
- <tdml:dfdlInfoset xmlns:xs="http://www.w3.org/2001/XMLSchema"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
- <choice_dispatchKeyByType_01>
- <one>one</one>
- </choice_dispatchKeyByType_01>
- </tdml:dfdlInfoset>
- </tdml:infoset>
- </tdml:unparserTestCase>
-
- <tdml:unparserTestCase name="InputTypeCalc_unparse_choiceDispatchByType_02"
- root="choice_dispatchKeyByType_02" model="inputTypeCalc-Embedded.dfdl.xsd"
description="Extensions - choiceDispatchByType with keysetValue types">
-
- <tdml:document>
- <tdml:documentPart type="byte">
- 01 02 02 65
- </tdml:documentPart>
- </tdml:document>
- <tdml:infoset>
- <tdml:dfdlInfoset xmlns:xs="http://www.w3.org/2001/XMLSchema"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
- <choice_dispatchKeyByType_02>
- <byte><one>one</one></byte>
- <byte><two>2-100</two></byte>
-
- <!-- It is a bit unclear what the below should unparse to.
- Since it's type is 2-100, it would normally unparse to 2 if it
- were outside of the choice, so this test expects that here.
- -->
- <byte><three_four_five>2-100</three_four_five></byte>
- <byte><_101_122>101 103-110 115 120-125</_101_122></byte>
- </choice_dispatchKeyByType_02>
- </tdml:dfdlInfoset>
- </tdml:infoset>
- </tdml:unparserTestCase>
-
- <tdml:parserTestCase name="InputTypeCalc_choiceBranchKeyByType_01"
- root="choice_branchKeyByType_01" model="inputTypeCalc-Embedded.dfdl.xsd"
description="Extensions - choiceBranchKeyByType with keysetValue types">
-
- <tdml:document>
- <tdml:documentPart type="byte">
- 01 01 02 02 07 08
- </tdml:documentPart>
- </tdml:document>
- <tdml:infoset>
- <tdml:dfdlInfoset xmlns:xs="http://www.w3.org/2001/XMLSchema"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
- <choice_branchKeyByType_01>
- <byte><dispatchKey>1</dispatchKey><one>one</one></byte>
- <byte><dispatchKey>2</dispatchKey><many>2</many></byte>
- <byte><dispatchKey>7</dispatchKey><many>8</many></byte>
- </choice_branchKeyByType_01>
- </tdml:dfdlInfoset>
- </tdml:infoset>
- </tdml:parserTestCase>
-
<tdml:parserTestCase name="InputTypeCalc_unionOfKeysetValueCalcs_01"
root="inputTypeCalc_unionOfKeysetValueCalcs_01"
model="inputTypeCalc-Embedded.dfdl.xsd" description="Extensions - repType with
union of keysetValue types">
@@ -465,47 +276,4 @@
</tdml:infoset>
</tdml:unparserTestCase>
- <tdml:parserTestCase name="InputTypeCalc_unionOfKeysetValueCalcs_02"
- root="inputTypeCalc_unionOfKeysetValueCalcs_02"
model="inputTypeCalc-Embedded.dfdl.xsd" description="Extensions - repType with
union of keysetValue types">
-
- <tdml:document>
- <tdml:documentPart type="byte">
- 01 02 03 64 65 67
- </tdml:documentPart>
- </tdml:document>
- <tdml:infoset>
- <tdml:dfdlInfoset xmlns:xs="http://www.w3.org/2001/XMLSchema"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
- <inputTypeCalc_unionOfKeysetValueCalcs_02>
- <byte><a>one</a></byte>
- <byte><a>2-100</a></byte>
- <byte><a>2-100</a></byte>
- <byte><a>2-100</a></byte>
- <byte><b>101 103-110 115 120-125</b></byte>
- <byte><b>101 103-110 115 120-125</b></byte>
- </inputTypeCalc_unionOfKeysetValueCalcs_02>
- </tdml:dfdlInfoset>
- </tdml:infoset>
- </tdml:parserTestCase>
-
- <tdml:unparserTestCase
name="InputTypeCalc_unparse_unionOfKeysetValueCalcs_02"
- root="inputTypeCalc_unionOfKeysetValueCalcs_02"
model="inputTypeCalc-Embedded.dfdl.xsd" description="Extensions - repType with
union of keysetValue types">
-
- <tdml:document>
- <tdml:documentPart type="byte">
- 01 02 65
- </tdml:documentPart>
- </tdml:document>
- <tdml:infoset>
- <tdml:dfdlInfoset xmlns:xs="http://www.w3.org/2001/XMLSchema"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
- <inputTypeCalc_unionOfKeysetValueCalcs_02>
- <byte><a>one</a></byte>
- <byte><a>2-100</a></byte>
- <byte><b>101 103-110 115 120-125</b></byte>
- </inputTypeCalc_unionOfKeysetValueCalcs_02>
- </tdml:dfdlInfoset>
- </tdml:infoset>
- </tdml:unparserTestCase>
-
</tdml:testSuite>
diff --git
a/daffodil-test/src/test/scala/org/apache/daffodil/extensions/TestInputTypeValueCalc.scala
b/daffodil-test/src/test/scala/org/apache/daffodil/extensions/TestInputTypeValueCalc.scala
index b9d5991..b54e524 100644
---
a/daffodil-test/src/test/scala/org/apache/daffodil/extensions/TestInputTypeValueCalc.scala
+++
b/daffodil-test/src/test/scala/org/apache/daffodil/extensions/TestInputTypeValueCalc.scala
@@ -48,21 +48,9 @@ class TestInputTypeValueCalc {
@Test def test_InputTypeCalc_unparse_keysetValue_01(): Unit = {
runner.runOneTest("InputTypeCalc_unparse_keysetValue_01") }
@Test def test_InputTypeCalc_unparse_keysetValue_02(): Unit = {
runner.runOneTest("InputTypeCalc_unparse_keysetValue_02") }
- @Test def test_InputTypeCalc_choiceDispatchByType_01(): Unit = {
runner.runOneTest("InputTypeCalc_choiceDispatchByType_01") }
- @Test def test_InputTypeCalc_choiceDispatchByType_02(): Unit = {
runner.runOneTest("InputTypeCalc_choiceDispatchByType_02") }
- @Test def test_InputTypeCalc_choiceDispatchByType_03(): Unit = {
runner.runOneTest("InputTypeCalc_choiceDispatchByType_03") }
-
- @Test def test_InputTypeCalc_unparse_choiceDispatchByType_01(): Unit = {
runner.runOneTest("InputTypeCalc_unparse_choiceDispatchByType_01") }
- @Test def test_InputTypeCalc_unparse_choiceDispatchByType_02(): Unit = {
runner.runOneTest("InputTypeCalc_unparse_choiceDispatchByType_02") }
-
- @Test def test_InputTypeCalc_choiceBranchKeyByType_01(): Unit = {
runner.runOneTest("InputTypeCalc_choiceBranchKeyByType_01") }
-
@Test def test_InputTypeCalc_unionOfKeysetValueCalcs_01(): Unit = {
runner.runOneTest("InputTypeCalc_unionOfKeysetValueCalcs_01") }
@Test def test_InputTypeCalc_unparse_unionOfKeysetValueCalcs_01(): Unit = {
runner.runOneTest("InputTypeCalc_unparse_unionOfKeysetValueCalcs_01") }
- @Test def test_InputTypeCalc_unionOfKeysetValueCalcs_02(): Unit = {
runner.runOneTest("InputTypeCalc_unionOfKeysetValueCalcs_02") }
- @Test def test_InputTypeCalc_unparse_unionOfKeysetValueCalcs_02(): Unit = {
runner.runOneTest("InputTypeCalc_unparse_unionOfKeysetValueCalcs_02") }
-
@Test def test_InputTypeCalc_expression_01(): Unit = {
exprRunner.runOneTest("InputTypeCalc_expression_01") }
@Test def test_OutputTypeCalc_expression_01(): Unit = {
exprRunner.runOneTest("OutputTypeCalc_expression_01") }
@Test def test_InputTypeCalc_expression_02(): Unit = {
exprRunner.runOneTest("InputTypeCalc_expression_02") }