Repository: zalmane/copybook (language: python)

Issue:
Implied and explicit decimal not recognized
The parser doesn't detect **implied_decimal** for a PICTURE clause that uses the V symbol:

       01  WORK-BOOK.
         10  AMOUNT2       PIC -9(4)V99.

or **explicit_decimal**:

       01  WORK-BOOK.
         10  AMOUNT2       PIC -9(4).99.

Looking at Field class, I see that implied decimal is literally implied and not intended to be captured as an attribute. But I also noticed that Field.explicit_decimal is never set because of paren placement in this rule:

```
numeric_pic = Group(
    ...snip...
    )
    + Optional(
        (
            ("V"+FollowedBy("9")("implied_decimal"))
            | ("."+FollowedBy("9")("explicit_decimal"))
        )
    ...snip...
```

We can resolve this by moving the right-most parens:

```
numeric_pic = Group(
    ...snip...
    )
    + Optional(
        (
            ("V"+FollowedBy("9"))("implied_decimal")
            | ("."+FollowedBy("9"))("explicit_decimal")
        )
    ...snip...
```
Parser now accepts plus sign as an editing control symbol for signed …
…data items (issue #12)


Discussion / hints:

Fix patch:
diff --git a/copybook/parser.py b/copybook/parser.py
index 199432a..3b9cd64 100644
--- a/copybook/parser.py
+++ b/copybook/parser.py
@@ -34,8 +34,8 @@
     )
     + Optional(
         (
-            ("V"+FollowedBy("9")("implied_decimal"))
-            | ("."+FollowedBy("9")("explicit_decimal"))
+            ("V"+FollowedBy("9"))("implied_decimal")
+            | ("."+FollowedBy("9"))("explicit_decimal")
         )
         # bracket notation, e.g. 9(13)
         + (


Test patch:
diff --git a/tests/test_parse_string.py b/tests/test_parse_string.py
index dec7790..682c932 100644
--- a/tests/test_parse_string.py
+++ b/tests/test_parse_string.py
@@ -165,7 +165,7 @@ def test_plus_sign_control_symbol():
     result = copybook.parse_string(test_str).flatten()
     assert len(result)==2
     assert result[1].datatype=="decimal"
-    assert result[1].get_total_length()==7
+    assert result[1].get_total_length()==8
 
 def test_minus_sign_control_symbol():
     test_str = """
@@ -175,4 +175,15 @@ def test_minus_sign_control_symbol():
     result = copybook.parse_string(test_str).flatten()
     assert len(result)==2
     assert result[1].datatype=="decimal"
+    assert result[1].get_total_length()==8
+
+def test_explicit_decimal():
+    test_str = """
+       01  WORK-BOOK.
+         10  AMOUNT2       PIC 9(4).99.
+    """
+    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()==7