Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/node source location #2615

Draft
wants to merge 2 commits into
base: develop
Choose a base branch
from

Conversation

mattvague
Copy link
Sponsor 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
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.

None yet

2 participants