mbeckerle commented on a change in pull request #74: Daffodil trailing sep URL: https://github.com/apache/incubator-daffodil/pull/74#discussion_r204080825
########## File path: daffodil-core/src/main/scala/org/apache/daffodil/grammar/primitives/ComplexTypeCombinator.scala ########## @@ -0,0 +1,53 @@ +/* + * 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.{ Parser => DaffodilParser } +import org.apache.daffodil.processors.unparsers.{ Unparser => DaffodilUnparser } +import org.apache.daffodil.processors.parsers._ +import org.apache.daffodil.processors.unparsers._ +import org.apache.daffodil.grammar.Gram +import org.apache.daffodil.util.Misc + +case class ComplexTypeCombinator(ct: ComplexTypeBase, body: Gram) extends Terminal(ct.elementDecl, !body.isEmpty) { + + override def isEmpty = body.isEmpty + + private lazy val p = body.parser + private lazy val u = body.unparser + + override def toString() = + "<" + Misc.getNameFromClass(this) + ">" + + body.toString() + + "</" + Misc.getNameFromClass(this) + ">" + + override lazy val parser: DaffodilParser = + if (p.isEmpty) + p Review comment: This theoretically happens if the entire body of the complex type gets optimized away. Lots of the encapsulating wrapper combinators look at the parsers, and attempt to propagate the empty parser (NadaParser) to allow it to be fully optimized out. The runtime no longer has any actual use for NadaParsers. They always are optimized out. The only case I can think of is if someone has an element with a complex type that exists as a placeholder for the future, but it actually contains nothing other than doc string annotations, so fully optimizes away. But then I'd think body.isEmpty would be true, and the whole thing would go away at the grammar level. I guess if you have complex types that are 100% parser-only or 100% unparser only, then these tests could be true. It *is* possible to have conditional behavior in schemas so that some parts of the schema are only for parsing or only for unparsing, but I'm not sure the schema compiler can detect that. ComplexTypeParser and ComplexTypeUnparser exist essentially for trace/debug purposes, and to be shared (in the future) parsers/unparsers for named complex type definitions. I might change these p.isEmpty to assert !p.isEmpty here instead, and see if it ever fails. ---------------------------------------------------------------- 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: [email protected] With regards, Apache Git Services
