From 83f995ef19c6a97bec3f7deb05b7f2da5880c0a8 Mon Sep 17 00:00:00 2001 From: Earlopain <14981592+Earlopain@users.noreply.github.com> Date: Mon, 23 Dec 2024 16:06:30 +0100 Subject: [PATCH] Fix parser token incompatibility with w/q arrays Take this code: `%I( )` It is currently made up of four tokens: ``` tSYMBOLS_BEG tSPACE tSTRING_END tNL ``` But for these types of arrays, the parser gem never emits the space token --- lib/prism/translation/parser/lexer.rb | 4 ++++ test/prism/ruby/parser_test.rb | 8 -------- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/lib/prism/translation/parser/lexer.rb b/lib/prism/translation/parser/lexer.rb index 4334540381..b03b1406cd 100644 --- a/lib/prism/translation/parser/lexer.rb +++ b/lib/prism/translation/parser/lexer.rb @@ -384,6 +384,10 @@ def to_a if (next_token = lexed[index][0]) && next_token.type != :STRING_CONTENT && next_token.type != :STRING_END type = :tBACK_REF2 end + when :tSYMBOLS_BEG, :tQSYMBOLS_BEG, :tWORDS_BEG, :tQWORDS_BEG + if (next_token = lexed[index][0]) && next_token.type == :WORDS_SEP + index += 1 + end end tokens << [type, [value, location]] diff --git a/test/prism/ruby/parser_test.rb b/test/prism/ruby/parser_test.rb index 8d5c02ff51..b1c86d2ce2 100644 --- a/test/prism/ruby/parser_test.rb +++ b/test/prism/ruby/parser_test.rb @@ -116,11 +116,7 @@ class ParserTest < TestCase "seattlerb/heredoc_with_carriage_return_escapes.txt", "seattlerb/heredoc_with_interpolation_and_carriage_return_escapes_windows.txt", "seattlerb/heredoc_with_interpolation_and_carriage_return_escapes.txt", - "seattlerb/interpolated_symbol_array_line_breaks.txt", - "seattlerb/interpolated_word_array_line_breaks.txt", "seattlerb/module_comments.txt", - "seattlerb/non_interpolated_symbol_array_line_breaks.txt", - "seattlerb/non_interpolated_word_array_line_breaks.txt", "seattlerb/parse_line_block_inline_comment_leading_newlines.txt", "seattlerb/parse_line_block_inline_comment.txt", "seattlerb/parse_line_block_inline_multiline_comment.txt", @@ -129,9 +125,7 @@ class ParserTest < TestCase "seattlerb/parse_line_multiline_str_literal_n.txt", "seattlerb/parse_line_str_with_newline_escape.txt", "seattlerb/pct_w_heredoc_interp_nested.txt", - "seattlerb/qsymbols_empty_space.txt", "seattlerb/qw_escape_term.txt", - "seattlerb/qWords_space.txt", "seattlerb/read_escape_unicode_curlies.txt", "seattlerb/read_escape_unicode_h4.txt", "seattlerb/required_kwarg_no_value.txt", @@ -139,7 +133,6 @@ class ParserTest < TestCase "seattlerb/str_double_escaped_newline.txt", "seattlerb/str_evstr_escape.txt", "seattlerb/str_newline_hash_line_number.txt", - "seattlerb/symbols_empty_space.txt", "seattlerb/TestRubyParserShared.txt", "unparser/corpus/literal/assignment.txt", "unparser/corpus/literal/dstr.txt", @@ -152,7 +145,6 @@ class ParserTest < TestCase "whitequark/dedenting_heredoc.txt", "whitequark/dedenting_non_interpolating_heredoc_line_continuation.txt", "whitequark/forward_arg_with_open_args.txt", - "whitequark/interp_digit_var.txt", "whitequark/lbrace_arg_after_command_args.txt", "whitequark/multiple_pattern_matches.txt", "whitequark/newline_in_hash_argument.txt",