diff options
| author | tomoya ishida <tomoyapenguin@gmail.com> | 2024-01-30 21:55:43 +0900 |
|---|---|---|
| committer | git <svn-admin@ruby-lang.org> | 2024-01-30 12:55:47 +0000 |
| commit | fd44b42fb308ddf71d709a508901d68583e61f51 (patch) | |
| tree | 0a2068557ea592938f854c722e899b5b4b6a4a80 /lib | |
| parent | f73ae058197ac134b89b0765bae147a19122f3dd (diff) | |
[ruby/irb] Fix undef and alias indent
(https://github.com/ruby/irb/pull/838)
https://github.com/ruby/irb/commit/a641746b18
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/irb/nesting_parser.rb | 10 | ||||
| -rw-r--r-- | lib/irb/ruby-lex.rb | 2 |
2 files changed, 11 insertions, 1 deletions
diff --git a/lib/irb/nesting_parser.rb b/lib/irb/nesting_parser.rb index 23eeeaf6cf..5aa940cc28 100644 --- a/lib/irb/nesting_parser.rb +++ b/lib/irb/nesting_parser.rb @@ -12,6 +12,8 @@ module IRB skip = false last_tok, state, args = opens.last case state + when :in_alias_undef + skip = t.event == :on_kw when :in_unquoted_symbol unless IGNORE_TOKENS.include?(t.event) opens.pop @@ -130,6 +132,10 @@ module IRB opens.pop opens << [t, nil] end + when 'alias' + opens << [t, :in_alias_undef, 2] + when 'undef' + opens << [t, :in_alias_undef, 1] when 'elsif', 'else', 'when' opens.pop opens << [t, nil] @@ -174,6 +180,10 @@ module IRB pending_heredocs.reverse_each { |t| opens << [t, nil] } pending_heredocs = [] end + if opens.last && opens.last[1] == :in_alias_undef && !IGNORE_TOKENS.include?(t.event) && t.event != :on_heredoc_end + tok, state, arg = opens.pop + opens << [tok, state, arg - 1] if arg >= 1 + end yield t, opens if block_given? end opens.map(&:first) + pending_heredocs.reverse diff --git a/lib/irb/ruby-lex.rb b/lib/irb/ruby-lex.rb index 4bce2aa6b2..754acfad05 100644 --- a/lib/irb/ruby-lex.rb +++ b/lib/irb/ruby-lex.rb @@ -290,7 +290,7 @@ module IRB when :on_embdoc_beg indent_level = 0 else - indent_level += 1 + indent_level += 1 unless t.tok == 'alias' || t.tok == 'undef' end end indent_level |
