irb 1.1.0 → 1.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,233 +0,0 @@
1
- # frozen_string_literal: true
2
- require 'reline'
3
- require 'ripper'
4
-
5
- module IRB # :nodoc:
6
- module Color
7
- CLEAR = 0
8
- BOLD = 1
9
- UNDERLINE = 4
10
- REVERSE = 7
11
- RED = 31
12
- GREEN = 32
13
- YELLOW = 33
14
- BLUE = 34
15
- MAGENTA = 35
16
- CYAN = 36
17
-
18
- TOKEN_KEYWORDS = {
19
- on_kw: ['nil', 'self', 'true', 'false', '__FILE__', '__LINE__'],
20
- on_const: ['ENV'],
21
- }
22
- private_constant :TOKEN_KEYWORDS
23
-
24
- # A constant of all-bit 1 to match any Ripper's state in #dispatch_seq
25
- ALL = -1
26
- private_constant :ALL
27
-
28
- begin
29
- # Following pry's colors where possible, but sometimes having a compromise like making
30
- # backtick and regexp as red (string's color, because they're sharing tokens).
31
- TOKEN_SEQ_EXPRS = {
32
- on_CHAR: [[BLUE, BOLD], ALL],
33
- on_backtick: [[RED, BOLD], ALL],
34
- on_comment: [[BLUE, BOLD], ALL],
35
- on_const: [[BLUE, BOLD, UNDERLINE], ALL],
36
- on_embexpr_beg: [[RED], ALL],
37
- on_embexpr_end: [[RED], ALL],
38
- on_embvar: [[RED], ALL],
39
- on_float: [[MAGENTA, BOLD], ALL],
40
- on_gvar: [[GREEN, BOLD], ALL],
41
- on_heredoc_beg: [[RED], ALL],
42
- on_heredoc_end: [[RED], ALL],
43
- on_ident: [[BLUE, BOLD], Ripper::EXPR_ENDFN],
44
- on_imaginary: [[BLUE, BOLD], ALL],
45
- on_int: [[BLUE, BOLD], ALL],
46
- on_kw: [[GREEN], ALL],
47
- on_label: [[MAGENTA], ALL],
48
- on_label_end: [[RED, BOLD], ALL],
49
- on_qsymbols_beg: [[RED, BOLD], ALL],
50
- on_qwords_beg: [[RED, BOLD], ALL],
51
- on_rational: [[BLUE, BOLD], ALL],
52
- on_regexp_beg: [[RED, BOLD], ALL],
53
- on_regexp_end: [[RED, BOLD], ALL],
54
- on_symbeg: [[YELLOW], ALL],
55
- on_symbols_beg: [[RED, BOLD], ALL],
56
- on_tstring_beg: [[RED, BOLD], ALL],
57
- on_tstring_content: [[RED], ALL],
58
- on_tstring_end: [[RED, BOLD], ALL],
59
- on_words_beg: [[RED, BOLD], ALL],
60
- on_parse_error: [[RED, REVERSE], ALL],
61
- compile_error: [[RED, REVERSE], ALL],
62
- }
63
- rescue NameError
64
- # Give up highlighting Ripper-incompatible older Ruby
65
- TOKEN_SEQ_EXPRS = {}
66
- end
67
- private_constant :TOKEN_SEQ_EXPRS
68
-
69
- class << self
70
- def colorable?
71
- $stdout.tty? && supported? && (/mswin|mingw/ =~ RUBY_PLATFORM || (ENV.key?('TERM') && ENV['TERM'] != 'dumb'))
72
- end
73
-
74
- def inspect_colorable?(obj, seen: {}.compare_by_identity)
75
- case obj
76
- when String, Symbol, Regexp, Integer, Float, FalseClass, TrueClass, NilClass
77
- true
78
- when Hash
79
- without_circular_ref(obj, seen: seen) do
80
- obj.all? { |k, v| inspect_colorable?(k, seen: seen) && inspect_colorable?(v, seen: seen) }
81
- end
82
- when Array
83
- without_circular_ref(obj, seen: seen) do
84
- obj.all? { |o| inspect_colorable?(o, seen: seen) }
85
- end
86
- when Range
87
- inspect_colorable?(obj.begin, seen: seen) && inspect_colorable?(obj.end, seen: seen)
88
- when Module
89
- !obj.name.nil?
90
- else
91
- false
92
- end
93
- end
94
-
95
- def clear
96
- return '' unless colorable?
97
- "\e[#{CLEAR}m"
98
- end
99
-
100
- def colorize(text, seq)
101
- return text unless colorable?
102
- seq = seq.map { |s| "\e[#{const_get(s)}m" }.join('')
103
- "#{seq}#{text}#{clear}"
104
- end
105
-
106
- # If `complete` is false (code is incomplete), this does not warn compile_error.
107
- # This option is needed to avoid warning a user when the compile_error is happening
108
- # because the input is not wrong but just incomplete.
109
- def colorize_code(code, complete: true)
110
- return code unless colorable?
111
-
112
- symbol_state = SymbolState.new
113
- colored = +''
114
- length = 0
115
-
116
- scan(code, allow_last_error: !complete) do |token, str, expr|
117
- in_symbol = symbol_state.scan_token(token)
118
- str.each_line do |line|
119
- line = Reline::Unicode.escape_for_print(line)
120
- if seq = dispatch_seq(token, expr, line, in_symbol: in_symbol)
121
- colored << seq.map { |s| "\e[#{s}m" }.join('')
122
- colored << line.sub(/\Z/, clear)
123
- else
124
- colored << line
125
- end
126
- end
127
- length += str.bytesize
128
- end
129
-
130
- # give up colorizing incomplete Ripper tokens
131
- if length != code.bytesize
132
- return Reline::Unicode.escape_for_print(code)
133
- end
134
-
135
- colored
136
- end
137
-
138
- private
139
-
140
- def without_circular_ref(obj, seen:, &block)
141
- return false if seen.key?(obj)
142
- seen[obj] = true
143
- block.call
144
- ensure
145
- seen.delete(obj)
146
- end
147
-
148
- # Ripper::Lexer::Elem#state is supported on Ruby 2.5+
149
- def supported?
150
- return @supported if defined?(@supported)
151
- @supported = Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('2.5.0')
152
- end
153
-
154
- def scan(code, allow_last_error:)
155
- pos = [1, 0]
156
-
157
- verbose, $VERBOSE = $VERBOSE, nil
158
- lexer = Ripper::Lexer.new(code)
159
- if lexer.respond_to?(:scan) # Ruby 2.7+
160
- lexer.scan.each do |elem|
161
- str = elem.tok
162
- next if allow_last_error and /meets end of file|unexpected end-of-input/ =~ elem.message
163
- next if ([elem.pos[0], elem.pos[1] + str.bytesize] <=> pos) <= 0
164
-
165
- str.each_line do |line|
166
- if line.end_with?("\n")
167
- pos[0] += 1
168
- pos[1] = 0
169
- else
170
- pos[1] += line.bytesize
171
- end
172
- end
173
-
174
- yield(elem.event, str, elem.state)
175
- end
176
- else
177
- lexer.parse.each do |elem|
178
- yield(elem.event, elem.tok, elem.state)
179
- end
180
- end
181
- $VERBOSE = verbose
182
- end
183
-
184
- def dispatch_seq(token, expr, str, in_symbol:)
185
- if token == :on_parse_error or token == :compile_error
186
- TOKEN_SEQ_EXPRS[token][0]
187
- elsif in_symbol
188
- [YELLOW]
189
- elsif TOKEN_KEYWORDS.fetch(token, []).include?(str)
190
- [CYAN, BOLD]
191
- elsif (seq, exprs = TOKEN_SEQ_EXPRS[token]; (expr & (exprs || 0)) != 0)
192
- seq
193
- else
194
- nil
195
- end
196
- end
197
- end
198
-
199
- # A class to manage a state to know whether the current token is for Symbol or not.
200
- class SymbolState
201
- def initialize
202
- # Push `true` to detect Symbol. `false` to increase the nest level for non-Symbol.
203
- @stack = []
204
- end
205
-
206
- # Return true if the token is a part of Symbol.
207
- def scan_token(token)
208
- prev_state = @stack.last
209
- case token
210
- when :on_symbeg, :on_symbols_beg, :on_qsymbols_beg
211
- @stack << true
212
- when :on_ident, :on_op, :on_const, :on_ivar, :on_cvar, :on_gvar, :on_kw
213
- if @stack.last # Pop only when it's Symbol
214
- @stack.pop
215
- return prev_state
216
- end
217
- when :on_tstring_beg
218
- @stack << false
219
- when :on_embexpr_beg
220
- @stack << false
221
- return prev_state
222
- when :on_tstring_end # :on_tstring_end may close Symbol
223
- @stack.pop
224
- return prev_state
225
- when :on_embexpr_end
226
- @stack.pop
227
- end
228
- @stack.last
229
- end
230
- end
231
- private_constant :SymbolState
232
- end
233
- end
@@ -1,38 +0,0 @@
1
-
2
- -+smJYYN?mm-
3
- HB"BBYT TQg NggT
4
- 9Q+g Nm,T 8g NJW
5
- YS+ N2NJ"Sg N?
6
- BQg #( gT Nggggk J
7
- 5j NJ NJ NNge
8
- #Q #JJ NgT N(
9
- @j bj mT J
10
- Bj @/d NJ (
11
- #q #(( NgT #J
12
- 5d #(t mT $d
13
- #q @(@J NJB;
14
- @( 5d ? HHH H HQmgggggggmN qD
15
- 5d #uN 2QdH E O
16
- 5 5JSd Nd NJH @d j
17
- Fd @J4d s NQH #d (
18
- #( #o6d Nd NgH #d #d
19
- 4 B&Od v NgT #d F
20
- #( 9JGd NH NgUd F
21
- #d #GJQ d NP $
22
- #J #U+#Q N Q # j
23
- j /W BQ+ BQ d NJ NJ
24
- - NjJH HBIjTQggPJQgW N W k #J
25
- #J b HYWgggN j s Nag d NN b #d
26
- #J 5- D s Ngg N d Nd F
27
- Fd BKH2 #+ s NNgg J Q J ]
28
- F H @ J N y K(d P I
29
- F4 E N? #d y #Q NJ E j
30
- F W Nd q m Bg NxW N(H-
31
- F d b @ m Hd gW vKJ
32
- NJ d K d s Bg aT FDd
33
- b # d N m BQ mV N>
34
- e5 Nd #d NggggggQWH HHHH NJ -
35
- m7 NW H N HSVO1z=?11-
36
- NgTH bB kH WBHWWHBHWmQgg&gggggNNN
37
- NNggggggNN
38
-
data/man/irb.1 DELETED
@@ -1,207 +0,0 @@
1
- .\"Ruby is copyrighted by Yukihiro Matsumoto <matz@netlab.jp>.
2
- .Dd August 11, 2019
3
- .Dt IRB \&1 "Ruby Programmer's Reference Guide"
4
- .Os UNIX
5
- .Sh NAME
6
- .Nm irb
7
- .Nd Interactive Ruby Shell
8
- .Sh SYNOPSIS
9
- .Nm
10
- .Op Fl -version
11
- .Op Fl dfUw
12
- .Op Fl I Ar directory
13
- .Op Fl r Ar library
14
- .Op Fl E Ar external Ns Op : Ns Ar internal
15
- .Op Fl W Ns Op Ar level
16
- .Op Fl - Ns Oo no Oc Ns inspect
17
- .Op Fl - Ns Oo no Oc Ns multiline
18
- .Op Fl - Ns Oo no Oc Ns singleline
19
- .Op Fl - Ns Oo no Oc Ns echo
20
- .Op Fl - Ns Oo no Oc Ns colorize
21
- .Op Fl - Ns Oo no Oc Ns verbose
22
- .Op Fl -prompt Ar mode
23
- .Op Fl -prompt-mode Ar mode
24
- .Op Fl -inf-ruby-mode
25
- .Op Fl -simple-prompt
26
- .Op Fl -noprompt
27
- .Op Fl -tracer
28
- .Op Fl -back-trace-limit Ar n
29
- .Op Fl -
30
- .Op program_file
31
- .Op argument ...
32
- .Pp
33
- .Sh DESCRIPTION
34
- .Nm
35
- is the REPL(read-eval-print loop) environment for Ruby programs.
36
- .Pp
37
- .Sh OPTIONS
38
- .Bl -tag -width "1234567890123" -compact
39
- .Pp
40
- .It Fl -version
41
- Prints the version of
42
- .Nm .
43
- .Pp
44
- .It Fl E Ar external Ns Op : Ns Ar internal
45
- .It Fl -encoding Ar external Ns Op : Ns Ar internal
46
- Same as `ruby -E' .
47
- Specifies the default value(s) for external encodings and internal encoding. Values should be separated with colon (:).
48
- .Pp
49
- You can omit the one for internal encodings, then the value
50
- .Pf ( Li "Encoding.default_internal" ) will be nil.
51
- .Pp
52
- .It Fl I Ar path
53
- Same as `ruby -I' .
54
- Specifies
55
- .Li $LOAD_PATH
56
- directory
57
- .Pp
58
- .It Fl U
59
- Same as `ruby -U' .
60
- Sets the default value for internal encodings
61
- .Pf ( Li "Encoding.default_internal" ) to UTF-8.
62
- .Pp
63
- .It Fl d
64
- Same as `ruby -d' .
65
- Sets
66
- .Li $DEBUG
67
- to true.
68
- .Pp
69
- .It Fl f
70
- Suppresses read of
71
- .Pa ~/.irbrc .
72
- .Pp
73
- .It Fl w
74
- Same as `ruby -w' .
75
- .Pp
76
- .Pp
77
- .It Fl W
78
- Same as `ruby -W' .
79
- .Pp
80
- .It Fl h
81
- .It Fl -help
82
- Prints a summary of the options.
83
- .Pp
84
- .It Fl r Ar library
85
- Same as `ruby -r'.
86
- Causes irb to load the library using require.
87
- .Pp
88
- .It Fl -inspect
89
- Uses `inspect' for output (default except for bc mode)
90
- .Pp
91
- .It Fl -noinspect
92
- Doesn't use inspect for output
93
- .Pp
94
- .It Fl -multiline
95
- Uses multiline editor module.
96
- .Pp
97
- .It Fl -nomultiline
98
- Doesn't use multiline editor module.
99
- .Pp
100
- .It Fl -singleline
101
- Uses singleline editor module.
102
- .Pp
103
- .It Fl -nosingleline
104
- Doesn't use singleline editor module.
105
- .Pp
106
- .Pp
107
- .It Fl -echo
108
- Show result(default).
109
- .Pp
110
- .It Fl -noecho
111
- Don't show result.
112
- .Pp
113
- .Pp
114
- .It Fl -colorize
115
- Use colorization.
116
- .Pp
117
- .It Fl -nocolorize
118
- Don't use colorization.
119
- .Pp
120
- .Pp
121
- .It Fl -verbose
122
- Show details.
123
- .Pp
124
- .It Fl -noverbose
125
- Don't show details.
126
- .Pp
127
- .It Fl -prompt Ar mode
128
- .It Fl -prompt-mode Ar mode
129
- Switch prompt mode. Pre-defined prompt modes are
130
- `default', `simple', `xmp' and `inf-ruby'.
131
- .Pp
132
- .It Fl -inf-ruby-mode
133
- Uses prompt appropriate for inf-ruby-mode on emacs.
134
- Suppresses --multiline and --singleline.
135
- .Pp
136
- .It Fl -simple-prompt
137
- Makes prompts simple.
138
- .Pp
139
- .It Fl -noprompt
140
- No prompt mode.
141
- .Pp
142
- .It Fl -tracer
143
- Displays trace for each execution of commands.
144
- .Pp
145
- .It Fl -back-trace-limit Ar n
146
- Displays backtrace top
147
- .Ar n
148
- and tail
149
- .Ar n Ns .
150
- The default value is 16.
151
- .El
152
- .Pp
153
- .Sh ENVIRONMENT
154
- .Bl -tag -compact
155
- .It Ev IRBRC
156
- .Pp
157
- .El
158
- .Pp
159
- Also
160
- .Nm
161
- depends on same variables as
162
- .Xr ruby 1 .
163
- .Pp
164
- .Sh FILES
165
- .Bl -tag -compact
166
- .It Pa ~/.irbrc
167
- Personal irb initialization.
168
- .Pp
169
- .El
170
- .Pp
171
- .Sh EXAMPLES
172
- .Dl % irb
173
- .Dl irb(main):001:0> Ic 1 + 1
174
- .Dl 2
175
- .Dl irb(main):002:0> Ic def t(x)
176
- .Dl irb(main):003:1> Ic x + 1
177
- .Dl irb(main):004:1> Ic end
178
- .Dl => :t
179
- .Dl irb(main):005:0> Ic t(3)
180
- .Dl => 4
181
- .Dl irb(main):006:0> Ic if t(3) == 4
182
- .Dl irb(main):007:1> Ic p :ok
183
- .Dl irb(main):008:1> Ic end
184
- .Dl :ok
185
- .Dl => :ok
186
- .Dl irb(main):009:0> Ic quit
187
- .Dl %
188
- .Pp
189
- .Sh SEE ALSO
190
- .Xr ruby 1 .
191
- .Pp
192
- .Sh REPORTING BUGS
193
- .Bl -bullet
194
- .It
195
- Security vulnerabilities should be reported via an email to
196
- .Mt security@ruby-lang.org .
197
- Reported problems will be published after being fixed.
198
- .Pp
199
- .It
200
- Other bugs and feature requests can be reported via the
201
- Ruby Issue Tracking System
202
- .Pq Lk https://bugs.ruby-lang.org/ .
203
- Do not report security vulnerabilities
204
- via this system because it publishes the vulnerabilities immediately.
205
- .El
206
- .Sh AUTHORS
207
- Written by Keiju ISHITSUKA.