summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorEarlopain <[email protected]>2025-01-12 13:49:44 +0100
committergit <[email protected]>2025-01-12 18:54:16 +0000
commit566f9463c2be0010815c6521b32c5067a6fff699 (patch)
tree2a0f9eaa6ed9fd25b921fb73441e73a6a8f95c4f /lib
parent14b9098459b88f94e316ccc9274693e74565739e (diff)
[ruby/prism] Fix parser translator tSPACE tokens for percent arrays
Tests worked around this but the incompatibility is not hard to fix. This fixes 17 token incompatibilies in tests here that were previously passing https://github.com/ruby/prism/commit/101962526d
Diffstat (limited to 'lib')
-rw-r--r--lib/prism/translation/parser/lexer.rb10
1 files changed, 9 insertions, 1 deletions
diff --git a/lib/prism/translation/parser/lexer.rb b/lib/prism/translation/parser/lexer.rb
index fd1d0243ca..1808473cad 100644
--- a/lib/prism/translation/parser/lexer.rb
+++ b/lib/prism/translation/parser/lexer.rb
@@ -457,7 +457,15 @@ module Prism
location = range(token.location.start_offset, token.location.start_offset + 1)
end
- quote_stack.pop
+ if percent_array?(quote_stack.pop)
+ prev_token = lexed[index - 2][0] if index - 2 >= 0
+ empty = %i[PERCENT_LOWER_I PERCENT_LOWER_W PERCENT_UPPER_I PERCENT_UPPER_W].include?(prev_token&.type)
+ ends_with_whitespace = prev_token&.type == :WORDS_SEP
+ # parser always emits a space token after content in a percent array, even if no actual whitespace is present.
+ if !empty && !ends_with_whitespace
+ tokens << [:tSPACE, [nil, range(token.location.start_offset, token.location.start_offset)]]
+ end
+ end
when :tSYMBEG
if (next_token = lexed[index][0]) && next_token.type != :STRING_CONTENT && next_token.type != :EMBEXPR_BEGIN && next_token.type != :EMBVAR && next_token.type != :STRING_END
next_location = token.location.join(next_token.location)