Skip to content

Commit 98f2633

Browse files
authored
WI #1917 Improve error messages on unexpected dots (#2025)
1 parent aea6c3c commit 98f2633

File tree

3 files changed

+68
-4
lines changed

3 files changed

+68
-4
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
IDENTIFICATION DIVISION.
2+
PROGRAM-ID. Pgm.
3+
ENVIRONMENT DIVISION.
4+
CONFIGURATION SECTION.
5+
SPECIAL-NAMES. DECIMAL-POINT IS COMMA.
6+
DATA DIVISION.
7+
WORKING-STORAGE SECTION.
8+
*OK
9+
01 A pic X.
10+
*KO Invalid Picture
11+
01 B pic X..
12+
*KO Unexpected '.'
13+
01 C pic X. .
14+
*KO not reported because of previous error
15+
01 var1..
16+
05 var2 pic XX.
17+
*KO Invalid Picture
18+
05 var3 pic X.05 var4 pic X.
19+
PROCEDURE DIVISION..
20+
move A to B..
21+
move A to B...move A to B.
22+
goback
23+
.
24+
END PROGRAM Pgm.
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
IDENTIFICATION DIVISION.
2+
PROGRAM-ID. Pgm.
3+
ENVIRONMENT DIVISION.
4+
CONFIGURATION SECTION.
5+
SPECIAL-NAMES. DECIMAL-POINT IS COMMA.
6+
DATA DIVISION.
7+
WORKING-STORAGE SECTION.
8+
*OK
9+
01 A pic X.
10+
*KO Invalid Picture
11+
Line 11[17,18] <27, Error, Syntax> - Syntax error : Combination of symbols 'X.' was not recognized as a valid PICTURE string
12+
01 B pic X..
13+
*KO Unexpected '.'
14+
Line 13[20,20] <27, Error, Syntax> - Syntax error : extraneous input '.' expecting {ProgramIdentification, ProgramEnd, ClassIdentification, ClassEnd, FactoryEnd, ObjectIdentification, ObjectEnd, MethodEnd, ProcedureDivisionHeader, WorkingStorageSectionHeader, LocalStorageSectionHeader, LinkageSectionHeader, FileDescriptionEntry, DataDescriptionEntry, DataRedefinesEntry, DataRenamesEntry, DataConditionEntry, ExecStatement, FunctionDeclarationEnd, GlobalStorageSectionHeader}
15+
01 C pic X. .
16+
*KO not reported because of previous error
17+
Line 15[15,15] <12, Warning, Tokens> - A blank was missing before character "." in column 16. A blank was assumed.
18+
01 var1..
19+
05 var2 pic XX.
20+
*KO Invalid Picture
21+
Line 18[23,26] <27, Error, Syntax> - Syntax error : Invalid PICTURE string 'X.05': character '5' at position '4' was not expected
22+
Line 18[28,31] <27, Error, Syntax> - Syntax error : extraneous input 'var4' expecting {separator, statement starting keyword, keyword}
23+
05 var3 pic X.05 var4 pic X.
24+
Line 19[26,26] <12, Warning, Tokens> - A blank was missing before character "." in column 27. A blank was assumed.
25+
PROCEDURE DIVISION..
26+
Line 20[23,23] <12, Warning, Tokens> - A blank was missing before character "." in column 24. A blank was assumed.
27+
move A to B..
28+
Line 21[23,23] <12, Warning, Tokens> - A blank was missing before character "." in column 24. A blank was assumed.
29+
Line 21[24,24] <12, Warning, Tokens> - A blank was missing before character "." in column 25. A blank was assumed.
30+
Line 21[25,25] <12, Warning, Tokens> - A blank was missing before character "m" in column 26. A blank was assumed.
31+
move A to B...move A to B.
32+
goback
33+
.
34+
END PROGRAM Pgm.

TypeCobol/Compiler/Types/PictureValidator.cs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public partial class PictureValidator
2121
private const string PARENTHESES_DO_NOT_MATCH = "Missing '(' or ')' in PICTURE string";
2222
private const string SYMBOL_COUNT_CANNOT_BE_ZERO = "Symbol count cannot be zero";
2323
private const string MULTIPLE_CURRENCIES_IN_SAME_PICTURE = "Cannot mix currency symbols in a PICTURE string: '{0}' symbol was not expected";
24-
private const string INVALID_DATA_CATEGORY = "Invalid data category for PICTURE string '{0}'";
24+
private const string INVALID_PICTURE_STRING = "Combination of symbols '{0}' was not recognized as a valid PICTURE string";
2525
private const string INVALID_SYMBOL_POSITION = "Invalid position in PICTURE string of the symbol: {0}";
2626
private const string SYMBOL_S_MUST_BE_THE_FIRST = "S must be at the beginning of a PICTURE string";
2727
private const string MULTIPLE_V = "V must appears only once in a PICTURE string";
@@ -60,6 +60,7 @@ public PictureValidator(string picture, bool separateSign = false, bool decimalP
6060
}
6161
_currencyDescriptor = null;
6262

63+
OriginalPicture = picture;
6364
_decimalPointIsComma = decimalPointIsComma;
6465
if (_decimalPointIsComma)
6566
{
@@ -92,7 +93,12 @@ public PictureValidator(string picture, bool separateSign = false, bool decimalP
9293
}
9394

9495
/// <summary>
95-
/// The Picture string, with comma and dot swapped if DECIMAL POINT IS COMMA is active.
96+
/// The unaltered Picture string
97+
/// </summary>
98+
public string OriginalPicture { get; }
99+
100+
/// <summary>
101+
/// The Picture string to validate, with comma and dot swapped if DECIMAL POINT IS COMMA is active.
96102
/// </summary>
97103
public string Picture { get; }
98104

@@ -134,7 +140,7 @@ public Result Validate(out List<string> validationMessages)
134140
var category = DeterminePictureCategory(sequence, symbolCounts);
135141
if (category == PictureCategory.Invalid)
136142
{
137-
validationMessages.Add(string.Format(INVALID_DATA_CATEGORY, Picture));
143+
validationMessages.Add(string.Format(INVALID_PICTURE_STRING, OriginalPicture));
138144
}
139145
else
140146
{
@@ -266,7 +272,7 @@ private List<Tuple<string, int>> PictureStringSplitter(List<string> validationMe
266272

267273
if (!match)
268274
{
269-
validationMessages.Add(string.Format(UNKNOWN_SYMBOL, Picture, Picture[l], l + 1));
275+
validationMessages.Add(string.Format(UNKNOWN_SYMBOL, OriginalPicture, Picture[l], l + 1));
270276
return null;
271277
}
272278
}

0 commit comments

Comments
 (0)