Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix the BAI2 grammar from forked package #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

tom-robbins
Copy link
Collaborator

Here is the specification for the file format
Cash Management Balance Reporting Specifications Version 2.pdf

I make a few changes to this code:

  • add support for continuation records (88)
  • harden a few types

@@ -90,7 +90,7 @@
"detailFundsType": "",
"bankReferenceNumber": "AGN",
"customerReferenceNumber": "935892",
"detailText": "POINT OF SALE"
"detailText": "POINT OF SALE/"
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I make a few changes to the test cases, because I believe the grammar was implemented incorrectly.

The specification states that

Therefore, the end of a record ending in text cannot be delimited using these characters. Instead, the logical record continues until another record that is not a continuation (88) record begins
Screen Shot 2021-03-02 at 3 57 32 PM

senderIdentification = alnum +
receiverIdentification = alnum +
senderIdentification = alphaNumeric+
receiverIdentification = alphaNumeric+
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These alterations are hardening the definition, these values cannot include , or /

@@ -74,7 +74,7 @@ BTR3 {

amountOpt = optSign digit*
itemCount = digit*
fundsType = alnum?
fundsType = ("0".."2" | "S" | "V" | "D" | "Z") ?
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again, hardening the definition, there is a specific set of values for this [pg. 29]

@@ -102,8 +102,10 @@ BTR3 {
bankReferenceNumber = alphaNumeric*
customerReferenceNumber = alphaNumeric*
detailText (Text relaxed for CBA BAI2 format does not contain , / Optionally followed by /)
= (~ eor any) *
= & "/" // null text field
| text * // normal text field
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here, we need to do a lookahead for a / (in the file, this would look like ,/ because detailText is preceded by delim. In this case, the text is null, and trying to parse it as a text would cause the expression to be unreasonably complex

@@ -120,10 +122,17 @@ BTR3 {
hh = ("0".."1" digit) | ("2" "0" .. "3")
mm = "0".."5" digit

delim = ","
newLine = ("\r\n" | "\n" | "\r")
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should accept all kinds of newlines

delim =
| "," -- comma_delimiter
| "/" newLine "88," -- continuation_record_delimiter

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is big. I have added support for 88 - Continuation Record [pg. 20]. It is simplest to treat \n88, as a delimiter rather than a new record.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If a record is "split" between fields, it will look like

...field1,field2/
88,field3,field4...

which we want to parse as field1,field2,field3,field4

The slash replaces the comma that ordinarily delimits that field. The example below correctly illustrates the use of delimiters.

Screen Shot 2021-03-02 at 4 11 46 PM

text = (continuationWithinTextField | ~newLine any)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

However, a text field does not have a delimiter at the end of a logical record. we want to parse

...text
88,andmoretext

as textandmoretext

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant