Skip to content

Commit 5949627

Browse files
committed
#451 The parser now supports COMP-9 (Cobrix extension).
1 parent 38a2733 commit 5949627

File tree

7 files changed

+848
-822
lines changed

7 files changed

+848
-822
lines changed

cobol-parser/src/main/scala/za/co/absa/cobrix/cobol/parser/antlr/ParserVisitor.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import java.nio.charset.Charset
2121
import org.antlr.v4.runtime.{ParserRuleContext, RuleContext}
2222
import za.co.absa.cobrix.cobol.parser.CopybookParser
2323
import za.co.absa.cobrix.cobol.parser.CopybookParser.CopybookAST
24-
import za.co.absa.cobrix.cobol.parser.ast.datatype.{AlphaNumeric, COMP1, COMP2, COMP3, COMP4, COMP5, CobolType, Decimal, Integral, Usage}
24+
import za.co.absa.cobrix.cobol.parser.ast.datatype.{AlphaNumeric, COMP1, COMP2, COMP3, COMP4, COMP5, COMP9, CobolType, Decimal, Integral, Usage}
2525
import za.co.absa.cobrix.cobol.parser.ast.{Group, Primitive}
2626
import za.co.absa.cobrix.cobol.parser.common.Constants
2727
import za.co.absa.cobrix.cobol.parser.decoders.DecoderSelector
@@ -124,6 +124,7 @@ class ParserVisitor(enc: Encoding,
124124
case "COMP-3" | "COMPUTATIONAL-3" | "PACKED-DECIMAL" => Some(COMP3())
125125
case "COMP-4" | "COMPUTATIONAL-4" => Some(COMP4())
126126
case "COMP-5" | "COMPUTATIONAL-5" => Some(COMP5())
127+
case "COMP-9" | "COMPUTATIONAL-9" => Some(COMP9())
127128
case "DISPLAY" => None
128129
case "BINARY" => Some(COMP4())
129130
case _ => throw new RuntimeException("Unknown Usage literal " + text)

cobol-parser/src/main/scala/za/co/absa/cobrix/cobol/parser/antlr/copybookLexer.g4

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,15 @@ COMP_2 : C O M P MINUSCHAR '2';
3838
COMP_3 : C O M P MINUSCHAR '3';
3939
COMP_4 : C O M P MINUSCHAR '4';
4040
COMP_5 : C O M P MINUSCHAR '5';
41+
COMP_9 : C O M P MINUSCHAR '9';
4142
COMPUTATIONAL : C O M P U T A T I O N A L;
4243
COMPUTATIONAL_0 : C O M P U T A T I O N A L MINUSCHAR '0';
4344
COMPUTATIONAL_1 : C O M P U T A T I O N A L MINUSCHAR '1';
4445
COMPUTATIONAL_2 : C O M P U T A T I O N A L MINUSCHAR '2';
4546
COMPUTATIONAL_3 : C O M P U T A T I O N A L MINUSCHAR '3';
4647
COMPUTATIONAL_4 : C O M P U T A T I O N A L MINUSCHAR '4';
4748
COMPUTATIONAL_5 : C O M P U T A T I O N A L MINUSCHAR '5';
49+
COMPUTATIONAL_9 : C O M P U T A T I O N A L MINUSCHAR '9';
4850
COPY : C O P Y;
4951
DEPENDING : D E P E N D I N G;
5052
DESCENDING: D E S C E N D I N G;

cobol-parser/src/main/scala/za/co/absa/cobrix/cobol/parser/antlr/copybookLexer.java

Lines changed: 708 additions & 694 deletions
Large diffs are not rendered by default.

cobol-parser/src/main/scala/za/co/absa/cobrix/cobol/parser/antlr/copybookParser.g4

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,8 @@ renames:
109109

110110
usageLiteral:
111111
(
112-
COMPUTATIONAL_0 | COMPUTATIONAL_1 | COMPUTATIONAL_2 | COMPUTATIONAL_3 | COMPUTATIONAL_4 | COMPUTATIONAL_5 | COMPUTATIONAL
113-
| COMP_0 | COMP_1 | COMP_2 | COMP_3 | COMP_4 | COMP_5 | COMP
112+
COMPUTATIONAL_0 | COMPUTATIONAL_1 | COMPUTATIONAL_2 | COMPUTATIONAL_3 | COMPUTATIONAL_4 | COMPUTATIONAL_5 | COMPUTATIONAL_9 | COMPUTATIONAL
113+
| COMP_0 | COMP_1 | COMP_2 | COMP_3 | COMP_4 | COMP_5 | COMP_9 | COMP
114114
| DISPLAY
115115
| BINARY
116116
| PACKED_DECIMAL
@@ -119,8 +119,8 @@ usageLiteral:
119119

120120
groupUsageLiteral:
121121
(
122-
COMPUTATIONAL_0 | COMPUTATIONAL_3 | COMPUTATIONAL_4 | COMPUTATIONAL_5 | COMPUTATIONAL
123-
| COMP_0 | COMP_3 | COMP_4 | COMP_5 | COMP
122+
COMPUTATIONAL_0 | COMPUTATIONAL_3 | COMPUTATIONAL_4 | COMPUTATIONAL_5 | COMPUTATIONAL_9 | COMPUTATIONAL
123+
| COMP_0 | COMP_3 | COMP_4 | COMP_5 | COMP_9 | COMP
124124
| DISPLAY
125125
| BINARY
126126
| PACKED_DECIMAL

cobol-parser/src/main/scala/za/co/absa/cobrix/cobol/parser/antlr/copybookParser.java

Lines changed: 125 additions & 116 deletions
Large diffs are not rendered by default.

cobol-parser/src/main/scala/za/co/absa/cobrix/cobol/parser/antlr/generate_classes.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#! /usr/bin/bash
1+
#!/bin/bash
22

33
# Copyright 2018 ABSA Group Limited
44
#

spark-cobol/src/test/scala/za/co/absa/cobrix/spark/cobol/source/regression/Test16BinaryLittleEndian.scala

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,15 @@ class Test16BinaryLittleEndian extends WordSpec with SparkTestBase with BinaryFi
3333
16, 0, 0, 0,
3434
32, 0,
3535
// Record 1
36-
0, 1, 0, 0,
36+
0, 0, 1, 0,
3737
0, 2
3838
)
3939

4040
"COMP-9" should {
4141
val copybook1 =
4242
""" 01 R.
43-
05 N1 PIC 9(8) COMP-5.
44-
05 N2 PIC 9(3) COMP-5.
43+
05 N1 PIC 9(8) COMP-9.
44+
05 N2 PIC 9(3) COMP-9.
4545
"""
4646

4747
"be interpreted as little-endian binary" when {
@@ -66,14 +66,14 @@ class Test16BinaryLittleEndian extends WordSpec with SparkTestBase with BinaryFi
6666
assertEqualsMultiline(actualSchema, expectedSchema)
6767
}
6868

69-
"data should match" ignore {
69+
"data should match" in {
7070
val expectedData =
7171
"""[ {
7272
| "N1" : 16,
7373
| "N2" : 32
7474
|}, {
75-
| "N1" : 32768,
76-
| "N2" : 65536
75+
| "N1" : 65536,
76+
| "N2" : 512
7777
|} ]""".stripMargin
7878

7979
assertEqualsMultiline(actualData, expectedData)

0 commit comments

Comments
 (0)