stevedlawrence commented on a change in pull request #207: Added support for
enumerations and TypeValueCalc
URL: https://github.com/apache/incubator-daffodil/pull/207#discussion_r278603539
##########
File path:
daffodil-core/src/main/scala/org/apache/daffodil/dsom/SimpleTypes.scala
##########
@@ -40,14 +69,70 @@ trait NonPrimTypeMixin {
}
}
-sealed trait SimpleTypeBase extends TypeBase {
- def primType: NodeInfo.PrimType = {
- optRestriction.map { _.primType }.getOrElse {
- optUnion.map { _.primType }.getOrElse {
- Assert.invariantFailed("must be either a restriction or union")
+sealed trait SimpleTypeBase extends TypeBase
+ with hasOptRepTypeMixin {
+
+ def primType: PrimType
+
+}
+
+/*
+ * For components which can define dfdl:repValues and dfdl:repValueRanges
+ * Construct the repValueSet using only the above mentioned attributes on the
element itself
+ * Applies to simpleType and enumeration
+ *
+ * In the case of simpleType, it is possible that optRepValueSetFromAttribute
will be none
+ * but the element will still have an optRepValueSet for another source (eg.
children elements)
+ */
+sealed trait HasRepValueAttributes extends AnnotatedSchemaComponent {
+ def optRepTypeFactory: Option[SimpleTypeFactory]
+ def optRepValueSet: Option[RepValueSet[AnyRef]]
+
+ lazy val (repValuesAttrCooked: Seq[AnyRef], repValueRangesAttrCooked:
Seq[(RangeBound[BigInt], RangeBound[BigInt])]) = optRepTypeFactory match {
+ case Some(repType) => {
+ val repValueSetRaw =
findPropertyOptionThisComponentOnly("repValues").toOption
+ .map(_.split("\\s+").toSeq).getOrElse(Seq())
+ val repValueRangesRaw =
findPropertyOptionThisComponentOnly("repValueRanges").toOption
+ .map(_.split("\\s+").toSeq).getOrElse(Seq())
+ repType.primType match {
+ case PrimType.String => {
+ if (repValueRangesRaw.size > 0) context.SDE("repValueRanges set when
using a string repType")
+ val repValueSetCooked =
repValueRangesRaw.map(RepValueCooker.convertConstant(_, context, false))
+ (repValueSetCooked, Seq())
+ }
+ case _: NodeInfo.Integer.Kind => {
+ if (repValueRangesRaw.size % 2 != 0) context.SDE("repValueRanges
must have an even number of elements")
+ val ans1 = repValueSetRaw.map(BigInt(_))
+ def cookRepValueRanges(xs: Seq[String]): Seq[(RangeBound[BigInt],
RangeBound[BigInt])] = {
+ xs match {
+ case Seq() => Seq()
+ case a +: b +: rest => {
+ val a2 = BigInt(a)
+ val b2 = BigInt(b)
+ if (a2.compare(b2) > 0) {
+ context.SDE("min value must not be greater than max value")
Review comment:
Would be helpful to a user if this messsage include the two values as well
as the string "repValueRange". If there's 50 different ranges, it would make it
easiser to find where the bad one is.
----------------------------------------------------------------
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