summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorEarlopain <[email protected]>2025-01-13 21:17:29 +0100
committerKevin Newton <[email protected]>2025-03-18 13:36:53 -0400
commit177adf6fa543663334bfb8918b356b4771e5ff1a (patch)
tree7e89331772a1ebffbe062b78d96c6d63e41c96f2 /lib
parentac728389e219480dd678a01e6f91f96098d3b6d6 (diff)
[ruby/prism] Fix parser translator tokens for %-arrays with whitespace escapes
Also fixes a token incompatibility for the word separator. parser only considers whitespace until the first newline https://github.com/ruby/prism/commit/bd3dd2b62a
Diffstat (limited to 'lib')
-rw-r--r--lib/prism/translation/parser/lexer.rb17
1 files changed, 17 insertions, 0 deletions
diff --git a/lib/prism/translation/parser/lexer.rb b/lib/prism/translation/parser/lexer.rb
index 4f2ea1855a..a2d4e84a13 100644
--- a/lib/prism/translation/parser/lexer.rb
+++ b/lib/prism/translation/parser/lexer.rb
@@ -403,6 +403,20 @@ module Prism
end
when :tSTRING_CONTENT
is_percent_array = percent_array?(quote_stack.last)
+<<<<<<< HEAD
+=======
+
+ if (lines = token.value.lines).one?
+ # Heredoc interpolation can have multiple STRING_CONTENT nodes on the same line.
+ 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_percent_array
+ value = percent_array_unescape(value)
+ elsif is_first_token_on_line && not_nested && (current_heredoc = heredoc_stack.last).common_whitespace > 0
+ value = trim_heredoc_whitespace(value, current_heredoc)
+ end
+>>>>>>> bd3dd2b62a (Fix parser translator tokens for %-arrays with whitespace escapes)
if (lines = token.value.lines).one?
# Prism usually emits a single token for strings with line continuations.
@@ -712,6 +726,7 @@ module Prism
end
end
+<<<<<<< HEAD
# Certain strings are merged into a single string token.
def simplify_string?(value, quote)
case quote
@@ -777,6 +792,8 @@ module Prism
end
end
+=======
+>>>>>>> bd3dd2b62a (Fix parser translator tokens for %-arrays with whitespace escapes)
# In a percent array, certain whitespace can be preceeded with a backslash,
# causing the following characters to be part of the previous element.
def percent_array_unescape(string)