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

Ensure range returns valid indices #458

Closed
wants to merge 1 commit into from

Conversation

davidanthoff
Copy link
Contributor

This (maybe) kind of fixes #457. It at least ensures that range always is a valid range that can be used to index into the source string, i.e. it moves the logic that fixes the indices returned by last_byte from Base.view into Base.range.

Still wondering, though, whether the proper fix wouldn't be to do something about span.

@@ -133,7 +133,7 @@ function sourcetext(node::AbstractSyntaxNode)
end

function Base.range(node::AbstractSyntaxNode)
(node.position-1) .+ (1:span(node))
node.position:prevind(node.source.code, node.position + span(node))
Copy link
Member

Choose a reason for hiding this comment

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

It's intentional that range() specifically returns a byte range, so this part won't be correct without reviewing the other code.

(In fact, in a change I'm about to do, I'm renaming range() to byte_range()!)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, I see. I think it would be good to have some minimal docs about these things :)

Also, if it is supposed to not return string indices here, then there is probably some test missing that would actually fail with the changes in my PR here, right?

Copy link
Member

Choose a reason for hiding this comment

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

Mm more docs would be good.

At some point this package went from "a hacky thing I dream of being the main parser" to "oh wait it's actually important but still incomplete" 😆

Copy link
Member

Choose a reason for hiding this comment

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

(Or more accurately "Oh wait it's actually important but still incomplete and it's proximal to the work I'm actually paid for, but not part of what I'm paid for". A tricky place to be in mentally 😬)

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.

char_range() function for indexing into source strings
2 participants