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 sliceLocation helper to simplify location operations #406

Merged
merged 2 commits into from
Feb 11, 2025

Conversation

st0012
Copy link
Member

@st0012 st0012 commented Feb 6, 2025

Motivation

As suggested in sorbet#8485 (comment) and sorbet#8485 (comment)

Test plan

See included automated tests.

@st0012 st0012 requested a review from egiurleo February 6, 2025 17:33
Copy link

@egiurleo egiurleo left a comment

Choose a reason for hiding this comment

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

Nice! So much simpler.

@@ -2,9 +2,9 @@ name: CI

on:
push:
branches: [prism]
branches: [prism, prism-squashed]
Copy link

Choose a reason for hiding this comment

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

Good catch

Comment on lines +1935 to +1938
std::string_view Translator::sliceLocation(pm_location_t loc) {
return std::string_view(reinterpret_cast<const char *>(loc.start), loc.end - loc.start);
}

Copy link

Choose a reason for hiding this comment

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

I don't have a super strong opinion -- what do you think about moving this to Parser.cc? It only relies on Prism's parse tree state and could feasibly be useful even when we're no longer translating.

Copy link
Member Author

Choose a reason for hiding this comment

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

Given that Parser current doesn't have any other helper functions and we're still many PRs away from addressing all the feedback, I think it'd be simpler for future changes if we keep this and future helpers in the Translator by default, until we have a clearer understanding on how they'd be used outside of the translator.

@st0012 st0012 merged commit a06ff97 into prism-squashed Feb 11, 2025
1 check passed
@st0012 st0012 deleted the add-slice-location-helper branch February 11, 2025 13:53
st0012 added a commit that referenced this pull request Feb 18, 2025
* Add sliceLocation helper to simplify location operations

* Run CI on prism-squahed too
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