Skip to content

Conversation

@Earlopain
Copy link
Collaborator

In parser, the string content is dedented. This implements these rules as far as I was able to understand them. It's all a bit confusing with spaces/tabs, always learning more funny things about them.

I refered to the prism implementation, parser seems to adhere to it very closely.

@Earlopain Earlopain force-pushed the parser-translator-squigly-heredoc branch 2 times, most recently from a179339 to 02c0a66 Compare December 23, 2024 11:01
is_first_token_on_line = lexed[index - 1] && token.location.start_line != lexed[index - 2][0].location&.start_line
# The parser gem only removes indentation when the heredoc is not nested
not_nested = heredoc_stack.size == 1
if is_first_token_on_line && not_nested && (heredoc = heredoc_stack[0]).common_whitespace > 0
Copy link
Collaborator Author

@Earlopain Earlopain Dec 23, 2024

Choose a reason for hiding this comment

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

Any tip for getting this through sorbet? It complains that heredoc can be nil but that will never be the case because the previous condition checked that the first element is present.

When rewriting this into something that proves to sorbet that it can't be nil, it's telling me that the condition is always falsy.

This also fails:

index = 0
lexed = [:FIRST, :SECOND]
length = lexed.length

identifiers = []

while index < length
  token = lexed[index]
  index += 1

  case token
  when :FIRST

    identifiers.push("abc")
  when :SECOND
    if (identifier = identifiers[0])
      puts identifier
    end
  end
end

It seems to believe that the array is always empty

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Got a workaround from sorbet/sorbet#8401 (comment) that seems to work

In parser, the string content is dedented. This implements these rules
as far as I was able to understand them. It's all a bit confusing with
spaces/tabs, always learning more funny things about them.

I refered to the prism implementation, parser seems to adhere to it very closely.
@Earlopain Earlopain force-pushed the parser-translator-squigly-heredoc branch from 8bbdc4f to 7bfd527 Compare December 30, 2024 15:00
Copy link
Collaborator

@kddnewton kddnewton left a comment

Choose a reason for hiding this comment

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

Wow, amazing work. I don't know that I can properly review this because obviously the code is quite complex. But the tests are passing and you've got even more tests passing, so I'm assuming this is working. Nice job!

@kddnewton kddnewton merged commit fd93c43 into ruby:main Jan 3, 2025
56 checks passed
@Earlopain Earlopain deleted the parser-translator-squigly-heredoc branch January 7, 2025 20:05
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