Граф коммитов

32 Коммитов

Автор SHA1 Сообщение Дата
Kaíque Kandy Koga 6b64e78823 [ruby/irb] Examine indentation of in keyword when trying to type include
Use in_keyword_case_scope?

Return fast

https://github.com/ruby/irb/commit/8acc7f8dc7
2021-12-03 00:56:43 +09:00
schneems 2b22c93533 Compatibility with IRB
Instead of accessing the struct as an array, access it via methods. There are other places inside of this file already using this API (for example e0a5c3d2b7/lib/irb/ruby-lex.rb (L829-L830)).

This commit moves all struct array-ish calls to use their method calls instead. It is also ~1.23 faster accessing values via a method instead of as an array according to this microbenchmark:

```ruby
Elem = Struct.new(:pos, :event, :tok, :state, :message) do
  def initialize(pos, event, tok, state, message = nil)
    super(pos, event, tok, State.new(state), message)
  end

  # ...

  def to_a
    a = super
    a.pop unless a.empty?
    a
  end
end

class ElemClass
  attr_accessor :pos, :event, :tok, :state, :message

  def initialize(pos, event, tok, state, message = nil)
    @pos = pos
    @event = event
    @tok = tok
    @state = State.new(state)
    @message = message
  end

  def to_a
    if @message
      [@pos, @event, @tok, @state, @message]
    else
      [@pos, @event, @tok, @state]
    end
  end
end

# stub state class creation for now
class State; def initialize(val); end; end
```

```ruby
Benchmark.ips do |x|
  x.report("struct") { struct[1] }
  x.report("class ") { from_class.event }
  x.compare!
end; nil
```

```
Warming up --------------------------------------
              struct     1.624M i/100ms
              class      1.958M i/100ms
Calculating -------------------------------------
              struct     17.139M (± 2.6%) i/s -     86.077M in   5.025801s
              class      21.104M (± 3.4%) i/s -    105.709M in   5.015193s

Comparison:
              class : 21103826.3 i/s
              struct: 17139201.5 i/s - 1.23x  (± 0.00) slower
```
2021-12-02 15:55:42 +09:00
Kaíque Kandy Koga 782d1d876b [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
2021-09-22 23:26:41 +09:00
aycabta f085a6fb69 [ruby/irb] Support symbol with backtick
https://github.com/ruby/irb/commit/0aa2425883
2021-09-10 04:59:17 +09:00
Hiroshi SHIBATA 598f4f4219 [ruby/irb] Use pend instead of skip
https://github.com/ruby/irb/commit/f441ce35bf
2021-08-30 12:39:23 +09:00
aycabta 0259ee6008 [ruby/irb] Change ripper_lex_without_warning to a class method
https://github.com/ruby/irb/commit/d9f8abc17e
2021-03-24 14:39:50 +09:00
aycabta 182cde8dfb [ruby/irb] Add a test for not continuing when endless range at eol
https://github.com/ruby/irb/commit/1020ac9c65
2021-03-05 22:03:11 +09:00
aycabta 743c44ee21 [ruby/irb] Indent correctly with method calling with receiver
https://github.com/ruby/irb/commit/e7c68e74a0
2021-01-24 14:35:34 +09:00
aycabta fc54af8aa1 [ruby/irb] Indent correctly with keyword "for" and "in"
https://github.com/ruby/irb/commit/47c83ea724
2021-01-24 14:35:26 +09:00
aycabta 0123bc9d38 [ruby/irb] Use error tokens if there are no correct tokens in the same place
For example, the broken code "%www" will result in only one error token.

https://github.com/ruby/irb/commit/9fa39a7cf3
2021-01-05 18:06:43 +09:00
aycabta 5a1866caff [ruby/irb] Use Ripper::Lexer#scan to take broken tokens
ref. https://github.com/ruby/reline/pull/242

https://github.com/ruby/irb/commit/54f90cb6c9
2021-01-05 18:06:34 +09:00
aycabta 505e01fe12 [ruby/irb] Heredoc may contain multiple newlines in a single token
Use the start token as the indentation criteria so that it works properly in
heredoc.

ref. https://github.com/ruby/reline/pull/242

https://github.com/ruby/irb/commit/9704808dfd
2021-01-05 18:06:26 +09:00
aycabta 5012512398 [ruby/irb] Handle indentations related to keyword "do" correctly
This fixes ruby/irb#158.

https://github.com/ruby/irb/commit/964643400b
2021-01-05 18:06:10 +09:00
aycabta cce72a2411 [ruby/irb] Newline in oneliner def doesn't reset indent
This closes ruby/irb#132.

https://github.com/ruby/irb/commit/43456dcf5e
2021-01-05 18:04:45 +09:00
aycabta 129ecb43e5 [ruby/irb] Fix error_message for assert_dynamic_prompt
https://github.com/ruby/irb/commit/b12dfb6298
2020-12-23 21:26:25 +09:00
aycabta 841d22ea47 [ruby/reline] [ruby/irb] Handle multiple newlines in a token correctly
Co-authored-by: manga_osyo <manga.osyo@gmail.com>
Co-authored-by: ima1zumi <mariimaizumi5@gmail.com>

https://github.com/ruby/irb/commit/c59a9be82f

https://github.com/ruby/reline/commit/a7922da16b
2020-12-23 06:06:07 +09:00
Nobuhiro IMAI 5218f17737 [ruby/irb] support more body argument for oneliner method definition
https://github.com/ruby/irb/commit/2ff1295533
2020-11-22 21:00:11 +09:00
aycabta a30dea5852 [ruby/irb] Support shortening lambda notetion for nesting level of prompt
https://github.com/ruby/irb/commit/f1a775af47
2020-08-18 14:38:02 +09:00
aycabta 43c648c832 [ruby/irb] Support shortening lambda notation
https://github.com/ruby/irb/commit/8e3f81d428
2020-08-18 14:38:02 +09:00
aycabta 5474007d61 [ruby/irb] Support oneline method definition
https://github.com/ruby/irb/commit/826ae909c9
2020-08-18 14:38:01 +09:00
Nobuhiro IMAI f6e789e3b0 [ruby/irb] handle rescue modifier properly
https://github.com/ruby/irb/commit/6de1341f5e
2020-07-22 02:31:47 +09:00
aycabta 4268084d69 [ruby/irb] Add encoding magic comments of editors
https://github.com/ruby/irb/commit/f8c10ea24b
2020-07-22 02:31:47 +09:00
aycabta 1dfd24a7fc [ruby/irb] Suppress incomplete encoding magic comment error
https://github.com/ruby/irb/commit/443e90af80
2020-07-22 02:31:46 +09:00
aycabta 78ccab2530 [ruby/irb] Suppress incomplete coding magic comment error
https://github.com/ruby/irb/commit/6a457edbd1
2020-07-22 02:31:46 +09:00
Kazuhiro NISHIYAMA f5b7896921
Fix a typo [ci skip] 2020-02-29 15:14:01 +09:00
aycabta 8b8cc01229 [ruby/irb] Fix auto indent with closed brace
A closed brace in auto-indent shouldn't affect the next brace in the same line,
but it behaves like below:

  p() {
    }

It's a bug.

https://github.com/ruby/irb/commit/fbe59e344f
2020-02-12 13:14:28 +09:00
Ben c94025b630 [ruby/irb] Fix crashing when multiple open braces per line
https://github.com/ruby/irb/issues/55

If we had put multiple open braces on a line the with no closing brace
spaces_of_nest array keeps getting '0' added to it. This means that when
we pop off of this array we are saying that we should be in position zero
for the next line. This is an issue because we don't always want to be
in position 0 after a closing brace.

Example:
```
[[[
]
]
]
```
In the above example the 'spaces_of_nest' array looks like this after
the first line is entered: [0,0,0]. We really want to be indented 4
spaces for the 1st closing brace 2 for the 2nd and 0 for the 3rd. i.e.
we want it to be: [0,2,4].

We also saw this issue with a heredoc inside of an array.

```
[<<FOO]
hello
FOO
```

https://github.com/ruby/irb/commit/80c69c8272
2020-01-14 15:40:38 +09:00
Ben 9994eb8a5e [ruby/irb] Fix newline depth with multiple braces
This commit fixes the check_newline_depth_difference method to multiple
open braces on one line into account. Before this change we were
subtracting from the depth in check_newline_depth_difference on
every open brace. This is the right thing to do if the opening and
closing brace are on the same line. For example in a method definition we
have an opening and closing parentheses we want to add 1 to our depth,
and then remove it.

```
def foo()
end
```

However this isn't the correct behavior when the brace spans multiple
lines. If a brace spans multiple lines we don't want to subtract from
check_newline_depth_difference and we want to treat the braces the same
way as we do `end` and allow check_corresponding_token_depth to pop the
correct depth.

Example of bad behavior:

```
def foo()
  [
  ]
puts 'bar'
end
```

Example of desired behavior:

```
def foo()
  [
  ]
  puts 'bar'
end
```

https://github.com/ruby/irb/commit/7dc8af01e0
2020-01-14 15:40:38 +09:00
aycabta 049292e302 Add load path and require for ruby/ruby 2020-01-01 02:04:41 +09:00
aycabta 66e6055c11 [ruby/irb] Fix lib name of OpenStruct
https://github.com/ruby/irb/commit/1f3a84ab6b
2020-01-01 01:38:37 +09:00
aycabta 9deb942715 Add "require 'openstruct'" what is forgotten 2019-12-31 23:32:24 +09:00
Ben a118bb805f [ruby/irb] Add tests for RubyLex
The set_auto_indent method calculates the correct number of spaces for
indenting a line. We think there might be a few bugs in this method so
we are testing the current functionality to make sure nothing breaks
when we address those bugs.

Example test failure:

```
  1) Failure:
TestIRB::TestRubyLex#test_auto_indent [/Users/Ben/Projects/irb/test/irb/test_ruby_lex.rb:75]:
Calculated the wrong number of spaces for:
 def each_top_level_statement
  initialize_input
  catch(:TERM_INPUT) do
    loop do
      begin
        prompt
        unless l = lex
          throw :TERM_INPUT if @line == ''
        else
.
<10> expected but was
<12>.
```

https://github.com/ruby/irb/commit/752d5597ab
2019-12-31 23:32:24 +09:00