diff options
author | KaĆque Kandy Koga <kaiquekandykoga@gmail.com> | 2021-09-19 16:44:11 -0300 |
---|---|---|
committer | git <svn-admin@ruby-lang.org> | 2021-09-22 23:26:41 +0900 |
commit | 782d1d876bb119284f52a7eb59e63f3571c4d55e (patch) | |
tree | 813e03d255c54985bb459df5e039c3056fac709c /lib/irb | |
parent | 7c0230b05d0978958f89434c84ddd9c82419c1a5 (diff) | |
download | ruby-782d1d876bb119284f52a7eb59e63f3571c4d55e.tar.gz |
[ruby/irb] Use typed spaces when the line is inside the here documents
Use first method instead of square brackets to support 2.5 and 2.6 versions
Use tokens
Clear check_newline_depth_difference
https://github.com/ruby/irb/commit/6fec2a5d46
Diffstat (limited to 'lib/irb')
-rw-r--r-- | lib/irb/ruby-lex.rb | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/lib/irb/ruby-lex.rb b/lib/irb/ruby-lex.rb index e281169788..f0c056e297 100644 --- a/lib/irb/ruby-lex.rb +++ b/lib/irb/ruby-lex.rb @@ -207,7 +207,7 @@ class RubyLex last_line = lines[line_index]&.byteslice(0, byte_pointer) code += last_line if last_line @tokens = self.class.ripper_lex_without_warning(code, context: context) - corresponding_token_depth = check_corresponding_token_depth + corresponding_token_depth = check_corresponding_token_depth(lines, line_index) if corresponding_token_depth corresponding_token_depth else @@ -603,7 +603,7 @@ class RubyLex depth_difference end - def check_corresponding_token_depth + def check_corresponding_token_depth(lines, line_index) corresponding_token_depth = nil is_first_spaces_of_line = true is_first_printable_of_line = true @@ -611,6 +611,11 @@ class RubyLex spaces_at_line_head = 0 open_brace_on_line = 0 in_oneliner_def = nil + + if heredoc_scope? + return lines[line_index][/^ */].length + end + @tokens.each_with_index do |t, index| # detecting one-liner method definition if in_oneliner_def.nil? @@ -817,5 +822,12 @@ class RubyLex end false end + + private + + def heredoc_scope? + heredoc_tokens = @tokens.select { |t| [:on_heredoc_beg, :on_heredoc_end].include?(t.event) } + heredoc_tokens[-1]&.event == :on_heredoc_beg + end end # :startdoc: |