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

Add helper for converting token IDs to indexes #436

Merged
merged 2 commits into from
Jan 30, 2025
Merged

Conversation

emcfarlane
Copy link
Contributor

@emcfarlane emcfarlane commented Jan 28, 2025

Adds a helper method index to convert an ID into it's index representation for improved readability. This is a follow up to #429.

Adds a helper method index to convert an ID into it's index
representation for improved readability.
@emcfarlane emcfarlane requested a review from mcy January 28, 2025 15:55
Comment on lines 66 to 68
// Need to invert the bits, because synthetic tokens are
// stored as negative numbers.
return ^int(t)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't seem right. What will the index be used for? Treating the indexes of synthetic tokens as in the same domain as indexes of natural tokens feels quite error-prone. I would instead expect separate syntheticIndex and naturalIndex methods, to make sure the caller doesn't screw things up, like indexing into the token stream using the value returned from a synthetic token.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems like a good idea.

@emcfarlane emcfarlane merged commit 4a37d6c into main Jan 30, 2025
8 checks passed
@emcfarlane emcfarlane deleted the ed/tokenIndex branch January 30, 2025 21:56
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.

3 participants