irb 1.1.0 → 1.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,267 @@
1
+ # frozen_string_literal: false
2
+ #
3
+ # irb/ruby-token.rb - ruby tokens
4
+ # $Release Version: 0.9.6$
5
+ # $Revision$
6
+ # by Keiju ISHITSUKA(keiju@ruby-lang.org)
7
+ #
8
+ # --
9
+ #
10
+ #
11
+ #
12
+ # :stopdoc:
13
+ module RubyToken
14
+ EXPR_BEG = :EXPR_BEG
15
+ EXPR_MID = :EXPR_MID
16
+ EXPR_END = :EXPR_END
17
+ EXPR_ARG = :EXPR_ARG
18
+ EXPR_FNAME = :EXPR_FNAME
19
+ EXPR_DOT = :EXPR_DOT
20
+ EXPR_CLASS = :EXPR_CLASS
21
+
22
+ class Token
23
+ def initialize(seek, line_no, char_no)
24
+ @seek = seek
25
+ @line_no = line_no
26
+ @char_no = char_no
27
+ end
28
+ attr_reader :seek, :line_no, :char_no
29
+ end
30
+
31
+ class TkNode < Token
32
+ def initialize(seek, line_no, char_no)
33
+ super
34
+ end
35
+ attr_reader :node
36
+ end
37
+
38
+ class TkId < Token
39
+ def initialize(seek, line_no, char_no, name)
40
+ super(seek, line_no, char_no)
41
+ @name = name
42
+ end
43
+ attr_reader :name
44
+ end
45
+
46
+ class TkVal < Token
47
+ def initialize(seek, line_no, char_no, value = nil)
48
+ super(seek, line_no, char_no)
49
+ @value = value
50
+ end
51
+ attr_reader :value
52
+ end
53
+
54
+ class TkOp < Token
55
+ attr_accessor :name
56
+ end
57
+
58
+ class TkOPASGN < TkOp
59
+ def initialize(seek, line_no, char_no, op)
60
+ super(seek, line_no, char_no)
61
+ op = TkReading2Token[op][0] unless op.kind_of?(Symbol)
62
+ @op = op
63
+ end
64
+ attr_reader :op
65
+ end
66
+
67
+ class TkUnknownChar < Token
68
+ def initialize(seek, line_no, char_no, id)
69
+ super(seek, line_no, char_no)
70
+ @name = name
71
+ end
72
+ attr_reader :name
73
+ end
74
+
75
+ class TkError < Token
76
+ end
77
+
78
+ def Token(token, value = nil)
79
+ case token
80
+ when String
81
+ if (tk = TkReading2Token[token]).nil?
82
+ IRB.fail TkReading2TokenNoKey, token
83
+ end
84
+ tk = Token(tk[0], value)
85
+ if tk.kind_of?(TkOp)
86
+ tk.name = token
87
+ end
88
+ return tk
89
+ when Symbol
90
+ if (tk = TkSymbol2Token[token]).nil?
91
+ IRB.fail TkSymbol2TokenNoKey, token
92
+ end
93
+ return Token(tk[0], value)
94
+ else
95
+ if (token.ancestors & [TkId, TkVal, TkOPASGN, TkUnknownChar]).empty?
96
+ token.new(@prev_seek, @prev_line_no, @prev_char_no)
97
+ else
98
+ token.new(@prev_seek, @prev_line_no, @prev_char_no, value)
99
+ end
100
+ end
101
+ end
102
+
103
+ TokenDefinitions = [
104
+ [:TkCLASS, TkId, "class", EXPR_CLASS],
105
+ [:TkMODULE, TkId, "module", EXPR_BEG],
106
+ [:TkDEF, TkId, "def", EXPR_FNAME],
107
+ [:TkUNDEF, TkId, "undef", EXPR_FNAME],
108
+ [:TkBEGIN, TkId, "begin", EXPR_BEG],
109
+ [:TkRESCUE, TkId, "rescue", EXPR_MID],
110
+ [:TkENSURE, TkId, "ensure", EXPR_BEG],
111
+ [:TkEND, TkId, "end", EXPR_END],
112
+ [:TkIF, TkId, "if", EXPR_BEG, :TkIF_MOD],
113
+ [:TkUNLESS, TkId, "unless", EXPR_BEG, :TkUNLESS_MOD],
114
+ [:TkTHEN, TkId, "then", EXPR_BEG],
115
+ [:TkELSIF, TkId, "elsif", EXPR_BEG],
116
+ [:TkELSE, TkId, "else", EXPR_BEG],
117
+ [:TkCASE, TkId, "case", EXPR_BEG],
118
+ [:TkWHEN, TkId, "when", EXPR_BEG],
119
+ [:TkWHILE, TkId, "while", EXPR_BEG, :TkWHILE_MOD],
120
+ [:TkUNTIL, TkId, "until", EXPR_BEG, :TkUNTIL_MOD],
121
+ [:TkFOR, TkId, "for", EXPR_BEG],
122
+ [:TkBREAK, TkId, "break", EXPR_END],
123
+ [:TkNEXT, TkId, "next", EXPR_END],
124
+ [:TkREDO, TkId, "redo", EXPR_END],
125
+ [:TkRETRY, TkId, "retry", EXPR_END],
126
+ [:TkIN, TkId, "in", EXPR_BEG],
127
+ [:TkDO, TkId, "do", EXPR_BEG],
128
+ [:TkRETURN, TkId, "return", EXPR_MID],
129
+ [:TkYIELD, TkId, "yield", EXPR_END],
130
+ [:TkSUPER, TkId, "super", EXPR_END],
131
+ [:TkSELF, TkId, "self", EXPR_END],
132
+ [:TkNIL, TkId, "nil", EXPR_END],
133
+ [:TkTRUE, TkId, "true", EXPR_END],
134
+ [:TkFALSE, TkId, "false", EXPR_END],
135
+ [:TkAND, TkId, "and", EXPR_BEG],
136
+ [:TkOR, TkId, "or", EXPR_BEG],
137
+ [:TkNOT, TkId, "not", EXPR_BEG],
138
+ [:TkIF_MOD, TkId],
139
+ [:TkUNLESS_MOD, TkId],
140
+ [:TkWHILE_MOD, TkId],
141
+ [:TkUNTIL_MOD, TkId],
142
+ [:TkALIAS, TkId, "alias", EXPR_FNAME],
143
+ [:TkDEFINED, TkId, "defined?", EXPR_END],
144
+ [:TklBEGIN, TkId, "BEGIN", EXPR_END],
145
+ [:TklEND, TkId, "END", EXPR_END],
146
+ [:Tk__LINE__, TkId, "__LINE__", EXPR_END],
147
+ [:Tk__FILE__, TkId, "__FILE__", EXPR_END],
148
+
149
+ [:TkIDENTIFIER, TkId],
150
+ [:TkFID, TkId],
151
+ [:TkGVAR, TkId],
152
+ [:TkCVAR, TkId],
153
+ [:TkIVAR, TkId],
154
+ [:TkCONSTANT, TkId],
155
+
156
+ [:TkINTEGER, TkVal],
157
+ [:TkFLOAT, TkVal],
158
+ [:TkSTRING, TkVal],
159
+ [:TkXSTRING, TkVal],
160
+ [:TkREGEXP, TkVal],
161
+ [:TkSYMBOL, TkVal],
162
+
163
+ [:TkDSTRING, TkNode],
164
+ [:TkDXSTRING, TkNode],
165
+ [:TkDREGEXP, TkNode],
166
+ [:TkNTH_REF, TkNode],
167
+ [:TkBACK_REF, TkNode],
168
+
169
+ [:TkUPLUS, TkOp, "+@"],
170
+ [:TkUMINUS, TkOp, "-@"],
171
+ [:TkPOW, TkOp, "**"],
172
+ [:TkCMP, TkOp, "<=>"],
173
+ [:TkEQ, TkOp, "=="],
174
+ [:TkEQQ, TkOp, "==="],
175
+ [:TkNEQ, TkOp, "!="],
176
+ [:TkGEQ, TkOp, ">="],
177
+ [:TkLEQ, TkOp, "<="],
178
+ [:TkANDOP, TkOp, "&&"],
179
+ [:TkOROP, TkOp, "||"],
180
+ [:TkMATCH, TkOp, "=~"],
181
+ [:TkNMATCH, TkOp, "!~"],
182
+ [:TkDOT2, TkOp, ".."],
183
+ [:TkDOT3, TkOp, "..."],
184
+ [:TkAREF, TkOp, "[]"],
185
+ [:TkASET, TkOp, "[]="],
186
+ [:TkLSHFT, TkOp, "<<"],
187
+ [:TkRSHFT, TkOp, ">>"],
188
+ [:TkCOLON2, TkOp],
189
+ [:TkCOLON3, TkOp],
190
+ [:TkASSOC, TkOp, "=>"],
191
+ [:TkQUESTION, TkOp, "?"], #?
192
+ [:TkCOLON, TkOp, ":"], #:
193
+
194
+ [:TkfLPAREN], # func( #
195
+ [:TkfLBRACK], # func[ #
196
+ [:TkfLBRACE], # func{ #
197
+ [:TkSTAR], # *arg
198
+ [:TkAMPER], # &arg #
199
+ [:TkSYMBEG], # :SYMBOL
200
+
201
+ [:TkGT, TkOp, ">"],
202
+ [:TkLT, TkOp, "<"],
203
+ [:TkPLUS, TkOp, "+"],
204
+ [:TkMINUS, TkOp, "-"],
205
+ [:TkMULT, TkOp, "*"],
206
+ [:TkDIV, TkOp, "/"],
207
+ [:TkMOD, TkOp, "%"],
208
+ [:TkBITOR, TkOp, "|"],
209
+ [:TkBITXOR, TkOp, "^"],
210
+ [:TkBITAND, TkOp, "&"],
211
+ [:TkBITNOT, TkOp, "~"],
212
+ [:TkNOTOP, TkOp, "!"],
213
+
214
+ [:TkBACKQUOTE, TkOp, "`"],
215
+
216
+ [:TkASSIGN, Token, "="],
217
+ [:TkDOT, Token, "."],
218
+ [:TkLPAREN, Token, "("], #(exp)
219
+ [:TkLBRACK, Token, "["], #[arry]
220
+ [:TkLBRACE, Token, "{"], #{hash}
221
+ [:TkRPAREN, Token, ")"],
222
+ [:TkRBRACK, Token, "]"],
223
+ [:TkRBRACE, Token, "}"],
224
+ [:TkCOMMA, Token, ","],
225
+ [:TkSEMICOLON, Token, ";"],
226
+
227
+ [:TkCOMMENT],
228
+ [:TkRD_COMMENT],
229
+ [:TkSPACE],
230
+ [:TkNL],
231
+ [:TkEND_OF_SCRIPT],
232
+
233
+ [:TkBACKSLASH, TkUnknownChar, "\\"],
234
+ [:TkAT, TkUnknownChar, "@"],
235
+ [:TkDOLLAR, TkUnknownChar, "$"],
236
+ ]
237
+
238
+ # {reading => token_class}
239
+ # {reading => [token_class, *opt]}
240
+ TkReading2Token = {}
241
+ TkSymbol2Token = {}
242
+
243
+ def RubyToken.def_token(token_n, super_token = Token, reading = nil, *opts)
244
+ token_n = token_n.id2name if token_n.kind_of?(Symbol)
245
+ if RubyToken.const_defined?(token_n)
246
+ IRB.fail AlreadyDefinedToken, token_n
247
+ end
248
+ token_c = eval("class #{token_n} < #{super_token}; end; #{token_n}")
249
+
250
+ if reading
251
+ if TkReading2Token[reading]
252
+ IRB.fail TkReading2TokenDuplicateError, token_n, reading
253
+ end
254
+ if opts.empty?
255
+ TkReading2Token[reading] = [token_c]
256
+ else
257
+ TkReading2Token[reading] = [token_c].concat(opts)
258
+ end
259
+ end
260
+ TkSymbol2Token[token_n.intern] = token_c
261
+ end
262
+
263
+ for defs in TokenDefinitions
264
+ def_token(*defs)
265
+ end
266
+ end
267
+ # :startdoc:
@@ -11,7 +11,7 @@
11
11
  #
12
12
 
13
13
  module IRB # :nodoc:
14
- VERSION = "1.1.0"
14
+ VERSION = "1.1.1"
15
15
  @RELEASE_VERSION = VERSION
16
- @LAST_UPDATE_DATE = "2019-11-21"
16
+ @LAST_UPDATE_DATE = "2018-12-18"
17
17
  end
@@ -9,9 +9,6 @@
9
9
  #
10
10
  #
11
11
  #
12
-
13
- require "delegate"
14
-
15
12
  module IRB # :nodoc:
16
13
  class WorkSpace
17
14
  # Creates a new workspace.
@@ -52,21 +49,17 @@ EOF
52
49
  @binding = BINDING_QUEUE.pop
53
50
 
54
51
  when 3 # binding in function on TOPLEVEL_BINDING(default)
55
- @binding = eval("self.class.send(:remove_method, :irb_binding) if defined?(irb_binding); private; def irb_binding; binding; end; irb_binding",
52
+ @binding = eval("def irb_binding; private; binding; end; irb_binding",
56
53
  TOPLEVEL_BINDING,
57
54
  __FILE__,
58
55
  __LINE__ - 3)
59
56
  end
60
57
  end
61
-
62
58
  if main.empty?
63
59
  @main = eval("self", @binding)
64
60
  else
65
61
  @main = main[0]
66
- end
67
- IRB.conf[:__MAIN__] = @main
68
-
69
- unless main.empty?
62
+ IRB.conf[:__MAIN__] = @main
70
63
  case @main
71
64
  when Module
72
65
  @binding = eval("IRB.conf[:__MAIN__].module_eval('binding', __FILE__, __LINE__)", @binding, __FILE__, __LINE__)
@@ -78,28 +71,6 @@ EOF
78
71
  end
79
72
  end
80
73
  end
81
-
82
- case @main
83
- when Object
84
- use_delegator = @main.frozen?
85
- else
86
- use_delegator = true
87
- end
88
-
89
- if use_delegator
90
- @main = SimpleDelegator.new(@main)
91
- IRB.conf[:__MAIN__] = @main
92
- @main.singleton_class.class_eval do
93
- private
94
- define_method(:exit) do |*a, &b|
95
- # Do nothing, will be overridden
96
- end
97
- define_method(:binding, Kernel.instance_method(:binding))
98
- define_method(:local_variables, Kernel.instance_method(:local_variables))
99
- end
100
- @binding = eval("IRB.conf[:__MAIN__].instance_eval('binding', __FILE__, __LINE__)", @binding, *@binding.source_location)
101
- end
102
-
103
74
  @binding.local_variable_set(:_, nil)
104
75
  end
105
76
 
@@ -124,55 +95,46 @@ EOF
124
95
 
125
96
  # error message manipulator
126
97
  def filter_backtrace(bt)
127
- return nil if bt =~ /irb\/.*\.rb/
128
- return nil if bt =~ /irb\.rb/
129
98
  case IRB.conf[:CONTEXT_MODE]
99
+ when 0
100
+ return nil if bt =~ /\(irb_local_binding\)/
130
101
  when 1
131
- return nil if bt =~ %r!/tmp/irb-binding!
102
+ if(bt =~ %r!/tmp/irb-binding! or
103
+ bt =~ %r!irb/.*\.rb! or
104
+ bt =~ /irb\.rb/)
105
+ return nil
106
+ end
107
+ when 2
108
+ return nil if bt =~ /irb\/.*\.rb/
109
+ return nil if bt =~ /irb\.rb/
132
110
  when 3
111
+ return nil if bt =~ /irb\/.*\.rb/
112
+ return nil if bt =~ /irb\.rb/
133
113
  bt = bt.sub(/:\s*in `irb_binding'/, '')
134
114
  end
135
115
  bt
136
116
  end
137
117
 
138
118
  def code_around_binding
139
- if @binding.respond_to?(:source_location)
140
- file, pos = @binding.source_location
141
- else
142
- file, pos = @binding.eval('[__FILE__, __LINE__]')
143
- end
119
+ file, pos = @binding.source_location
144
120
 
145
- if defined?(::SCRIPT_LINES__[file]) && lines = ::SCRIPT_LINES__[file]
146
- code = ::SCRIPT_LINES__[file].join('')
147
- else
121
+ unless defined?(::SCRIPT_LINES__[file]) && lines = ::SCRIPT_LINES__[file]
148
122
  begin
149
- code = File.read(file)
123
+ lines = File.readlines(file)
150
124
  rescue SystemCallError
151
125
  return
152
126
  end
153
127
  end
154
-
155
- # NOT using #use_colorize? of IRB.conf[:MAIN_CONTEXT] because this method may be called before IRB::Irb#run
156
- use_colorize = IRB.conf.fetch(:USE_COLORIZE, true)
157
- if use_colorize
158
- lines = Color.colorize_code(code).lines
159
- else
160
- lines = code.lines
161
- end
162
128
  pos -= 1
163
129
 
164
130
  start_pos = [pos - 5, 0].max
165
131
  end_pos = [pos + 5, lines.size - 1].min
166
132
 
167
- if use_colorize
168
- fmt = " %2s #{Color.colorize("%#{end_pos.to_s.length}d", [:BLUE, :BOLD])}: %s"
169
- else
170
- fmt = " %2s %#{end_pos.to_s.length}d: %s"
171
- end
133
+ fmt = " %2s %#{end_pos.to_s.length}d: %s"
172
134
  body = (start_pos..end_pos).map do |current_pos|
173
135
  sprintf(fmt, pos == current_pos ? '=>' : '', current_pos + 1, lines[current_pos])
174
136
  end.join("")
175
- "\nFrom: #{file} @ line #{pos + 1} :\n\n#{body}#{Color.clear}\n"
137
+ "\nFrom: #{file} @ line #{pos + 1} :\n\n#{body}\n"
176
138
  end
177
139
 
178
140
  def IRB.delete_caller
metadata CHANGED
@@ -1,29 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: irb
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Keiju ISHITSUKA
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-11-20 00:00:00.000000000 Z
11
+ date: 2019-12-07 00:00:00.000000000 Z
12
12
  dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: reline
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - ">="
18
- - !ruby/object:Gem::Version
19
- version: 0.0.1
20
- type: :runtime
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - ">="
25
- - !ruby/object:Gem::Version
26
- version: 0.0.1
27
13
  - !ruby/object:Gem::Dependency
28
14
  name: bundler
29
15
  requirement: !ruby/object:Gem::Requirement
@@ -60,14 +46,14 @@ executables:
60
46
  extensions: []
61
47
  extra_rdoc_files: []
62
48
  files:
49
+ - ".gitignore"
50
+ - ".travis.yml"
63
51
  - Gemfile
64
52
  - LICENSE.txt
65
53
  - README.md
66
54
  - Rakefile
67
55
  - bin/console
68
56
  - bin/setup
69
- - doc/irb/irb-tools.rd.ja
70
- - doc/irb/irb.rd.ja
71
57
  - exe/irb
72
58
  - irb.gemspec
73
59
  - lib/irb.rb
@@ -78,7 +64,6 @@ files:
78
64
  - lib/irb/cmd/nop.rb
79
65
  - lib/irb/cmd/pushws.rb
80
66
  - lib/irb/cmd/subirb.rb
81
- - lib/irb/color.rb
82
67
  - lib/irb/completion.rb
83
68
  - lib/irb/context.rb
84
69
  - lib/irb/ext/change-ws.rb
@@ -106,14 +91,13 @@ files:
106
91
  - lib/irb/notifier.rb
107
92
  - lib/irb/output-method.rb
108
93
  - lib/irb/ruby-lex.rb
109
- - lib/irb/ruby_logo.aa
94
+ - lib/irb/ruby-token.rb
110
95
  - lib/irb/slex.rb
111
96
  - lib/irb/src_encoding.rb
112
97
  - lib/irb/version.rb
113
98
  - lib/irb/workspace.rb
114
99
  - lib/irb/ws-for-case-2.rb
115
100
  - lib/irb/xmp.rb
116
- - man/irb.1
117
101
  homepage: https://github.com/ruby/irb
118
102
  licenses:
119
103
  - BSD-2-Clause
@@ -126,7 +110,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
126
110
  requirements:
127
111
  - - ">="
128
112
  - !ruby/object:Gem::Version
129
- version: '2.4'
113
+ version: '0'
130
114
  required_rubygems_version: !ruby/object:Gem::Requirement
131
115
  requirements:
132
116
  - - ">="