jadams-tresys commented on a change in pull request #207: Added support for
enumerations and TypeValueCalc
URL: https://github.com/apache/incubator-daffodil/pull/207#discussion_r275964158
##########
File path:
daffodil-core/src/main/scala/org/apache/daffodil/dsom/RestrictionUnion.scala
##########
@@ -166,16 +175,126 @@ final class Restriction(xmlArg: Node, val simpleType:
SimpleTypeDefBase)
case None => Nil
}
}.value
+
+ lazy val enumerations: Seq[EnumerationDefFactory] = (xml \
"enumeration").map(new EnumerationDefFactory(_, simpleTypeFactory))
+
+ lazy val facetValueSet: RepValueSet[AnyRef] = {
+ val initAns: (RangeBound[BigInt], RangeBound[BigInt]) = (new
RangeBound(Maybe.Nope, false), new RangeBound(Maybe.Nope, false))
+ val range = combinedBaseFacets.foldLeft(initAns)({
+ case (acc, (facetType, facetValue)) =>
+ lazy val valueAsBigInt = BigInt(facetValue)
+ val (maybeBound, isMax, isInclusive) = facetType match {
+ case Facet.maxExclusive => (Maybe(valueAsBigInt), true, false)
+ case Facet.maxInclusive => (Maybe(valueAsBigInt), true, true)
+ case Facet.minExclusive => (Maybe(valueAsBigInt), false, false)
+ case Facet.minInclusive => (Maybe(valueAsBigInt), false, true)
+ case _ => (Maybe.Nope, false, false)
+ }
+ if (maybeBound.isEmpty) {
+ acc
+ } else {
+ if (isMax) {
+ val oldMax = acc._2
+ if (!oldMax.isEmpty) {
+ SDE("Cannot define multiple max bounds on restriction")
+ }
+ val newMax = new RangeBound(maybeBound, isInclusive)
+ (acc._1, newMax)
+ } else {
+ val oldMin = acc._1
+ if (!oldMin.isEmpty) {
+ SDE("Cannot define multiple min bounds on restriction")
+ }
+ val newMin = new RangeBound(maybeBound, isInclusive)
+ (newMin, acc._2)
+ }
+ }
+ })
+ RepValueSetCompiler.compile(Seq(),
Seq(range.asInstanceOf[(RangeBound[AnyRef], RangeBound[AnyRef])]))
+ }
+ lazy val repValueSet: RepValueSet[AnyRef] = {
+ val subsets =
enumerations.map(_.optRepValueSet).filter(_.isDefined).map(_.get)
+ if (subsets.length != 0 && subsets.length != enumerations.length) {
+ context.SDE("If one enumeration value defines a repValue, then all must
define a repValue")
+ }
+ val fromEnums = subsets.fold(RepValueSetCompiler.empty)((a, b) =>
a.merge(b))
+ if (enumerations.length > 0) {
+ fromEnums
+ } else {
+ //We are some form of identity mapping, so our facetValues are also our
repValues
+ facetValueSet
+ }
+ }
+ lazy val optRepValueSet = if (repValueSet.isEmpty) None else
Some(repValueSet)
+
+ lazy val logicalValueSet: RepValueSet[AnyRef] = {
+ val subsets = enumerations.map(_.logicalValueSet)
+ if (subsets.length != 0 && subsets.length != enumerations.length) {
+ context.SDE("If one enumeration value defines a repValue, then all must
define a repValue")
+ }
+ val fromEnums = subsets.fold(RepValueSetCompiler.empty)((a, b) =>
a.merge(b))
+ if (enumerations.length > 0) {
+ fromEnums
+ } else {
+ //We are some form of identity mapping, so our facetValues are also our
repValues
+ facetValueSet
+ }
+ }
+ lazy val optLogicalValueSet:Option[RepValueSet[AnyRef]] =
if(logicalValueSet.isEmpty) None else Some(logicalValueSet)
+
+ lazy val optRepType:Option[SimpleTypeBase] = {
+ enumerations.map(_.optRepTypeFactory)
+ ???
Review comment:
This should be addressed before being merged.
----------------------------------------------------------------
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