Skip to content

Feature/node source location#2615

Closed
mattvague wants to merge 2 commits intojosdejong:developfrom
goodproblems:feature/node-source-loc
Closed

Feature/node source location#2615
mattvague wants to merge 2 commits intojosdejong:developfrom
goodproblems:feature/node-source-loc

Conversation

@mattvague
Copy link
Contributor

@mattvague mattvague commented Jul 2, 2022

I went ahead and implemented support for MathJS on ASTExplorer (see PR here) but was unable to implement the source code highlighting feature since MathJS doesn't store positional information on nodes yet.

Took a crack at trying to implement that here, however wasn't able to figure out how to calculate the correct start/end positions, @josdejong could you possibly give me some pointers on how to do that?

@josdejong
Copy link
Owner

Thanks Matt, that looks good already.

About the correct start and end positions: I see you're indeed already using state.index and state.token, that's indeed the positioning information that the parser has right now. You will need to keep track of the location of the index at the moment the parser starts parsing a specific type of node. I'm not sure what will be the handiest approach in that regard. Maybe you can create a variable indexAtStart = ... at the beginning of all parse* functions. Or maybe it works better to create a new state variable holding a stack with start indexes of all the nested operations (a bit similar to keeping track of the nestingLevel).

@mattvague mattvague changed the title Feature/node source loc Feature/node source locatin Oct 4, 2022
@mattvague mattvague changed the title Feature/node source locatin Feature/node source location Oct 4, 2022
@josdejong
Copy link
Owner

Closing this PR now in favor of #3557

@josdejong josdejong closed this Oct 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants