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

62 Коммитов

Автор SHA1 Сообщение Дата
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
aycabta 1226791368 Support :@@cvar and : on colorize 2019-05-27 02:56:05 +09:00
Takashi Kokubun e50aa359de
Make the imaginary color on IRB close to pry
and sorted the token names alphabetically.
2019-05-26 10:23:04 -07:00
Nobuyoshi Nakada 4f2a7b8001
Colorize imaginary and rational literals 2019-05-26 23:46:14 +09:00
Takashi Kokubun aaf6c678d2
Handle keyword symbol in IRB::Color::SymbolState 2019-05-25 22:32:28 -07:00
Takashi Kokubun 52b09fcee1
Deal with more syntax highlight edge cases
Please refer to the tests again.
2019-05-25 22:29:16 -07:00
Takashi Kokubun 8aba3b7a04
Fix more unintended syntax highlights
See tests for what kind of things are fixed.
2019-05-25 22:07:32 -07:00
Takashi Kokubun 13f58eccda
Always color Symbol as Yellow on IRB::Color
Symbol color was made blue as a workaround because it was hard to
distinguish `foo`s in `:foo` and `def foo; end` (both are :on_ident).
But I wanted to make it yellow like pry.

`:Struct` had the same problem in :on_const. Because the :on_const was
also blue (but underlined and bold), it was not a big issue.

While they're not so problematic since we got a workaround, we also had
a more serious issue for highlighting a symbol like `:"a#{b}c"`.
The first half was considered as Symbol and the last half was considered
as String, because the colorizer did not have a state like a parser.

To approach the last issue, I introduced `IRB::Color::SymbolState` which
is a thin state manager knowing only "the token is Symbol or not". Having
this module magically solves the first two problems as well. So now we
can highlight Symbol as yellow in the perfect manner.
2019-05-25 20:47:33 -07:00
Takashi Kokubun 208ed56e57
Colorize empty embexpr more on IRB::Color 2019-05-25 14:15:08 -07:00
Takashi Kokubun 98be203704
Support some unhandled syntax highlight
Heredoc, %i, :Foo, { 'a': ... }, ...

:'a' is still half-broken.
2019-05-25 08:19:15 -07:00
Takashi Kokubun ada64aa9e7
Clear IRB::Color escape sequence before newline
because otherwise prompt and other things could be polluted.
2019-05-25 07:49:15 -07:00
Takashi Kokubun e2db9f4cc3
Add and use Reline::Unicode.escape_for_print 2019-05-25 07:10:09 -07:00
Takashi Kokubun b83119be9e
Incremental syntax highlight for IRB source lines
Closes: https://github.com/ruby/ruby/pull/2202
2019-05-24 23:54:52 -07:00
NAKAMURA Usaku c5cbabf8a8
Use colorized IRB on Windows without checking `TERM` 2019-05-23 15:33:40 +09:00