regexp-tree
regexp-tree copied to clipboard
Suggestion: source map in transformer
While source maps are not extremely useful for debugging on such a small data sets, they can be still handy for testing transformers and (re)using existing tools that can match transformed pieces of regexp with original ones.
Given that you already have API to generate transformed regexp, and you know original / final locations, it should be pretty easy to add source map support using https://www.npmjs.com/package/source-map.
Yep, sounds like a good idea 👍
I'll probably reach it at some point later, and of course will appreciate a PR in case.
@DmitrySoshnikov Started trying but noticed that currently AST lacks line/column locations, and my understanding is that regexps are not necessarily single-line... Would need to have such locations available in AST first if doing this in a non-hacky way.
@RReverser, ah, yes, it's tracked in the #49. In general there should be no issue with adding it (except it might be breaking change for existing transforms, but might be fine).
The Token, and AST node locations in the parsing handlers already have all needed information (for line, column, and offset). Currently we get only offsets, here (and in other similar places), but can get all.
The only ugly handling in the parser is this function, which handles named grouped reference. With the Unicode names have to parse manually, and track locations. Should be doable there as well, or we can drop support of Unicode names in named group references (like \k\u{0d36}
-- not sure if someone even use this on practice, see this note).
I finally added line/column support, in https://github.com/DmitrySoshnikov/regexp-tree/commit/97daef91aec7a61fdd7a5a356e566ac65c3a834c 😄
Great, thanks! Maybe we can merge all the breaking changes together into a new release?