def act()

in daffodil-runtime1/src/main/scala/org/apache/daffodil/runtime1/debugger/InteractiveDebugger.scala [1080:1178]


      def act(
        args: Seq[String],
        state: ParseOrUnparseState,
        processor: Processor
      ): DebugState.Type = {
        val expressionList = args
        val expression = expressionList.mkString(" ")

        if (!state.hasInfoset) {
          debugPrintln("eval: There is no infoset currently.")
          return DebugState.Pause
        }
        val element = state.infoset
        // this adjustment is so that automatic display of ".." doesn't fail
        // for the root element.
        val adjustedExpression =
          if ((element.parent eq null) && (expression == "..")) "."
          else expression
        val context = state.getContext()
        val namespaces = context.dpathCompileInfo.namespaces
        val noPrefixNamespace = context.dpathCompileInfo.noPrefixNamespace
        val expressionWithBraces =
          if (!DPathUtil.isExpression(adjustedExpression)) "{ " + adjustedExpression + " }"
          else adjustedExpression
        val isEvaluatedAbove = false
        try {
          val hostForDiags = new DebuggerHost(state.tunable)
          val compiledExpression = eCompilers.AnyRef.compileExpression(
            debuggerQName,
            NodeInfo.AnyType,
            expressionWithBraces,
            namespaces,
            noPrefixNamespace,
            context.dpathCompileInfo,
            isEvaluatedAbove,
            hostForDiags,
            context.dpathElementCompileInfo
          )
          val res = compiledExpression.evaluate(state)
          val warnings = hostForDiags.getDiagnostics.filterNot(_.isError)
          warnings.foreach {
            debugPrintln(_)
          }
          res match {
            case ie: InfosetElement => debugPrettyPrintXML(ie)
            case nodeSeq: Seq[Any] =>
              nodeSeq.foreach { a =>
                a match {
                  case ie: InfosetElement => debugPrettyPrintXML(ie)
                  case _ => debugPrintln(a)
                }
              }
            case _ => debugPrintln(res)
          }
        } catch {
          case e: ErrorsNotYetRecorded => {
            val diags = e.diags
            val newDiags = diags.flatMap { d =>
              d match {
                case rel: RelativePathPastRootError => Nil
                case _ => List(d)
              }
            }
            if (!newDiags.isEmpty) {
              val ex = new ErrorsNotYetRecorded(newDiags)
              throw new DebugException(
                "expression evaluation failed: %s".format(Misc.getSomeMessage(ex).get)
              )
            }
          }
          case s: scala.util.control.ControlThrowable => throw s
          //
          // If we eval(.) on a node that has no value, we get a RSDE thrown.
          //
          // Users (such as tests in daffodil's cli module) can set up a 'display eval (.)' and then
          // single steps until they start parsing an element which has no value.
          // That will throw this RSDE. If we recognize this situation, we
          // display the empty element.
          //
          case r: RuntimeSchemaDefinitionError if r.getCause() ne null =>
            r.getCause() match {
              case nd: InfosetNoDataExceptionBase => {
                //
                // Displays the empty element since it has no value.
                //
                debugPrettyPrintXML(nd.diElement)
                state.suppressDiagnosticAndSucceed(r)
              }
              case _ => throw r
            }
          case e: Throwable => {
            val ex = e // just so we can see it in the debugger.
            throw new DebugException(
              "expression evaluation failed: %s".format(Misc.getSomeMessage(ex).get)
            )
          }
        }
        DebugState.Pause
      }