Add information about node's original location in the parsed string
Prior to this commit it was not possible to trace back the parsed node location in the original string. This information could be used to highlight the syntax of a math expression displayed in a rich editor (e.g. a spreadsheet or a calculator).
This commit is based on the PR #2796 that has been abandoned for 2 years. I rebased the task branch and fixed the issues reported in the original PR.
In the nutshell, each parsed node stores an array of sources (SourceMapping[]) that are set during parsing (see tokenSource and its usages for details). The node's constructor and clone method are adjusted to take an optional MetaOptions object containing the source mappings. In the future MetaOptions could be extended to store more information.
Benchmarks showed no change in evaluate. parse became slower, from 3.68µs to 5.17µs with the changes from this commit.
Closes #2795
@josdejong any chance you or someone else can look into this PR? Feedback is highly appreciated 🙏
Hi Sergey, thanks a lot for picking this up! I think I don't have enough time today to review this (large) PR, I hope to look into it coming Friday.
Does this also supersede #2615 ?
Does this also supersede #2615 ?
Ah, yes. I'll close that PR in favor of this one. Thanks for pointing this out.
@serso I just merged #3547 adding support for optional chaining. This causes a few merge conflicts with this PR. Please let me know if you need help resolving them.
@serso can you have a look into the merge conflicts? Please let me know if you need help.