-
Notifications
You must be signed in to change notification settings - Fork 150
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 squiggly heredocs for the parser translator #3341
Implement squiggly heredocs for the parser translator #3341
Conversation
a179339
to
02c0a66
Compare
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 |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
02c0a66
to
302cc30
Compare
302cc30
to
8bbdc4f
Compare
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.
8bbdc4f
to
7bfd527
Compare
There was a problem hiding this 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!
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.