stevedlawrence commented on a change in pull request #207: Added support for
enumerations and TypeValueCalc
URL: https://github.com/apache/incubator-daffodil/pull/207#discussion_r279782605
##########
File path:
daffodil-runtime1/src/main/scala/org/apache/daffodil/processors/parsers/ExpressionEvaluatingParsers.scala
##########
@@ -67,6 +83,82 @@ class IVCParser(expr: CompiledExpression[AnyRef], e:
ElementRuntimeData)
}
}
+/*
+ * Run a parser for an element that does not occur in the infoset
+ * Prior to running, a temporary element (of the type expected by the parser)
will be created in the infoset,
+ * After running, the infoset will be reverted to its original state, but any
other side effect of parsing will remain
+ *
+ * Additionally, the dataValue of the element the parser parsed will be
returned
+ */
+trait withDetachedParser {
+ def runDetachedParser(pstate: PState, distachedParser: Parser, erd:
ElementRuntimeData): Maybe[AnyRef] = {
+ /*
+ * The parse1 being called here is that of ElementCombinator1, which
expects to begin and end in the parent
+ * of whatever element it is parsing. parse1 will create the new element
and append it to the end of the
+ * children list of the parent.
+ *
+ * The parse() call we are in currently is in the middle of the above
process already.
+ * To use the distachedParser, we need to unwind then rewind the work that
ElementCombinator1 has already done
+ * (in addition to reverting the infoset changes that repTypeParser
made). the general flow is:
+ *
+ * 1) priorElement = pstate.infoset
+ * 2) pstate.infoset = pstate.infoset.parent
+ * 3) pstate.infoset.mark
+ * 4) distachedParser.parse1
+ * 5) pstate.infoset.restore
+ * 6) pstate.infoset = priorElement
+ *
+ * Note that we are only restoring the infoset. Any other side effects
the repTypeParser has on pstate
+ * (such as advancing the bit posistion) will remain.
+ *
+ * If repTypeParser has an error (either thrown or status), we percolate
it up to our caller.
+ */
+
+ Processor.initialize(distachedParser)
+
+ val priorElement = pstate.infoset
+ pstate.setParent(pstate.infoset.diParent)
+
+ val priorState = pstate.mark("TypeValueCalcParser.parse: About to parse
repTypeQuasiElement")
Review comment:
This mark name is too specific. I assume this was created before being split
into a more generic trait?
----------------------------------------------------------------
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