Repository: zalmane/copybook (language: python)

Issue:
Accept leading decimal for signed data items
I have copybooks that use PICTURE clauses for a signed decimal with leading decimal point:

       01  WORK-BOOK.
         10  AMOUNT2       PIC +.9999999.

       01  WORK-BOOK.
         10  AMOUNT2       PIC +.9(7).

Parsing these copybooks raises an exception:

    pyparsing.exceptions.ParseException: Expected end of text, found '10'  (at char 32), (line:3, col:10)

I'll submit a pull request.


Discussion / hints:

Fix patch:
diff --git a/copybook/parser.py b/copybook/parser.py
index 3b9cd64..0ab12f3 100644
--- a/copybook/parser.py
+++ b/copybook/parser.py
@@ -20,6 +20,8 @@
     Optional(
         Suppress("S")("signed")
         | (one_of("+ -")+FollowedBy("9"))("signed")
+        | (one_of("+ -")+FollowedBy(".9"))("signed")
+        | (one_of("+ -")+FollowedBy("V9"))("signed")
     )
     + Optional(
         # bracket notation, e.g. 9(13)


Test patch:
diff --git a/tests/test_parse_string.py b/tests/test_parse_string.py
index 682c932..65e8122 100644
--- a/tests/test_parse_string.py
+++ b/tests/test_parse_string.py
@@ -66,6 +66,14 @@
         10  TAX-RATE        PIC S9(13)V9(2)                
                     SIGN LEADING SEPARATE.                                     
 """,
+"numeric pic signed with leading literal decimal":"""
+       01  WORK-BOOK.                                                             
+        10  TAX-RATE              PIC +.999.
+""",
+"numeric pic signed with leading implied decimal":"""
+       01  WORK-BOOK.                                                             
+        10  TAX-RATE              PIC +V999.
+""",
 "string pic with leading 0s":"""
        01  WORK-BOOK.                                                             
         10  TAX-RATE        PIC X(005).
@@ -187,3 +195,26 @@ def test_explicit_decimal():
     assert result[1].datatype=="decimal"
     assert result[1].explicit_decimal == True
     assert result[1].get_total_length()==7
+
+def test_signed_leading_literal_decimal():
+    test_str = """
+       01  WORK-BOOK.
+         10  AMOUNT2       PIC +.9(7).
+    """
+    result = copybook.parse_string(test_str).flatten()
+    assert len(result)==2
+    assert result[1].datatype=="decimal"
+    assert result[1].explicit_decimal == True
+    assert result[1].get_total_length()==9
+
+
+def test_signed_leading_implied_decimal():
+    test_str = """
+       01  WORK-BOOK.
+         10  AMOUNT2       PIC +V9(7).
+    """
+    result = copybook.parse_string(test_str).flatten()
+    assert len(result)==2
+    assert result[1].datatype=="decimal"
+    assert result[1].explicit_decimal == False
+    assert result[1].get_total_length()==8