Skip to content

Commit 298e2f4

Browse files
committed
#324 Make parseSimple() signature backwards compatible.
1 parent 6d5a4cc commit 298e2f4

File tree

3 files changed

+38
-21
lines changed

3 files changed

+38
-21
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ class Copybook(val ast: CopybookAST) extends Serializable {
268268
new Copybook(CopybookParser.calculateBinaryProperties(newRoot))
269269
}
270270

271-
def dropFillers(dropValueFillers: Boolean, dropGroupFillers: Boolean): Copybook = {
271+
def dropFillers(dropGroupFillers: Boolean, dropValueFillers: Boolean): Copybook = {
272272
def dropFillersAst(group: Group): Option[Group] = {
273273
if (dropGroupFillers && group.isFiller) {
274274
None

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

Lines changed: 33 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -54,34 +54,51 @@ object CopybookParser {
5454

5555
case class RecordBoundary(name: String, begin: Int, end: Int)
5656

57+
5758
/**
5859
* Tokenizes a Cobol Copybook contents and returns the AST.
5960
*
6061
* This method accepts arguments that affect only structure of the output AST.
6162
*
62-
* FILLER fields renaming/removal scenarios can be seen in `ParseCopybookFeaturesSpec.scala`
63+
* @param copyBookContents A string containing all lines of a copybook
64+
* @param dropGroupFillers Drop GROUPs marked as fillers from the output AST
65+
* (the name of this parameter is retained for compatibility, fields won't be actually removed from
66+
* the AST unless dropFillersFromAst is set to true).
67+
*
68+
* When dropGroupFillers is set to true, FILLER fields will retain their names,
69+
* and 'isFiller() = true' for FILLER GROUPs.
70+
*
71+
* When dropGroupFillers is set to false, FILLER fields will be renamed to 'FILLER_1, FILLER_2, ...'
72+
* to retain uniqueness of names in the output schema.
73+
*
74+
* @param dropValueFillers Drop primitive fields marked as fillers from the output AST
75+
* (the name of this parameter is retained for compatibility, fields won't be actually removed from
76+
* the AST unless dropFillersFromAst is set to true).
77+
*
78+
* When dropValueFillers is set to true, FILLER fields will retain their names,
79+
* and 'isFiller() = true' for FILLER primitive fields.
80+
*
81+
* When dropValueFillers is set to false, FILLER fields will be renamed to 'FILLER_P1, FILLER_P2, ...'
82+
* to retain uniqueness of names in the output schema.
6383
*
64-
* @param copyBookContents A string containing all lines of a copybook
65-
* @param giveUniqueNameToGroupFillers If true each FILLER GROUP field will have a unique name that helps retaining it in
66-
* target schemas where column names must be unique. FILLERs become FILLER_1, FILLER_2, etc.
67-
* @param giveUniqueNameToValueFillers If true each FILLER value field will have a unique name that helps retaining it in
68-
* target schemas where column names must be unique. FILLERs become FILLER_P1, FILLER_P2, etc.
69-
* @param dropFillersFromAst If true FILLER fields that are not renamed will be removed from the AST.
70-
* @param commentPolicy Specifies a policy for comments truncation inside a copybook
84+
* @param commentPolicy Specifies a policy for comments truncation inside a copybook
85+
* @param dropFillersFromAst If true, fillers are going to be dropped from AST according to dropGroupFillers and dropValueFillers.
86+
* If false, fillers will remain in the AST, but still can be recognizable by 'isFiller()' method.
7187
* @return Seq[Group] where a group is a record inside the copybook
7288
*/
7389
def parseSimple(copyBookContents: String,
74-
giveUniqueNameToGroupFillers: Boolean = true,
75-
giveUniqueNameToValueFillers: Boolean = false,
76-
dropFillersFromAst: Boolean = false,
77-
commentPolicy: CommentPolicy = CommentPolicy()): Copybook = {
90+
dropGroupFillers: Boolean = false,
91+
dropValueFillers: Boolean = true,
92+
commentPolicy: CommentPolicy = CommentPolicy(),
93+
dropFillersFromAst: Boolean = false
94+
): Copybook = {
7895
val copybook = parse(copyBookContents = copyBookContents,
79-
dropGroupFillers = !giveUniqueNameToGroupFillers,
80-
dropValueFillers = !giveUniqueNameToValueFillers,
96+
dropGroupFillers = dropGroupFillers,
97+
dropValueFillers = dropValueFillers,
8198
commentPolicy = commentPolicy)
8299

83-
if (dropFillersFromAst && (!giveUniqueNameToGroupFillers || !giveUniqueNameToValueFillers)) {
84-
copybook.dropFillers(!giveUniqueNameToValueFillers, !giveUniqueNameToGroupFillers)
100+
if (dropFillersFromAst && (dropGroupFillers || dropValueFillers)) {
101+
copybook.dropFillers(dropGroupFillers, dropValueFillers)
85102
} else {
86103
copybook
87104
}

cobol-parser/src/test/scala/za/co/absa/cobrix/cobol/parser/copybooks/ParseCopybookFeaturesSpec.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ class ParseCopybookFeaturesSpec extends FunSuite with SimpleComparisonBase {
116116
}
117117

118118
test("Test parseSimple() not dropping fillers") {
119-
val copybook = CopybookParser.parseSimple(copybookFillers, giveUniqueNameToValueFillers = true, giveUniqueNameToGroupFillers = true)
119+
val copybook = CopybookParser.parseSimple(copybookFillers, dropGroupFillers = false, dropValueFillers = false, dropFillersFromAst = false)
120120
val layout = copybook.generateRecordLayoutPositions()
121121

122122
val expectedLayout =
@@ -148,7 +148,7 @@ class ParseCopybookFeaturesSpec extends FunSuite with SimpleComparisonBase {
148148
assertEqualsMultiline(layout, expectedLayout)
149149
}
150150
test("Test parseSimple() drop value fillers") {
151-
val copybook = CopybookParser.parseSimple(copybookFillers, giveUniqueNameToValueFillers = false, giveUniqueNameToGroupFillers = true, dropFillersFromAst = true)
151+
val copybook = CopybookParser.parseSimple(copybookFillers, dropGroupFillers = false, dropValueFillers = true, dropFillersFromAst = true)
152152
val layout = copybook.generateRecordLayoutPositions()
153153

154154
val expectedLayout =
@@ -173,7 +173,7 @@ class ParseCopybookFeaturesSpec extends FunSuite with SimpleComparisonBase {
173173
}
174174

175175
test("Test parseSimple() drop group fillers") {
176-
val copybook = CopybookParser.parseSimple(copybookFillers, giveUniqueNameToValueFillers = true, giveUniqueNameToGroupFillers = false, dropFillersFromAst = true)
176+
val copybook = CopybookParser.parseSimple(copybookFillers, dropGroupFillers = true, dropValueFillers = false, dropFillersFromAst = true)
177177
val layout = copybook.generateRecordLayoutPositions()
178178

179179
val expectedLayout =
@@ -199,7 +199,7 @@ class ParseCopybookFeaturesSpec extends FunSuite with SimpleComparisonBase {
199199
}
200200

201201
test("Test parseSimple() drop all fillers") {
202-
val copybook = CopybookParser.parseSimple(copybookFillers, giveUniqueNameToValueFillers = false, giveUniqueNameToGroupFillers = false, dropFillersFromAst = true)
202+
val copybook = CopybookParser.parseSimple(copybookFillers, dropGroupFillers = true, dropValueFillers = true, dropFillersFromAst = true)
203203
val layout = copybook.generateRecordLayoutPositions()
204204

205205
val expectedLayout =

0 commit comments

Comments
 (0)