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

Tracking segment groups #21

Open
gnatowski opened this issue Oct 28, 2016 · 1 comment
Open

Tracking segment groups #21

gnatowski opened this issue Oct 28, 2016 · 1 comment
Labels

Comments

@gnatowski
Copy link

Could it be possible to track segment group on closing segment in parser?
When we convert components to properties of our model, we need to know where we are in structure. For example in PRICAT/D02A we have DTM in groups SG1 = RFF-DTM, SG3 = RFF-DTM, SG5 = TAX-MOA-DTM, SG6 = CUX-DTM, and so on.
In our old converter we had definitions for it, knowing which property in our model we have to set, e.g.:
sg33.dtm.64=dateFrom,
sg33.dtm.63=dateTo
or for ORDRSP:
root.dtm.64=default.DateFrom
sg01.dtm.171=referenceDate
sg26.dtm.64=item.dateFrom

Regards, Gabriel

@tdecaluwe
Copy link
Owner

Hello Gabriel, I've been thinking about this as well.

Currently there is one relatively easy way to do this. With the Tracker class you can validate a message against a certain segment table (for example to make sure you're receiving an INVOIC message). Since this class needs to track the current position to be able to do this you could also use this for your use case. However, currently there is no simple API for this.

The Tracker class only has one internal variable called stack which is actually a path to the current segment. Each element in the stack contains a reference to a segment table, a position and a repetition count. This means something like this should work:

var tracker = ... // get the tracker associated with your parser
var myDTMSegment = ... // to be retrieved in the segment table
var pointer = tracker.stack[tracker.stack.length - 1];
var segment = pointer.array[pointer.position];
if (segment === myDTMSegment) {
  ...
}

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

No branches or pull requests

2 participants