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

75 Коммитов

Автор SHA1 Сообщение Дата
Stan Lo d3311e5cc3 [ruby/irb] Add black and white color to IRB::Color
(https://github.com/ruby/irb/pull/676)

https://github.com/ruby/irb/commit/a2763acade
2023-08-11 16:03:11 +00:00
Stan Lo 2f8e5c80e6 [ruby/irb] Drop Ruby 2.6 support
(https://github.com/ruby/irb/pull/555)

* Remove all Ruby 2.6 support

* Drop Ruby 2.6 specific testing conditions

* Only run Ruby 2.7+ on CI

* Bump Ruby requirement to 2.7+

https://github.com/ruby/irb/commit/3f714b616c
2023-04-05 21:40:40 +00:00
tomoya ishida f313514563 [ruby/irb] Fix colorize backtick symbol
(https://github.com/ruby/irb/pull/508)

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

Co-authored-by: Stan Lo <stan001212@gmail.com>
2023-02-12 20:27:32 +00:00
Takashi Kokubun 931bcd1b63 [ruby/irb] Assert lvars_code doesn't include \n
Removing /\A.+\n/ could have an unexpected impact, depending on how
RubyLex.generate_local_variables_assign_code is implemented. It feels
like a too much assumption and the intention isn't immediately clear,
so I added these changes.

https://github.com/ruby/irb/commit/ccc07a35ce
2022-10-18 06:03:23 +00:00
tomoya ishida a09f764ce5 [ruby/irb] Always use local variables in current context to parse code (https://github.com/ruby/irb/pull/397)
* Use local_variables for colorize, code_block_open check, nesting_level and assignment_expression check

* Check if expression is an assignment BEFORE evaluating it. evaluate might define new localvars and change result of assignment_expression?

* Add local_variables dependent code test

* pend local variable dependent test on truffleruby

code_block_open is not working on truffleruby

* Always pass context to RubyLex#lex

* Rename local_variable_assign_code generator method name

* Add assignment expression truncate test

* Add Context#local_variables and make generate_local_variables_assign_code more simple

* Update lib/irb/input-method.rb

Co-authored-by: Stan Lo <stan001212@gmail.com>

* Add a comment why assignment expression check should be done before evaluate

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

Co-authored-by: Stan Lo <stan001212@gmail.com>
Co-authored-by: Takashi Kokubun <takashikkbn@gmail.com>
2022-10-18 05:44:07 +00:00
tompng 369f1668cd [ruby/irb] Rewrite on_scan proc to be more readable.
https://github.com/ruby/irb/commit/da54e7f081
2022-09-22 00:37:40 +09:00
tompng 9f68687879 [ruby/irb] Scan every single characters in IRB::Color.scan
https://github.com/ruby/irb/commit/d14e56a65d
2022-09-22 00:37:38 +09:00
st0012 7d211c93af [ruby/irb] Color.colorable? needs to consider the condition when irb is not loaded
ruby/debug uses `irb/color` selectively:
0ac22406bb/lib/debug/color.rb (L4)

And in that case, `IRB.conf` won't be defined. So Color.colorable? needs
to consider that.

This also fixes the Ruby trunk CI.

https://github.com/ruby/irb/commit/b2cd07e795
2022-06-28 22:57:17 +09:00
Stan Lo 44c1316293 [ruby/irb] Centralize coloring control (https://github.com/ruby/irb/pull/374)
* Use colorable: argument as the only coloring control

* Centalize color controling logic at Color.colorable?

There are 2 requirements for coloring output:

1. It's supported on the platform
2. The user wants it: `IRB.conf[:USE_COLORIZE] == true`

Right now we check 1 and 2 separately whenever we colorize things.
But it's error-prone because while 1 is the default of `colorable`
parameter, 2 always need to manually checked. When 2 is overlooked, it
causes issues like https://github.com/ruby/irb/pull/362

And there's 0 case where we may want to colorize even when the user
disables it. So I think we should merge 2 into `Color.colorable?` so it
can be automatically picked up.

* Add tests for all inspect modes

* Simplify inspectors' coloring logic

* Replace use_colorize? with Color.colorable?

* Remove Context#use_colorize cause it's redundant

https://github.com/ruby/irb/commit/1c53023ac4
2022-06-28 22:30:42 +09:00
st0012 81b604fb00 [ruby/irb] Use require_relative to require lib files
1. `require` can mislead Ruby to load system irb's files and cause
   constant redefined warnings as other code loads the same module/class
   from lib folder.
2. Most files already use `require_relative`.

https://github.com/ruby/irb/commit/848d339f2e
2022-01-17 14:23:40 +09:00
Nobuyoshi Nakada 8fdc45c894 [ruby/irb] Added `colorable` keyword option
Currently `IRB::Color.colorize` and `IRB::Color.colorize_code`
refer `$stdin.tty?` internally.
This patch adds `colorable` keyword option which overrides it.

https://github.com/ruby/irb/commit/402e3f1907
2021-04-26 21:14:52 +09:00
Nobuyoshi Nakada 3816157e5d [ruby/irb] Ripper::Lexer::Elem#state is defined since Ruby 2.5
And the required ruby version is 2.5 or later.

https://github.com/ruby/irb/commit/ac496d4c78
2021-04-08 20:42:14 +09:00
Nobuyoshi Nakada 79af8ce6d7 [ruby/irb] Colorize `__END__` as keyword
https://github.com/ruby/irb/commit/9b84018311
2021-04-02 10:52:53 +09:00
Nobuhiro IMAI 3f0b4665df [ruby/irb] handle `__ENCODING__` as a keyword as well
https://github.com/ruby/irb/commit/a6a33d908f
2021-01-18 02:12:43 +09:00
Nobuyoshi Nakada 903af74bbd [ruby/irb] Ensure to restore $VERBOSE
https://github.com/ruby/irb/commit/cef474a76a
2021-01-05 18:07:18 +09:00
Takashi Kokubun 6d07785127 [ruby/irb] Remove unnecessary ignore_error in dispatch_seq
Just forgotten in a5804c3560

https://github.com/ruby/irb/commit/e42e548793
2020-12-28 23:29:29 -08:00
Takashi Kokubun f30a3a0629
[ruby/irb] Do not colorize partially-correct inspect
This is to prevent a yellow-mixed output for ActiveSupport::TimeWithZone.

Follows up https://github.com/ruby/irb/pull/159 and https://github.com/ruby/ruby/pull/3967.

a5804c3560
2020-12-28 23:29:08 -08:00
Nobuhiro IMAI 9b7ceb6765
irb: add more syntax errors colorizing support (#3967) 2020-12-28 23:07:20 -08:00
Takashi Kokubun c715fb46c2 [ruby/irb] Enhance colored inspect output
https://github.com/ruby/irb/commit/dffcdb5269
2020-12-28 23:01:00 -08:00
Nobuyoshi Nakada 0fcbd07247 [ruby/irb] Directly check if the method is available instead of version
https://github.com/ruby/irb/commit/3ea9fd9ed0
2020-08-18 14:38:01 +09:00
aycabta 20172672db Add require 'irb/ruby-lex' to use RubyLex 2020-07-22 04:11:38 +09:00
aycabta c72a2fad97 [ruby/irb] Simplify RubyLex.compile_with_errors_suppressed
nobu-san reviewed,

https://github.com/ruby/irb/pull/106#pullrequestreview-423400033
> How about lexer = Ripper::Lexer.new(";\n#{code}", nil, 0)?
> Encoding pragma is effective only at the beginning.
> And the semicolon and newline will be skipped because the position is before
> the initial pos.

I employ the way.

Co-authored-by: Nobuyoshi Nakada <nobu@ruby-lang.org>

https://github.com/ruby/irb/commit/e593cc65b7
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
aycabta a5b6d7bca8 Suppress warnings except for when last evaluation
Co-authored-by: Kazuhiro NISHIYAMA <zn@mbf.nifty.com>
2019-11-13 15:15:28 +09:00
Takashi Kokubun fcd9bc28e3
qsymbols and symbols should be colored as Symbol 2019-11-10 13:54:44 -08:00
Takashi Kokubun 25c53a8eec
Colorize on_symbols_beg (%I) 2019-11-10 13:41:41 -08:00
Takashi Kokubun b5996b25ae
Colorize string quotes as bold
like pry
2019-11-10 13:33:23 -08:00
Nobuyoshi Nakada c01df7e58f
Fixed the key to delete [Bug #16250]
f94202fcc2 (commitcomment-35505076)

Co-Authored-By: Ary Borenszweig <asterite@gmail.com>
2019-10-15 23:16:24 +09:00
Nobuyoshi Nakada f94202fcc2
Use compare_by_identity hash [Bug #16250] 2019-10-15 19:41:16 +09:00
Takashi Kokubun c800967acd
Simplify circular reference check of IRB::Color 2019-10-14 21:58:13 -07:00
Ary Borenszweig 96617ad1d5 IRB colorize: take into account recursive arrays and hashes (#2555)
[Bug #16250]
2019-10-14 21:25:05 -07:00
Takashi Kokubun 1808029061
make sync-default-gems GEM=irb
Upgrade IRB to 41ea43a4a7

Mostly backport changes.
2019-06-13 00:32:20 +09:00
Nobuyoshi Nakada 9593e76ac2
Ripper::Lexer: fallback parse error token to the previous one 2019-06-12 15:25:06 +09:00
Takashi Kokubun 9987f45765
Reflect behavior changes to argument name
0c459af7c2 changed the meaning of
`detect_compile_error`, and this commit lets it follow the change.
2019-06-04 00:36:51 +09:00
Takashi Kokubun de541fe196
colorize_code must return escaped text
This was needed before 0c459af7c2 but it
could be actually useless now. But I added this anyway just in case.
2019-06-04 00:26:02 +09:00
Nobuyoshi Nakada 0c459af7c2
Colorize error characters
* lib/irb/color.rb (IRB::Color.scan): ignore "incomplete end of
  input" error only, to colorize invalid characters, e.g., control
  characters, and invalid symbols, as errors.
2019-06-04 00:14:55 +09:00
Takashi Kokubun 856593cc49
Fix typo 🐛 [ci skip] 2019-05-31 09:44:14 +09:00
Takashi Kokubun cb40a21da0
Warn compile_error only when input is finished
Let's say we are in progress to write `"foo"`:

```
irb> "fo
```

at this moment, nothing is wrong.
It would be just a normal way to write `"foo"`.

Prior to this commit, the `fo` part was warned because of
5b64d7ac6e. But I think warning such a
normal input is not valuable for users.

However, we'd like to warn `:@1` or `@@1` which is also a syntax error.
Then this commit switches the syntax highlight based on whether the
input text is finished or not. When it's not finished yet, it does not
warn compile_error.
2019-05-31 06:54:00 +09:00
Takashi Kokubun 6e052817f9
Abstract away Ripper::Lexer#scan in IRB::Color#scan
because 5b64d7ac6e made it hard to
understand #colorize_code for me and this change is needed for my next
commit.
2019-05-31 06:21:17 +09:00
Nobuyoshi Nakada 5b64d7ac6e
Colorize errors more
* lib/irb/color.rb (IRB::Color.colorize_code): colorize
  `compile_error` part as same as `on_parse_error`.
2019-05-29 22:09:54 +09:00
Nobuyoshi Nakada 12644e8b02
Get rid of nested string interpolations
* lib/irb/color.rb (IRB::Color.colorize): get rid of nesting string
  interpolations not to confuse ruby-mode.el
2019-05-29 21:59:34 +09:00
Nobuyoshi Nakada 5ceff480c2
ripper: Ripper::Lexer#scan
* ext/ripper/lib/ripper/lexer.rb (Ripper::Lexer#scan): parses the
  code and returns the result elements including errors.
  [EXPERIMENTAL]
2019-05-29 18:21:28 +09:00
Nobuyoshi Nakada 068d327595
Colorize compile_error as same as on_parse_error 2019-05-29 13:34:19 +09:00
Nobuyoshi Nakada cc66272e50
parse.y: flush invalid char 2019-05-29 13:24:24 +09:00
Koichi Sasada 8187ffa461 Revert "Colorize error part more"
This reverts commit c7f3c222c9.
2019-05-29 04:30:36 +01:00
Nobuyoshi Nakada c7f3c222c9
Colorize error part more
Colorize `compile_error` parts as well as `on_parse_error` parts.
2019-05-29 12:12:19 +09:00
Nobuyoshi Nakada 8a2a5822ca
Colorize error part 2019-05-27 23:08:51 +09:00
Takashi Kokubun 64ee8900c8
Highlight global variable on IRB 2019-05-26 11:32:23 -07:00
Takashi Kokubun 7597f7ecb1
Simplify lexer state matching in #dispatch_seq
for improving readability of the condition. It may be slightly faster, or may not.
2019-05-26 11:26:04 -07:00
Takashi Kokubun 897901283c
Refactor IRB color dispatch
The reason why we were checking lexer state in addition to token was
that we do not want to colorize local variable, method call, etc., while
they share the :on_ident token with a name of method definition which
should be colored as blue.

It means that we're concerned about the lexer state only for :on_ident.
Thus we can skip checking lexer state for non-:on_ident tokens. This
refactoring is based on that idea.

Also, now we manage Ripper's lexer state as Integer (use `|` if you
need to check multiple states). It should be faster than using Array of
Integer because #any? block call is not needed.
2019-05-26 11:03:57 -07:00