RESSA
RESSA copied to clipboard
Feature Request: capture line and column number from parsing
Now that I'm getting into RESSA, I noticed an omission which could be useful which is to capture the line and column number during parsing. There are several use cases that would require this e.g.
Producing source maps from the parsed files, Accurate error messages referring back to the source file, etc
One way of doing this might be to have a 'metadata' field on each AST node which can store arbitrary data where the parser could populate the source line and column during parsing. Similarly the writer could populate an output line and column during writing. Both of these things could then be used to create a source map. The metadata is also generally useful for 'decorating' nodes with data that can be used in later traversals etc.
Thanks for the feature request. I absolutely understand why this is desired, currently I have avoided this because calculating the line/column from a byte offset is quite expensive. That being said I have tried to continue to make this something easy to add, currently the Item
from ress
contains a Location
which will provide the byte offset for the start and end. This could be used to calculate the line/column index as needed but would need some extra state in the parser to do so.
I can try and write up more about how this might be doable later this week.
Hi Robert, Yes please share your thoughts and then I?ll look to see if I can get something working. I discovered another bug today which was a PITA to isolate but looks quite simple. I suspect it?s the writer that?s at fault but I raised it on RESSA because I wasn?t sure. Hopefully the example I provided explains it. I wonder though whether it could be wider than ternary expressions though so I?ll do some more test cases. Thanks again,AndrewOn Mon, 23 Aug 2021 at 13:42, Robert Masen @.***> wrote: Thanks for the feature request. I absolutely understand why this is desired, currently I have avoided this because calculating the line/column from a byte offset is quite expensive. That being said I have tried to continue to make this something easy to add, currently the Item from ress contains a Location which will provide the byte offset for the start and end. This could be used to calculate the line/column index as needed but would need some extra state in the parser to do so. I can try and write up more about how this might be doable later this week.
?You are receiving this because you authored the thread.Reply to this email directly, view it on GitHub, or unsubscribe.Triage notifications on the go with GitHub Mobile for iOS or Android.
This feature was included with the v0.8.0 release