mbeckerle commented on code in PR #900:
URL: https://github.com/apache/daffodil/pull/900#discussion_r1059402696


##########
daffodil-core/src/main/scala/org/apache/daffodil/grammar/primitives/PrimitivesTextNumber.scala:
##########
@@ -46,8 +46,226 @@ case class ConvertTextCombinator(e: ElementBase, value: 
Gram, converter: Gram)
   override lazy val unparser = new 
ConvertTextCombinatorUnparser(e.termRuntimeData, value.unparser, 
converter.unparser)
 }
 
-case class ConvertTextNumberPrim(e: ElementBase)
-  extends Terminal(e, true) {
+// This is a separate object for unit testing purposes.
+private[primitives]
+object TextNumberPatternUtils {
+
+  /**
+   * A regex which matches textNumberPatterns that legally use the V
+   * (implied decimal point) character.
+   */
+   private[primitives] lazy val vregexStandard = {
+    //  DFDL v1.0 Spec says
+    //  It is a Schema Definition Error if any symbols other than "0", "1" 
through "9" or #
+    //  are used in the vpinteger region of the pattern.
+    //
+    // The prefix and suffix chars can surround the vpinteger region, and 
there can be
+    // a positive and a negative pattern.
+    //
+    // The prefix and suffix cannot be digits, # or P or V. No quoted chars in 
prefix either.
+    //
+    val prefix = """([^0-9#PV']?)"""
+    val suffix = prefix // same syntax as prefix
+    val vpinteger = """(#*[0-9]+)V([0-9]+)"""
+    val subpattern = s"""${prefix}${vpinteger}${suffix}"""
+     // don't forget the ^ and $ (start of data, end of data) because we want
+     // the match to consume all the characters, starting at the beginning.
+    val vPattern = s"""^${subpattern}(?:;${subpattern})?$$"""
+    val re = vPattern.r
+    re
+  }
+
+  def textDecimalVirtualPointForStandard(
+    e: ImplementsThrowsOrSavesSDE,
+    originalPattern: String,
+    patternStripped: String): Int = {
+    val r = TextNumberPatternUtils.vregexStandard
+    r.findFirstMatchIn(patternStripped) match {
+      case Some(r(_, _, afterV, _, _, _, _, _)) => afterV.length
+      case None =>
+        e.SDE(
+          s"""The dfdl:textNumberPattern '%s' contains 'V' (virtual decimal 
point).
+             | Other than the sign indicators, it can contain only
+             | '#', then digits 0-9 then 'V' then digits 0-9.
+             | The positive part of the dfdl:textNumberPattern is 
mandatory.""".stripMargin('|'),

Review Comment:
   That is a good style suggestion for regexs with capture groups generally. 
   
   The other groups are there in case we need/want to create finer grain 
diagnostics that point at the smaller parts of the overall pattern, but really 
I needed them to test that it was working at all. Regexs are notoriously 
difficult. 



-- 
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.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to