mbeckerle commented on a change in pull request #214: Sequences and Separators
Refactoring and Rewrite
URL: https://github.com/apache/incubator-daffodil/pull/214#discussion_r285236000
##########
File path:
daffodil-runtime1/src/main/scala/org/apache/daffodil/processors/parsers/SequenceChildBases.scala
##########
@@ -37,86 +40,136 @@ import org.apache.daffodil.processors.ParseOrUnparseState
sealed trait ParseAttemptStatus {
def isSuccess: Boolean = false
}
-sealed trait SuccessParseAttemptStatus extends ParseAttemptStatus {
- override def isSuccess = true
-}
-sealed trait FailedParseAttemptStatus extends ParseAttemptStatus {
- override def isSuccess = false
-}
object ParseAttemptStatus {
-
+ type Type = ParseAttemptStatus
+ sealed trait SuccessParseAttemptStatus extends Type {
+ override def isSuccess = true
+ }
+ sealed trait FailedParseAttemptStatus extends Type {
+ override def isSuccess = false
+ }
/**
* State that we initialize the variable to. Only exists until the first
* parse attempt.
*/
- case object Uninitialized extends ParseAttemptStatus
+ case object Uninitialized extends Type
/**
- * The parse succeeded. The parse consumed no bits - i.e., was zero length.
- */
- case object Success_ZeroLength extends SuccessParseAttemptStatus
-
- /**
- * The parse succeeded. The parse consumed a separator that is being skipped.
+ * Means the Nil representation was found in the data stream.
*
- * This is used only by separated sequences, and only for optional
occurrences
- * when a separator is being passed over and ignored, without an occurrence
- * being added to the infoset.
+ * Used only on nillable elements.
+ *
+ * The NilRep has priority over other representations. Due to
+ * dfdl:nilValueDelimiterPolicy, the NilRep can be zero-length or non-zero
length.
*/
- case object Success_SkippedSeparator extends SuccessParseAttemptStatus
+ case object NilRep extends SuccessParseAttemptStatus
/**
- * The parse succeeded. The parse consumed some bits - was not zero length.
+ * Empty rep is second in priority to NilRep. Due to
+ * dfdl:emptyValueDelimiterPolicy, the EmptyRep can be zero-length or
non-zero-length, which
+ * allows the schema author to arrange for it to be distinguished from
AbsentRep.
+ *
+ * An example would be dfdl:emptyValueDelimiterPolicy="both"
dfdl:initiator='"' dfdl:terminator='"'.
+ * Then in comma separated data, if you want to specify that a field
contains an empty string,
+ * the data must contain ....,"",.... i.e., open-close quotes to indicate a
literal empty string.
+ *
+ * The EmptyRep for simpleTypes enables default values to be substituted at
parse time.
+ *
+ * For simple types xs:string and xs:hexBinary, the property
daf:emptyElementPolicy controls
+ * whether the EmptyRep is allowed for strings and hexBinary. In required
positions, when
+ * daf:emptyElementPolicy is 'emptySuppressed', a required string/hexBinary
that has EmptyRep
+ * causes a Parse Error, and an optional EmptyRep causes nothing to be added
to the infoset (the empty string
+ * or hexBinary value is suppressed). When daf:emptyElementPolicy is
'emptyAllowed', a required
+ * string/hexBinary with EmptyRep creates an empty string or zero-length
byte array in the infoset.
+ * An optional EmptyRep behaves differently depending on whether the
EmptyRep is truly zero-length, or
+ * dfdl:emptyValueDelimiterPolicy is such that EmptyRep is non-zero-length.
When truly zero-length, no
+ * value is added to the infoset. When non-zero-length, an empty string or
zero-length byte array is added
+ * to the infoset at the current index.
+ *
+ * An element may have no EmptyRep. For example, a fixed-length data element
has no EmptyRep.
+ *
+ * An element of complex type can have EmptyRep, but
dfdl:emptyValueDelimiterPolicy does not apply.
+ * TBD: CONFIRM THIS. When a complex type element is parsed, and zero data
is consumed, but the parse is successful,
+ * then any infoset created is the "empty value" for this complex type
element. When the element is required,
+ * this infoset is retained. When the element is optional, this infoset is
discarded, any side-effects that occurred
+ * in its creation are backtracked.
*/
- case object Success_NotZeroLength extends SuccessParseAttemptStatus
+ case object EmptyRep extends SuccessParseAttemptStatus
/**
- * The parse succeeded. We did not keep track of whether it consumed bits or
not.
+ * When the parse is successful, and the data did not match NilRep(if
nillable) or EmptyRep(if defined/meaningful.)
*/
- case object Success_LengthUndetermined extends SuccessParseAttemptStatus
+ case object NormalRep extends SuccessParseAttemptStatus
Review comment:
Insert scaladoc for NormalRep: means the data in the data stream matches the
representation required for the type of the element. For all simple types other
than string and hexBinary, this requires some representation in the data
stream. For string and hexBinary it is possible for "normal" data to be empty
string, in which case normalRep is the same thing as emptyRep, and so can be
ambiguous with absentRep
----------------------------------------------------------------
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