Track the absolute position in the drivers of Parser#2861
Track the absolute position in the drivers of Parser#2861harendra-kumar merged 9 commits intomasterfrom
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
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 |
5721b6a to
18c6d1f
Compare
|
I am seeing the following perf changes. No allocation changes in Parser, but some CPU regressions: There are significant allocation as well as CPU regressions in ParserK: No significant changes in Array parsers. |
72e74df to
41077db
Compare
| src = Prelude.reverse src0 | ||
| goExtract SPEC (List buf1) (List src) pst1 | ||
| goExtract SPEC (List buf1) (List src) pst1 (i - n) | ||
| --XXX |
With this, we can use cpp macros easily to generate the drivers with position info. Move Array.parseBreak to ParserDrivers module Move the Generic Array.parseBreak to ParserDrivers module Move parseMany to ParserDrivers.hs module Move parseIterate to ParserDrivers module Move parseBreak from StreamK module to ParserDrivers
Use parsePos in tests Use parsePos in ParserK tests
41077db to
2772e36
Compare
No description provided.