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

Implement Prism -> Sorbet translation for interpolated matches #298

Merged
merged 3 commits into from
Oct 25, 2024

Conversation

amomchilov
Copy link

Similar to #288, but for interpolated regexes. Closes #117.

@amomchilov amomchilov self-assigned this Oct 24, 2024
@@ -645,6 +645,16 @@ unique_ptr<parser::Node> Translator::translate(pm_node_t *node) {
// Will only work for positive, 32-bit integers
return make_unique<parser::Integer>(location, std::to_string(intNode->value.value));
}
case PM_INTERPOLATED_MATCH_LAST_LINE_NODE: { // A test of the last read line with interpolation,
Copy link
Member

Choose a reason for hiding this comment

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

A test? I don't quite get what this means.

Copy link
Author

Choose a reason for hiding this comment

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

Yeah it's really hard to summarize clearly.

I explain it better in the PR description of #288. Given that, do you have any suggestion for how to summarize it here?

Copy link
Member

Choose a reason for hiding this comment

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

Thanks for the context, and WOW.
Maybe something like: An interpolated regex in a conditional that checks last read line from IO?

Choose a reason for hiding this comment

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

I like Stan's description!

Copy link
Author

Choose a reason for hiding this comment

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

I had to break it on 2 line to pass the formatter. That gave me some extra room, so I added some more detail:

Suggested change
case PM_INTERPOLATED_MATCH_LAST_LINE_NODE: { // A test of the last read line with interpolation,
case PM_INTERPOLATED_MATCH_LAST_LINE_NODE: { // An interpolated regex literal in a conditional...
// ...that implicitly checks against the last read line by an IO object, e.g. `if /wat #{123}/`

test/prism_regression/match_last_line.rb Outdated Show resolved Hide resolved
@@ -645,6 +645,16 @@ unique_ptr<parser::Node> Translator::translate(pm_node_t *node) {
// Will only work for positive, 32-bit integers
return make_unique<parser::Integer>(location, std::to_string(intNode->value.value));
}
case PM_INTERPOLATED_MATCH_LAST_LINE_NODE: { // A test of the last read line with interpolation,

Choose a reason for hiding this comment

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

I like Stan's description!

@amomchilov amomchilov marked this pull request as draft October 24, 2024 19:29
@amomchilov amomchilov marked this pull request as ready for review October 25, 2024 17:21
@amomchilov amomchilov merged commit efc984d into prism Oct 25, 2024
1 check passed
@amomchilov amomchilov deleted the Alex/translate-last-line-2 branch October 25, 2024 19:18
@amomchilov amomchilov changed the title Implement translation of interpolated matches Implement Prism -> Sorbet translation for interpolated matches Oct 25, 2024
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.

Implement translation for PM_INTERPOLATED_MATCH_LAST_LINE_NODE
3 participants