stevedlawrence commented on a change in pull request #262: Unordered sequences
URL: https://github.com/apache/incubator-daffodil/pull/262#discussion_r318160514
##########
File path:
daffodil-core/src/main/scala/org/apache/daffodil/grammar/primitives/SequenceCombinator.scala
##########
@@ -76,3 +78,63 @@ class OrderedSequence(sq: SequenceTermBase,
sequenceChildrenArg: Seq[SequenceChi
}
}
}
+
+class UnorderedSequence(sq: SequenceTermBase, sequenceChildrenArg:
Seq[SequenceChild], alternatives: Seq[Gram])
+ extends SequenceCombinator(sq, sequenceChildrenArg) {
+
+ private lazy val sepGram = sq.sequenceSeparator
+ private lazy val sepParser = sepGram.parser
+ private lazy val sepUnparser = sepGram.unparser
+
+ private lazy val sequenceChildren = sequenceChildrenArg.toVector
+
+
+ private lazy val parsers = {
+ val res = alternatives.map { alt =>
+ val p = alt.parser
+ val res =
+ if (p.isEmpty)
+ new EmptyChoiceBranchParser(alt.context.runtimeData)
+ else
+ p
+ res
+ }
+ res
+ }
+
+
+ override lazy val parser: Parser = sq.hasSeparator match {
+ case true => {
+ lazy val choiceParser = new ChoiceParser(srd, sepParser +:
parsers.toVector)
+ new UnorderedSeparatedSequenceParser(
+ srd, sq.separatorPosition, sepParser,
+ choiceParser,
+ parsers.toVector)
Review comment:
Why is parsers need in the UnorderedSeparatedSequenceParser? Doesn't it just
keep parsing the choiceParser until that fails?
Also, this calls toVector on the parsers twice, so this creates two
duplicate Vectors. Instead, this should call toVector once and pass the same
result into the two classes.
Same thing for the unseparated case.
----------------------------------------------------------------
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