-
Notifications
You must be signed in to change notification settings - Fork 66
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
Track the absolute position in the drivers of Parser #2861
base: master
Are you sure you want to change the base?
Conversation
38f5c2c
to
4a9e2e6
Compare
In the stream function drivers, the abs-position argument is at the end. We should put it as the first argument just because stream and the stream constructors do the same. Edit: Whatever is there should be fine. |
0719551
to
7bcca5b
Compare
3f1949a
to
57238e9
Compare
1b81447
to
5721b6a
Compare
Benchmark regressions need to be checked. |
@harendra-kumar referred to this PR here: #2895 so I thought I'd throw in a few cents. I don't completely understand this PR , but I would be hesitant about making position tracking a sort of hard coded thing. It looks like in this PR "position" is just the number of tokens, but I'm not sure that's a useful definition in a lot of cases. In some cases "line and column" is more useful than just an absolute position. But even that's sometimes not what you want. In a JSON document you might want a The following parser transformer (which I mentioned in the issue) seems to achieve position tracking anyway:
To achieve what I think this PR does using the above function, you'll just need to pattern match on the But this has the following benefits:
By own concepts of "position", for example That being said, I'm just starting to use this library, but it seems to me that position tracking can be done with just parser transforms instead of modifying the library to hard code the logic everywhere, but I may be missing something. |
Hi @clintonmead , thank you for the detailed comment. I can see one problem with the implementation of In the current implementation of parsers, the backtracking information is stored Extending your example, (I did not compile and check)
Although this accounts for backtracking, we only keep track of the We can however solve this by implementing a driver that accounts for the token
The diver for this parser would keep track of the token size and the On a side note: I'll need to check if I'm missing anything in |
A custom driver might not be required, if we can save the buffer in the parser
|
Let me verify if this covers everything and solves the issue and your use case |
We can evaluate both the approaches. About the implicit tracking approach in this PR:
About the proposed explicit tracking:
Is there any other potential third way like tracking the context in an underlying state monad? |
@clintonmead Assuming parser combinators like the above exist. For a CSV file, we may want to track the position by: Line Number + Part Index |
No description provided.