Skip to content

Commit

Permalink
#669 Allow 'V' to be at the end of scaled PICs.
Browse files Browse the repository at this point in the history
For example, '9(7)PPPV' is the same as '9(7)PPP'.
  • Loading branch information
yruslan committed Apr 17, 2024
1 parent 7365fc1 commit 48fc55e
Show file tree
Hide file tree
Showing 9 changed files with 1,007 additions and 946 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,11 @@ class ParserVisitor(enc: Encoding,
+ genericLengthRegex('9')
+ genericLengthRegex('P', optional = true)
).r
val numericSPicRegexScaledWithV: Regex = ("(S?)"
+ genericLengthRegex('9')
+ genericLengthRegex('P', optional = true)
+ "V"
).r
val numericSPicRegexExplicitDot: Regex = ("(S?)"
+ genericLengthRegex('9', optional = true)
+ "."
Expand Down Expand Up @@ -680,13 +685,13 @@ class ParserVisitor(enc: Encoding,
override def visitPrecision9Ss(ctx: copybookParser.Precision9SsContext): PicExpr = {
ctx.getText match {
case numericSPicRegexDecimalScaled(s, nine1, scale, nine2) => PicExpr(
fromNumericSPicRegexDecimalScaled(s, nine1, scale, nine2)
fromNumericSPicRegexDecimalScaled(s, nine1, scale, nine2).copy(originalPic = Some(ctx.getText))
)
case numericSPicRegexScaled(z, nine, scale) => PicExpr(
fromNumericSPicRegexScaled(z, nine, scale)
fromNumericSPicRegexScaled(z, nine, scale).copy(originalPic = Some(ctx.getText))
)
case numericSPicRegexDecimalScaledLead(s, scale, nine) => PicExpr(
fromNumericSPicRegexDecimalScaledLead(s, scale, nine)
fromNumericSPicRegexDecimalScaledLead(s, scale, nine).copy(originalPic = Some(ctx.getText))
)
case _ => throw new RuntimeException("Error reading PIC " + ctx.getText)
}
Expand All @@ -695,14 +700,14 @@ class ParserVisitor(enc: Encoding,
override def visitPrecision9Ps(ctx: copybookParser.Precision9PsContext): PicExpr = {
val numericSPicRegexDecimalScaledLead(s, scale, nine) = ctx.getText
PicExpr(
fromNumericSPicRegexDecimalScaledLead(s, scale, nine)
fromNumericSPicRegexDecimalScaledLead(s, scale, nine).copy(originalPic = Some(ctx.getText))
)
}

override def visitPrecision9Vs(ctx: copybookParser.Precision9VsContext): PicExpr = {
ctx.getText match {
case numericSPicRegexDecimalScaled(s, nine1, scale, nine2) => PicExpr(
fromNumericSPicRegexDecimalScaled(s, nine1, scale, nine2)
fromNumericSPicRegexDecimalScaled(s, nine1, scale, nine2).copy(originalPic = Some(ctx.getText))
)
case _ => throw new RuntimeException("Error reading PIC " + ctx.getText)
}
Expand Down Expand Up @@ -734,6 +739,13 @@ class ParserVisitor(enc: Encoding,
)
}

override def visitPrecision9DecimalScaledWithV(ctx: copybookParser.Precision9DecimalScaledWithVContext): PicExpr = {
val numericSPicRegexScaledWithV(s, nine1, scale) = ctx.getText
PicExpr(
fromNumericSPicRegexScaled(s, nine1, scale).copy(originalPic = Some(ctx.getText))
)
}

override def visitPrecision9Scaled(ctx: copybookParser.Precision9ScaledContext): PicExpr = {
val numericSPicRegexScaled(s, text, scale) = ctx.getText
PicExpr(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ A_S: A+;
P_S: P+ '9'*;
X_S: X+;
N_S: N+;
S_S: S '9'+ V? P* '9'* | S '9'* V? P* '9'+;
S_S: S '9'+ V? P* '9'* | S '9'* V? P* '9'*;
Z_S: Z+ '9'* P* | Z+ '9'* V P* '9'*;
V_S: V+ '9'+;

Expand All @@ -136,6 +136,7 @@ V_NS: V+ '9'*;
// numbers
PRECISION_9_EXPLICIT_DOT: S? LENGTH_TYPE_9? (DOT | COMMACHAR) LENGTH_TYPE_9;
PRECISION_9_DECIMAL_SCALED: S? LENGTH_TYPE_9? V ((LENGTH_TYPE_P LENGTH_TYPE_9)? | LENGTH_TYPE_9?);
PRECISION_9_DECIMAL_WITH_V: S? LENGTH_TYPE_9 LENGTH_TYPE_P? V;
PRECISION_9_SCALED: S? LENGTH_TYPE_9 LENGTH_TYPE_P?;
PRECISION_9_SCALED_LEAD: S? LENGTH_TYPE_P LENGTH_TYPE_9;
PRECISION_Z_EXPLICIT_DOT: LENGTH_TYPE_Z LENGTH_TYPE_9? (DOT | COMMACHAR) ((LENGTH_TYPE_9 LENGTH_TYPE_Z?) | LENGTH_TYPE_Z);
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ precision9:
| V_S #precision9Vs
| PRECISION_9_EXPLICIT_DOT #precision9ExplicitDot
| PRECISION_9_DECIMAL_SCALED #precision9DecimalScaled
| PRECISION_9_DECIMAL_WITH_V #precision9DecimalScaledWithV
| PRECISION_9_SCALED #precision9Scaled
| PRECISION_9_SCALED_LEAD #precision9ScaledLead
| PRECISION_Z_EXPLICIT_DOT #precisionZExplicitDot
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,13 @@ public class copybookParserBaseVisitor<T> extends AbstractParseTreeVisitor<T> im
* {@link #visitChildren} on {@code ctx}.</p>
*/
@Override public T visitPrecision9DecimalScaled(copybookParser.Precision9DecimalScaledContext ctx) { return visitChildren(ctx); }
/**
* {@inheritDoc}
*
* <p>The default implementation returns the result of calling
* {@link #visitChildren} on {@code ctx}.</p>
*/
@Override public T visitPrecision9DecimalScaledWithV(copybookParser.Precision9DecimalScaledWithVContext ctx) { return visitChildren(ctx); }
/**
* {@inheritDoc}
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public interface copybookParserVisitor<T> extends ParseTreeVisitor<T> {
T visitThru(copybookParser.ThruContext ctx);
/**
* Visit a parse tree produced by the {@code values}
* labeled alternative in {@link copybookParser#plusMinusplusMinusprecision9precision9precision9precision9precision9precision9precision9precision9precision9precision9precision9precision9signPrecision9signPrecision9}.
* labeled alternative in {@link copybookParser#plusMinusplusMinusprecision9precision9precision9precision9precision9precision9precision9precision9precision9precision9precision9precision9precision9signPrecision9signPrecision9}.
* @param ctx the parse tree
* @return the visitor result
*/
Expand Down Expand Up @@ -246,6 +246,13 @@ public interface copybookParserVisitor<T> extends ParseTreeVisitor<T> {
* @return the visitor result
*/
T visitPrecision9DecimalScaled(copybookParser.Precision9DecimalScaledContext ctx);
/**
* Visit a parse tree produced by the {@code precision9DecimalScaledWithV}
* labeled alternative in {@link copybookParser#precision9}.
* @param ctx the parse tree
* @return the visitor result
*/
T visitPrecision9DecimalScaledWithV(copybookParser.Precision9DecimalScaledWithVContext ctx);
/**
* Visit a parse tree produced by the {@code precision9Scaled}
* labeled alternative in {@link copybookParser#precision9}.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,11 @@ class DataSizeSpec extends AnyFunSuite {
assert(decimalLength("ZZZ99(5)") == (9, 0, 0))
assert(decimalLength("ZZZ999") == (6, 0, 0))
assert(decimalLength("ZZZ999PPP") == (6, 0, 3))
assert(decimalLength("9(7)PPP") == (7, 0, 3))
assert(decimalLength("9(7)VPPP999") == (7, 3, -3))
assert(decimalLength("9(7)PPPV") == (7, 0, 3))
assert(decimalLength("S9(7)PPP") == (7, 0, 3))
assert(decimalLength("S9(7)PPPV") == (7, 0, 3))
assert(decimalLength("ZZZ999V99") == (6, 2, 0))
assert(decimalLength("ZZZ999VPP99") == (6, 2, -2))
assert(decimalLength("ZZZ999.99") == (6, 2, 0))
Expand Down
2 changes: 1 addition & 1 deletion data/test24_copybook.cob
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@
10 COMMON-UPI5DISP PIC S9(5)PPP.

10 COMMON-UPC1BIN PIC SPPP9 COMP.
10 COMMON-UPI1BIN PIC S9PPP COMP.
10 COMMON-UPI1BIN PIC S9PPPV COMP.
10 COMMON-UPC3BIN PIC SPPP9(3) COMP.
10 COMMON-UPI3BIN PIC S9(3)PPP COMP.
10 COMMON-UPC5BIN PIC SPPP9(5) COMP.
Expand Down

0 comments on commit 48fc55e

Please sign in to comment.