stevedlawrence commented on a change in pull request #259: Incremental progress 
on schema compilation space/speed issue.
URL: https://github.com/apache/incubator-daffodil/pull/259#discussion_r301550474
 
 

 ##########
 File path: 
daffodil-core/src/main/scala/org/apache/daffodil/dpath/Expression.scala
 ##########
 @@ -943,155 +950,148 @@ sealed abstract class StepExpression(val step: String, 
val pred: Option[Predicat
     NodeInfo.ArrayIndex
   }
 
+}
+
+sealed abstract class DownStepExpression(s: String, predArg: 
Option[PredicateExpression])
+  extends StepExpression(s, predArg) {
+
   override lazy val inherentType: NodeInfo.Kind = {
     if (!isLastStep) NodeInfo.Complex
     else {
-      if (stepElement.optPrimType.isDefined) {
+      if (stepElements.head.optPrimType.isDefined) {
         // simple type, so
-        val pt = stepElement.optPrimType.get
+        val pt = stepElements.head.optPrimType.get
         pt
       } else {
         NodeInfo.Complex
       }
     }
   }
-
 }
 
-//TODO: Is ".[i]" ever a valid expression in DFDL?
+// TODO: Is ".[i]" ever a valid expression in DFDL?
+// Yes. For an array element, .[1] is the first occurrence.
 
-case class Self(predArg: Option[PredicateExpression]) extends 
StepExpression(null, predArg) {
+sealed abstract class SelfStepExpression(s: String, predArg: 
Option[PredicateExpression])
+  extends DownStepExpression(s, predArg) {
 
   override lazy val compiledDPath = new CompiledDPath(SelfMove +: conversions)
-
   override def text = "."
 
-  override lazy val stepElement: DPathElementCompileInfo =
-    priorStep.map { _.stepElement }.getOrElse {
-      //  no prior step, so we're the first step
-      this.compileInfo.elementCompileInfo.getOrElse {
-        relPathErr()
+  override lazy val stepElements = stepElementDefs
+
+  protected def stepElementDefs: Seq[DPathElementCompileInfo] = {
+    if (this.isFirstStep) {
+      val ecs = compileInfo.elementCompileInfos
+      if (ecs.isEmpty) {
+        SDE("There is no enclosing element")
       }
-    }
+      ecs
+    } else
+      priorStep.get match {
+        case priorUp: UpStepExpression => SDE("Path '../.' is not allowed.")
+        case priorDown: DownStepExpression => priorDown.stepElements
+        case x => Assert.invariantFailed("Not recognized: " + x)
+      }
+  }
 }
 
+case class Self(predArg: Option[PredicateExpression])
+  extends SelfStepExpression(null, predArg)
+
 /**
  * Different from Self in that it verifies the qName (s) is
  * the name of the context.
  */
 case class Self2(s: String, predArg: Option[PredicateExpression])
-  extends StepExpression(s, predArg) {
+  extends SelfStepExpression(s, predArg) {
 
   requiredEvaluations(stepQName)
 
-  override lazy val compiledDPath = new CompiledDPath(SelfMove +: conversions)
+  override def stepElementDefs: Seq[DPathElementCompileInfo] = {
+    val cis = super.stepElementDefs
+    cis.map { ci =>
+      if (!ci.namedQName.matches(stepQName))
+        ci.noMatchError(stepQName)
+      ci
+    }
+  }
+}
 
-  override def text = "."
+sealed abstract class UpStepExpression(s: String, predArg: 
Option[PredicateExpression])
+  extends StepExpression(s, predArg) {
+
+  override def text = ".." // + "{" + stepElement.path + "}"
 
 Review comment:
   Remove comment? I'm not sure what that's trying to say? 

----------------------------------------------------------------
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:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to