stevedlawrence commented on a change in pull request #74: Daffodil trailing sep
URL: https://github.com/apache/incubator-daffodil/pull/74#discussion_r195070198
 
 

 ##########
 File path: 
daffodil-core/src/main/scala/org/apache/daffodil/grammar/primitives/ChoiceCombinator.scala
 ##########
 @@ -0,0 +1,124 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.daffodil.grammar.primitives
+
+import org.apache.daffodil.grammar.Terminal
+import org.apache.daffodil.dsom._
+import org.apache.daffodil.processors.parsers._
+import org.apache.daffodil.processors.unparsers._
+import org.apache.daffodil.grammar.Gram
+import org.apache.daffodil.exceptions.Assert
+import org.apache.daffodil.cookers.ChoiceBranchKeyCooker
+import org.apache.daffodil.api.WarnID
+import org.apache.daffodil.equality._
+
+/*
+ * The purpose of the ChoiceCombinator (and the parsers it creates) is to
+ * determine which branch to go down. In the parser case, for non-direct
+ * dispatch, we just rely on backtracking here.
+ *
+ * For direct dispatch, we create a disapatch-branch key map
+ * which is used to determine which branch to parse at runtime.
+ *
+ * In the unparser case, we know which element we got from the infoset, but we
+ * need to determine which branch of the choice to take at runtime. This
+ * unparser uses a Map to make the determination based on the element seen.
+ */
+case class ChoiceCombinator(ch: ChoiceTermBase, rawAlternatives: Seq[Gram])
+  extends Terminal(ch, !rawAlternatives.isEmpty) {
+
+  private lazy val alternatives = rawAlternatives.filterNot(_.isEmpty)
+
+  private lazy val parsers = alternatives.map { _.parser }.filterNot { 
_.isEmpty }
+
+  override def isEmpty = super.isEmpty || alternatives.isEmpty
 
 Review comment:
   Should this be parsers.isEmpty? Is it possible that alternatives is not 
empty but parsers is?

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to