Commit graph

352 commits

Author SHA1 Message Date
Takashi Kokubun
70e87d9660
Do not rely on IRB.conf[:MAIN_CONTEXT] before initialize
so that we can colorize binding.irb source lines.
2019-05-30 15:50:21 +09:00
aycabta
55c34b994b Check the end token of heredoc correctly 2019-05-30 15:34:41 +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
aycabta
8d83743170 Use IO.copy_stream 2019-05-29 06:57:47 +09:00
aycabta
a4a682c450 Check RUBY_YES_I_AM_NOT_A_NORMAL_USER env to access RubyVM doc 2019-05-29 06:57:47 +09:00
aycabta
d341bb2857 IRB never show RubyVM's doc 2019-05-29 06:57:47 +09:00
aycabta
d390af3686 Encode completed strings corecctly 2019-05-29 06:54:57 +09:00
aycabta
d5682eb939 Remove unused variable from IRB::InputCompletor 2019-05-28 03:25:47 +09:00
aycabta
5e275dd2af Treat :@1, :@@1, @1, and @@1 correctly to check termination 2019-05-28 03:23:52 +09:00
Kazuki Tsujimoto
b2b5ed1410 Supress duplicated warning 2019-05-28 01:32:07 +09:00
Nobuyoshi Nakada
8a2a5822ca
Colorize error part 2019-05-27 23:08:51 +09:00
Nobuyoshi Nakada
0aa9b003de
context.rb: hide wrapping lines
* lib/irb/context.rb (IRB::Context#evaluate): separate the code
  from wrapping lines to propagate the given exception, not to show
  the wrapping lines when SyntaxError.
2019-05-27 11:05:51 +09:00
aycabta
9840f52c77 Use IRB::InputMethod#eof? to quit 2019-05-27 10:18:09 +09:00
Sutou Kouhei
29c16b30ce Add support for history with Reline backend 2019-05-27 06:32:52 +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
e73a68ebc3 Support op, cvar, iver, gvar and kw that follow on symbeg in IRB 2019-05-27 02:59:21 +09: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
aycabta
0f35c79ad6 Fix number literal regexp of IRB completion 2019-05-27 01:59:17 +09:00
aycabta
e39c950c2b Use correctly RI output in IRB completion 2019-05-27 01:24:12 +09: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
e691b4da5d
Respect --nocolorize on REPL source highlight 2019-05-25 06:31:13 -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
aycabta
7686e33ee4 JSON like label ends by differs from the start
pp Ripper.lex('{ "a": 3 }')
 =>
[[[1, 0], :on_lbrace, "{", EXPR_BEG|EXPR_LABEL],
 [[1, 1], :on_sp, " ", EXPR_BEG|EXPR_LABEL],
 [[1, 2], :on_tstring_beg, "\"", EXPR_BEG|EXPR_LABEL],
 [[1, 3], :on_tstring_content, "a", EXPR_BEG|EXPR_LABEL],
 [[1, 4], :on_label_end, "\":", EXPR_BEG|EXPR_LABEL],
 [[1, 6], :on_sp, " ", EXPR_BEG|EXPR_LABEL],
 [[1, 7], :on_int, "3", EXPR_END],
 [[1, 8], :on_sp, " ", EXPR_END],
 [[1, 9], :on_rbrace, "}", EXPR_END]]
2019-05-25 10:42:57 +09:00
aycabta
559dca509d Show documents when completion 2019-05-25 03:30:01 +09:00
aycabta
260235ce87 Use Reline as Reidline multiline editor in IRB 2019-05-25 02:16:19 +09:00
NAKAMURA Usaku
c5cbabf8a8
Use colorized IRB on Windows without checking TERM 2019-05-23 15:33:40 +09:00
Takashi Kokubun
32ed85f601
Copy config to make IRB::Context#use_colorize? functional
on initialize

This fixes https://github.com/ruby/ruby/pull/2188
2019-05-21 04:32:17 -07:00
aycabta
4613c4bd5c Symbol beginning token may take a constant token 2019-05-21 18:55:31 +09:00
aycabta
fd95ab44c6 IRB should eval and show an error when only . is inputted 2019-05-21 18:37:35 +09:00
aycabta
29c81265c1 Check whether IRB.conf is nil in IRB::WorkSpace#code_around_binding 2019-05-21 09:14:08 +09:00
aycabta
3a9008b984 Add --colorize and --nocolorize options to IRB 2019-05-21 08:57:21 +09:00
aycabta
94b740b249 Use Ripper for IRB
The debug option of IRB is deleted because it's just for IRB's pure Ruby
parser.
2019-04-30 14:40:06 +09:00
Takashi Kokubun
f2d7ba6a74
make sync-default-gems GEM=irb
from e8e79d569e.

This colorizes Range object on IRB inspect.
2019-04-28 21:51:37 +09:00