Skip to content

Commit 989bf28

Browse files
committed
260 Unicode support with PIC N notation
- Add support for PIC N(num) notation, where field size is num * 2 - Adapted tests to include PIC N
1 parent d85a8f8 commit 989bf28

File tree

12 files changed

+1263
-1033
lines changed

12 files changed

+1263
-1033
lines changed

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ class ParserVisitor(enc: Encoding,
6464
s"((?:$char\\(\\d+\\)|$char)$question)"
6565
}
6666

67-
val lengthRegex: Regex = "([9XPZA])\\((\\d+)\\)|([9XPZA])".r
67+
val lengthRegex: Regex = "([9XNPZA])\\((\\d+)\\)|([9XNPZA])".r
6868
val numericSPicRegexScaled: Regex = ("(S?)"
6969
+ genericLengthRegex('9')
7070
+ genericLengthRegex('P', optional = true)
@@ -576,6 +576,9 @@ class ParserVisitor(enc: Encoding,
576576
else if (ctx.alphaA() != null) {
577577
visitAlphaA(ctx.alphaA())
578578
}
579+
else if (ctx.alphaN() != null) {
580+
visitAlphaN(ctx.alphaN())
581+
}
579582
else if (ctx.COMP_1() != null || ctx.COMP_2() != null) {
580583
PicExpr(
581584
Decimal(
@@ -608,6 +611,12 @@ class ParserVisitor(enc: Encoding,
608611
PicExpr(AlphaNumeric(s"$char($len)", len, None, Some(enc), Some(ctx.getText)))
609612
}
610613

614+
override def visitAlphaN(ctx: copybookParser.AlphaNContext): PicExpr = {
615+
val text = ctx.getText
616+
val (char, len) = length(text)
617+
PicExpr(AlphaNumeric(s"$char($len)", len * 2, None, Some(enc), Some(ctx.getText)))
618+
}
619+
611620
override def visitAlphaA(ctx: copybookParser.AlphaAContext): PicExpr = {
612621
val text = ctx.getText
613622
val (char, len) = length(text)

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ NINES: '9'+;
118118
A_S: A+;
119119
P_S: P+ '9'*;
120120
X_S: X+;
121+
N_S: N+;
121122
S_S: S '9'+ V? P* '9'* | S '9'* V? P* '9'+;
122123
Z_S: Z+ '9'* P* | Z+ '9'* V P* '9'*;
123124
V_S: V+ '9'+;
@@ -174,6 +175,14 @@ LENGTH_TYPE_X_1:
174175
| X+
175176
;
176177

178+
LENGTH_TYPE_N:
179+
LENGTH_TYPE_N_1+
180+
;
181+
182+
LENGTH_TYPE_N_1:
183+
(N LPARENCHAR POSITIVELITERAL RPARENCHAR)
184+
| N+
185+
;
177186

178187
LENGTH_TYPE_Z:
179188
LENGTH_TYPE_Z_1+;
@@ -190,6 +199,8 @@ STRINGLITERAL: QUOTEDLITERAL | HEXNUMBER;
190199
fragment HEXNUMBER :
191200
X '"' [0-9A-F]+ '"'
192201
| X '\'' [0-9A-F]+ '\''
202+
| N '"' [0-9A-F]+ '"'
203+
| N '\'' [0-9A-F]+ '\''
193204
;
194205

195206
fragment QUOTEDLITERAL :

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

Lines changed: 671 additions & 644 deletions
Large diffs are not rendered by default.

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ booleanLiteral
4848
;
4949

5050
identifier:
51-
IDENTIFIER | THRU_OR_THROUGH | A_S | P_S | P_NS | X_S | S_S | S_NS | Z_S | Z_NS | V_S | V_NS
51+
IDENTIFIER | THRU_OR_THROUGH | A_S | P_S | P_NS | X_S | | N_S | S_S | S_NS | Z_S | Z_NS | V_S | V_NS
5252
| SINGLE_QUOTED_IDENTIFIER // is this valid?
5353
;
5454

@@ -178,6 +178,11 @@ alphaX:
178178
| LENGTH_TYPE_X
179179
;
180180

181+
alphaN:
182+
N_S
183+
| LENGTH_TYPE_N
184+
;
185+
181186
alphaA:
182187
A_S
183188
| LENGTH_TYPE_A
@@ -192,6 +197,7 @@ pic:
192197
(
193198
alphaX
194199
| alphaA
200+
| alphaN
195201
| (
196202
signPrecision9 usage?
197203
| usage? signPrecision9

0 commit comments

Comments
 (0)