eturem 0.1.0 → 0.2.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b90412ed6406c24b2fa9ba675d7650ff9870b936
4
- data.tar.gz: 7b2572ea2cb36ce486e5c372ea702aa18f3f1a76
3
+ metadata.gz: a64814fe6cc81e8dc3d83a2be9b81e31fc4cdc60
4
+ data.tar.gz: 28129a9bf1e68921a7f603a330edbf38585f3859
5
5
  SHA512:
6
- metadata.gz: 6de0d89d9107da3e802477bec66f902acbd7ad8ddc252ad9abb154cb830356fc5defe2927902ff1411bcd0e00630dfc37d83e47331112d777c5bc661558f8c32
7
- data.tar.gz: 9a957f69850f9c9226582db4be79dcf14d7a9960e8a64b772778632a5c90bf81e74b408b918bf6112d4adf6f489fabf17139dc78bcc90fd275d019a9b787535e
6
+ metadata.gz: 6d4f440e6861f060bdcd0e45eafd6c7bead5b37f37c7bd93b2ba36a96204ca4fdd1de4c9aaddee665fb82fed0f676f7aa4ef6f6a24a1e904edd29329246f8c2b
7
+ data.tar.gz: 79c53579d45fc7bcec00f4a5e6579f2d62f0b3f2479356354c504baa101af3310843b70d755cf6be7bd4be13245039e8df6474df0512a1112fde4c77b34d1d20
@@ -1,11 +1,35 @@
1
- require "eturem/base"
2
- require "eturem/version"
1
+ enable = true
2
+ lang = "en"
3
+ output_backtrace = true
4
+ output_original = true
5
+ output_script = true
6
+ max_backtrace = 16
7
+ before_line_num = 2
8
+ after_line_num = 2
3
9
 
4
- begin
5
- load $0
6
- rescue Exception => exception
7
- exit if exception.is_a? SystemExit
8
- Eturem.output_error(exception, File.absolute_path(__FILE__))
10
+ config_file = File.join(Dir.home, ".eturem")
11
+ if File.exist?(config_file)
12
+ config = File.read(config_file)
13
+ enable = false if config.match(/^enable\s*\:\s*false/i)
14
+ lang = Regexp.last_match(:lang) if config.match(/^lang\s*\:\s*(?<lang>\S+)/i)
15
+ output_backtrace = false if config.match(/^output_backtrace\s*\:\s*false/i)
16
+ output_original = false if config.match( /^output_original\s*\:\s*false/i)
17
+ output_script = false if config.match( /^output_script\s*\:\s*false/i)
18
+ max_backtrace = Regexp.last_match(:num).to_i if config.match( /^max_backtrace\s*\:\s*(?<num>\d+)/i)
19
+ before_line_num = Regexp.last_match(:num).to_i if config.match(/^before_line_num\s*\:\s*(?<num>\d+)/i)
20
+ after_line_num = Regexp.last_match(:num).to_i if config.match( /^after_line_num\s*\:\s*(?<num>\d+)/i)
9
21
  end
22
+ require "eturem/#{lang}" if enable && !defined?(Eturem)
10
23
 
11
- exit
24
+ if defined? Eturem
25
+ Eturem.eturem_class.output_backtrace = output_backtrace
26
+ Eturem.eturem_class.output_original = output_original
27
+ Eturem.eturem_class.output_script = output_script
28
+ Eturem.eturem_class.max_backtrace = max_backtrace
29
+ Eturem.eturem_class.before_line_num = before_line_num
30
+ Eturem.eturem_class.after_line_num = after_line_num
31
+
32
+ exception = Eturem.load($0)
33
+ exception.output_error if exception
34
+ exit
35
+ end
@@ -1,197 +1,270 @@
1
+ require "eturem/version"
2
+
1
3
  module Eturem
2
- def self.set_eturem_class(klass)
4
+ def self.eturem_class
5
+ @eturem_class
6
+ end
7
+
8
+ def self.eturem_class=(klass)
3
9
  @eturem_class = klass
4
10
  end
5
11
 
6
- def self.output_error(exception, eturem_path)
7
- @eturem_class.new(exception, eturem_path).output_error
12
+ def self.load(file)
13
+ begin
14
+ Kernel.load file
15
+ rescue Exception => exception
16
+ return @eturem_class.new(exception) unless exception.is_a? SystemExit
17
+ end
18
+ return nil
19
+ end
20
+
21
+ def self.eval(expr, bind = nil, fname = "(eval)", lineno = 1)
22
+ begin
23
+ bind ? Kernel.eval(expr, bind, fname, lineno) : Kernel.eval(expr)
24
+ rescue Exception => exception
25
+ return @eturem_class.new(exception) unless exception.is_a? SystemExit
26
+ end
27
+ return nil
8
28
  end
9
29
 
10
30
  class Base
11
- def initialize(exception, eturem_path)
31
+ attr_reader :exception
32
+
33
+ @@output_backtrace = true
34
+ @@output_original = true
35
+ @@output_script = true
36
+ @@max_backtrace = 16
37
+ @@before_line_num = 2
38
+ @@after_line_num = 2
39
+
40
+ @inspect_methods = {}
41
+
42
+ def self.inspect_methods
43
+ return @inspect_methods
44
+ end
45
+
46
+ def self.output_backtrace=(value)
47
+ @@output_backtrace = value
48
+ end
49
+
50
+ def self.output_original=(value)
51
+ @@output_original = value
52
+ end
53
+
54
+ def self.output_script=(value)
55
+ @@output_script = value
56
+ end
57
+
58
+ def self.max_backtrace=(value)
59
+ @@max_backtrace = value
60
+ end
61
+
62
+ def self.before_line_num=(value)
63
+ @@before_line_num = value
64
+ end
65
+
66
+ def self.after_line_num=(value)
67
+ @@after_line_num = value
68
+ end
69
+
70
+ # prepare
71
+ def initialize(exception)
12
72
  @exception = exception
13
73
  @exception_s = exception.to_s
14
- @eturem_path = eturem_path
15
- @locations = @exception.backtrace_locations.select do |location|
74
+
75
+ eturem_path = File.dirname(File.absolute_path(__FILE__))
76
+ @backtrace_locations = @exception.backtrace_locations.reject do |location|
16
77
  path = File.absolute_path(location.path)
17
- path !~ /\/rubygems\/core_ext\/kernel_require\.rb$/ &&
18
- path != @eturem_path &&
19
- File.basename(File.dirname(path)) != "eturem"
78
+ path.start_with?(eturem_path) || path.end_with?("/rubygems/core_ext/kernel_require.rb")
79
+ end
80
+ @backtrace_locations.each do |location|
81
+ if $0 == location.path
82
+ def location.label
83
+ super.sub("<top (required)>", "<main>")
84
+ end
85
+ end
20
86
  end
21
- @locations = @locations[0, max_backtrace]
22
- if @exception_s.match(/\A(?<path>[^:]+)\:(?<lineno>\d+)/)
23
- @lineno_in_exception_s = true
87
+
88
+ if @exception.is_a?(SyntaxError) && @exception_s.match(/\A(?<path>[^:]+?)\:(?<lineno>\d+)/)
24
89
  @path = Regexp.last_match(:path)
25
90
  @lineno = Regexp.last_match(:lineno).to_i
26
91
  else
27
- @lineno_in_exception_s = false
28
- @path = @locations.first.path
29
- @lineno = @locations.first.lineno
92
+ backtrace_locations_shift
30
93
  end
94
+
95
+ load_script
96
+ prepare
97
+ end
98
+
99
+ def load_script
31
100
  @script = ""
32
101
  if @path && File.exist?(@path)
33
102
  @script = File.binread(@path)
34
- encoding = @script.lines[0..2].join("\n").match(/coding:\s*(?<encoding>\S+)/) ?
35
- Regexp.last_match(:encoding) : "UTF-8"
103
+ encoding = "utf-8"
104
+ if @script.match(/\A(?:#!.*\R)?#.*coding *[:=] *(?<encoding>[^\s:]+)/)
105
+ encoding = Regexp.last_match(:encoding)
106
+ end
36
107
  @script.force_encoding(encoding)
37
- @script.encode("UTF-8")
38
108
  end
39
109
  @script_lines = @script.lines
40
110
  @script_lines.unshift("")
41
- @range = default_range
42
- prepare
111
+ @output_lines = default_output_lines
43
112
  end
44
113
 
45
114
  def prepare
46
115
  case @exception
47
- when SyntaxError
48
- return unless @exception_s.match(/unexpected (?<unexpected>\S+)\,\s*expecting (?<expected>\S+)/)
49
- @unexpected = Regexp.last_match(:unexpected)
50
- @expected = Regexp.last_match(:expected)
51
- when NameError
52
- highlight!(@script_lines[@lineno], @exception.name.to_s, "\e[31m\e[4m")
53
- return unless @exception_s.match(/Did you mean\?/)
54
- @did_you_mean = Regexp.last_match.post_match.strip.split(/\s+/)
55
- new_range = []
56
- @did_you_mean.each do |did_you_mean|
57
- index = @script_lines.index{|line| line.match(did_you_mean)}
58
- next unless index
59
- highlight!(@script_lines[index], did_you_mean, "\e[33m")
60
- new_range.push(index)
61
- end
62
- before = new_range.select{|i| i < @range.min}
63
- after = new_range.select{|i| i > @range.max}
64
- unless before.empty?
65
- @range.unshift(0) unless @range.include?(before.max + 1)
66
- @range.unshift(*before.sort)
67
- end
68
- unless after.empty?
69
- @range.push(0) unless @range.include?(after.min - 1)
70
- @range.push(*after.sort)
71
- end
72
- when ArgumentError
73
- @method = @locations.first.label
74
- shift_locations
75
- return unless @exception_s.match(/given (?<given>\d+)\, expected (?<expected>[^)]+)/)
76
- @given = Regexp.last_match(:given).to_i
77
- @expected = Regexp.last_match(:expected)
78
- when TypeError
79
- @method = @locations.first.label
80
- shift_locations
116
+ when SyntaxError then prepare_syntax_error
117
+ when NameError then prepare_name_error
118
+ when ArgumentError then prepare_argument_error
119
+ when TypeError then prepare_type_error
81
120
  end
82
121
  end
83
122
 
84
- def shift_locations
85
- @locations.shift
86
- @path = @locations.first.path
87
- @lineno = @locations.first.lineno
88
- @range = default_range
123
+ def prepare_syntax_error
124
+ @unexpected = @exception_s.match(/unexpected (?<unexpected>(?:','|[^,])+)/) ?
125
+ Regexp.last_match(:unexpected) : "end-of-input"
126
+ @expected = @exception_s.match(/[,\s]expecting (?<expected>\S+)/) ?
127
+ Regexp.last_match(:expected) : "end-of-input"
89
128
  end
90
129
 
91
- def default_range
92
- from = [1, @lineno - before_line].max
93
- to = [@script_lines.size - 1, @lineno + after_line].min
94
- (from..to).to_a
130
+ def prepare_name_error
131
+ highlight!(@script_lines[@lineno], @exception.name.to_s, "\e[31m\e[4m")
132
+ return unless @exception_s.match(/Did you mean\?/)
133
+ @did_you_mean = Regexp.last_match.post_match.strip.scan(/\S+/)
134
+ return if @script.empty?
135
+
136
+ new_range = []
137
+ @did_you_mean.each do |name|
138
+ index = @script_lines.index { |line| line.include?(name) }
139
+ next unless index
140
+ highlight!(@script_lines[index], name, "\e[33m")
141
+ new_range.push(index)
142
+ end
143
+ new_range.sort!
144
+ before = new_range.select { |i| i < @output_lines.first }
145
+ after = new_range.select { |i| i > @output_lines.last }
146
+ unless before.empty?
147
+ @output_lines.unshift(nil) if before.last + 1 != @output_lines.first
148
+ @output_lines.unshift(*before)
149
+ end
150
+ unless after.empty?
151
+ @output_lines.push(nil) if @output_lines.last + 1 != after.first
152
+ @output_lines.push(*after)
153
+ end
154
+ end
155
+
156
+ def prepare_argument_error
157
+ @method = @label
158
+ old_path = @path
159
+ backtrace_locations_shift
160
+ load_script unless old_path == @path
161
+ @output_lines = default_output_lines
162
+ if @exception_s.match(/given (?<given>\d+)\, expected (?<expected>[^)]+)/)
163
+ @given = Regexp.last_match(:given).to_i
164
+ @expected = Regexp.last_match(:expected)
165
+ end
95
166
  end
96
167
 
168
+ def prepare_type_error
169
+ @method = @label
170
+ end
171
+
172
+ # main
97
173
  def output_error
98
- output_backtrace
99
- output_exception
100
- output_script
174
+ output_backtrace if @@output_backtrace
175
+ error_message = exception_inspect
176
+ if error_message.to_s.empty?
177
+ puts original_exception_inspect
178
+ else
179
+ puts original_exception_inspect if @@output_original
180
+ puts error_message
181
+ end
182
+ output_script if @@output_script
101
183
  end
102
184
 
103
185
  # backtrace
104
186
  def output_backtrace
105
- return if backtrace.empty?
187
+ return if @backtrace_locations.empty?
106
188
 
107
189
  puts traceback_most_recent_call_last
108
- backtrace.each_with_index do |location, i|
109
- label =
110
- $0 == location.path && location.label == "<top (required)>" ?
111
- "<main>" : location.label
112
- puts sprintf("%9d: %s", backtrace.size - i, location_inspect(location, label))
190
+ @backtrace_locations[0, @@max_backtrace].reverse.each_with_index do |location, i|
191
+ puts sprintf("%9d: %s", @backtrace_locations.size - i, location_inspect(location))
113
192
  end
114
193
  end
115
194
 
116
- def backtrace
117
- get_backtrace unless @backtrace
118
- return @backtrace
119
- end
120
-
121
- def get_backtrace
122
- @backtrace = @locations.reverse.dup
123
- @backtrace.pop unless @lineno_in_exception_s
124
- end
125
-
126
- def max_backtrace
127
- 16
195
+ def backtrace_locations_shift
196
+ @label = @backtrace_locations.first.label
197
+ @path = @backtrace_locations.first.path
198
+ @lineno = @backtrace_locations.first.lineno
199
+ @backtrace_locations.shift
128
200
  end
129
201
 
130
202
  def traceback_most_recent_call_last
131
203
  "Traceback (most recent call last):"
132
204
  end
133
205
 
134
- def location_inspect(location, label = nil)
135
- "from #{location.path}:#{location.lineno}:in `#{label || location.label}'"
206
+ def location_inspect(location)
207
+ "from #{location.path}:#{location.lineno}:in `#{location.label}'"
136
208
  end
137
209
 
138
210
  # exception
139
- def output_exception
140
- puts exception_inspect
141
- end
142
-
143
211
  def exception_inspect
144
- original_exception_inspect
212
+ inspect_methods = self.class.inspect_methods
213
+ inspect_methods.keys.reverse_each do |key|
214
+ case key
215
+ when Class
216
+ return public_send(inspect_methods[key]) if @exception.is_a? key
217
+ when String
218
+ return public_send(inspect_methods[key]) if @exception.class.to_s == key
219
+ end
220
+ end
221
+ return nil
145
222
  end
146
223
 
147
224
  def original_exception_inspect
148
- if @lineno_in_exception_s
225
+ if @exception.is_a? SyntaxError
149
226
  return @exception_s
150
227
  else
151
- label = @locations.first.label
152
- label = "<main>" if $0 == @path && label == "<top (required)>"
153
- location_str = "#{@path}:#{@lineno}:in `#{label}'"
154
- if @exception_s.match(/\A(.*?)\n/)
155
- matched = Regexp.last_match
156
- return "#{location_str}: #{matched[1]} (#{@exception.class})\n#{matched.post_match}"
228
+ location_str = "#{@path}:#{@lineno}:in `#{@label}'"
229
+ if @exception_s.match(/\A(?<first_line>.*?)\n/)
230
+ return "#{location_str}: #{Regexp.last_match(:first_line)} (#{@exception.class})\n" +
231
+ "#{Regexp.last_match.post_match}"
157
232
  else
158
- return "#{location_str}: #{@exception} (#{@exception.class})"
233
+ return "#{location_str}: #{@exception_s} (#{@exception.class})"
159
234
  end
160
235
  end
161
236
  end
162
237
 
163
238
  # script
164
239
  def output_script
165
- max_lineno_length = @range.max.to_s.length
166
- @range.each do |i|
167
- if i == 0
168
- puts " \e[34m#{" " * max_lineno_length} :\e[0m"
240
+ return if @script.empty?
241
+
242
+ max_lineno_length = @output_lines.compact.max.to_s.length
243
+ @output_lines.each do |i|
244
+ if @lineno == i
245
+ puts sprintf(" => \e[34m%#{max_lineno_length}d:\e[0m %s", i, @script_lines[i])
246
+ elsif i
247
+ puts sprintf(" \e[34m%#{max_lineno_length}d:\e[0m %s", i, @script_lines[i])
169
248
  else
170
- if @lineno == i
171
- puts sprintf(" => \e[34m%#{max_lineno_length}d:\e[0m %s", i, @script_lines[i])
172
- else
173
- puts sprintf(" \e[34m%#{max_lineno_length}d:\e[0m %s", i, @script_lines[i])
174
- end
249
+ puts " \e[34m#{" " * max_lineno_length} :\e[0m"
175
250
  end
176
251
  end
177
252
  end
178
253
 
179
- def before_line
180
- 2
254
+ def highlight(str, keyword, color)
255
+ str.to_s.gsub(keyword){ color + ($1 || $&) + "\e[0m" }
181
256
  end
182
257
 
183
- def after_line
184
- 2
258
+ def highlight!(str, keyword, color)
259
+ str.gsub!(keyword){ color + ($1 || $&) + "\e[0m" } if str
185
260
  end
186
261
 
187
- def highlight(str, keyword, color)
188
- str.gsub(keyword){ color + ($1 || $&) + "\e[0m" }
189
- end
190
-
191
- def highlight!(str, keyword, color)
192
- str.gsub!(keyword){ color + ($1 || $&) + "\e[0m" }
262
+ def default_output_lines
263
+ from = [1, @lineno - @@before_line_num].max
264
+ to = [@script_lines.size - 1, @lineno + @@after_line_num].min
265
+ (from..to).to_a
193
266
  end
267
+
268
+ Eturem.eturem_class = self
194
269
  end
195
-
196
- set_eturem_class Base
197
270
  end
@@ -0,0 +1,216 @@
1
+ require "eturem/base"
2
+
3
+ module Eturem
4
+ class En < Base
5
+ @inspect_methods = {
6
+ # NoMemoryError => :no_memory_error_inspect,
7
+ # ScriptError => :script_error_inspect,
8
+ # LoadError => :load_error_inspect,
9
+ # NotImplementedError => :not_implemented_error_inspect,
10
+ # SyntaxError => :syntax_error_inspect,
11
+ # SecurityError => :security_error_inspect,
12
+ # SignalException => :signal_exception_inspect,
13
+ # Interrupt => :interrupt_inspect,
14
+ # StandardError => :standard_error_inspect,
15
+ # ArgumentError => :argument_error_inspect,
16
+ # UncaughtThrowError => :uncaught_throw_error_inspect,
17
+ # EncodingError => :encoding_error_inspect,
18
+ # Encoding::CompatibilityError => :encoding_compatibility_error_inspect,
19
+ # Encoding::ConverterNotFoundError => :encoding_converter_not_found_error_inspect,
20
+ # Encoding::InvalidByteSequenceError => :encoding_invalid_byte_sequence_error_inspect,
21
+ # Encoding::UndefinedConversionError => :encoding_undefined_conversion_error_inspect,
22
+ # FiberError => :fiber_error_inspect,
23
+ # IOError => :io_error_inspect,
24
+ # EOFError => :eof_error_inspect,
25
+ # IndexError => :index_error_inspect,
26
+ # KeyError => :key_error_inspect,
27
+ # StopIteration => :stop_iteration_inspect,
28
+ # ClosedQueueError => :closed_queue_error_inspect,
29
+ # LocalJumpError => :local_jump_error_inspect,
30
+ # Math::DomainError => :math_domain_error_inspect,
31
+ # NameError => :name_error_inspect,
32
+ # NoMethodError => :no_method_error_inspect,
33
+ # RangeError => :range_error_inspect,
34
+ # FloatDomainError => :float_domain_error_inspect,
35
+ # RegexpError => :regexp_error_inspect,
36
+ # RuntimeError => :runtime_error_inspect,
37
+ # FrozenError => :frozen_error_inspect,
38
+ # SystemCallError => :system_call_error_inspect,
39
+ # Errno::E2BIG => :errno_e2big_inspect,
40
+ # Errno::EACCES => :errno_eacces_inspect,
41
+ # Errno::EADDRINUSE => :errno_eaddrinuse_inspect,
42
+ # Errno::EADDRNOTAVAIL => :errno_eaddrnotavail_inspect,
43
+ # Errno::EADV => :errno_eadv_inspect,
44
+ # Errno::EAFNOSUPPORT => :errno_eafnosupport_inspect,
45
+ # Errno::EAGAIN => :errno_eagain_inspect,
46
+ # Errno::EALREADY => :errno_ealready_inspect,
47
+ # Errno::EAUTH => :errno_eauth_inspect,
48
+ # Errno::EBADE => :errno_ebade_inspect,
49
+ # Errno::EBADF => :errno_ebadf_inspect,
50
+ # Errno::EBADFD => :errno_ebadfd_inspect,
51
+ # Errno::EBADMSG => :errno_ebadmsg_inspect,
52
+ # Errno::EBADR => :errno_ebadr_inspect,
53
+ # Errno::EBADRPC => :errno_ebadrpc_inspect,
54
+ # Errno::EBADRQC => :errno_ebadrqc_inspect,
55
+ # Errno::EBADSLT => :errno_ebadslt_inspect,
56
+ # Errno::EBFONT => :errno_ebfont_inspect,
57
+ # Errno::EBUSY => :errno_ebusy_inspect,
58
+ # Errno::ECANCELED => :errno_ecanceled_inspect,
59
+ # Errno::ECAPMODE => :errno_ecapmode_inspect,
60
+ # Errno::ECHILD => :errno_echild_inspect,
61
+ # Errno::ECHRNG => :errno_echrng_inspect,
62
+ # Errno::ECOMM => :errno_ecomm_inspect,
63
+ # Errno::ECONNABORTED => :errno_econnaborted_inspect,
64
+ # Errno::ECONNREFUSED => :errno_econnrefused_inspect,
65
+ # Errno::ECONNRESET => :errno_econnreset_inspect,
66
+ # Errno::EDEADLK => :errno_edeadlk_inspect,
67
+ # Errno::EDEADLOCK => :errno_edeadlock_inspect,
68
+ # Errno::EDESTADDRREQ => :errno_edestaddrreq_inspect,
69
+ # Errno::EDOM => :errno_edom_inspect,
70
+ # Errno::EDOOFUS => :errno_edoofus_inspect,
71
+ # Errno::EDOTDOT => :errno_edotdot_inspect,
72
+ # Errno::EDQUOT => :errno_edquot_inspect,
73
+ # Errno::EEXIST => :errno_eexist_inspect,
74
+ # Errno::EFAULT => :errno_efault_inspect,
75
+ # Errno::EFBIG => :errno_efbig_inspect,
76
+ # Errno::EFTYPE => :errno_eftype_inspect,
77
+ # Errno::EHOSTDOWN => :errno_ehostdown_inspect,
78
+ # Errno::EHOSTUNREACH => :errno_ehostunreach_inspect,
79
+ # Errno::EHWPOISON => :errno_ehwpoison_inspect,
80
+ # Errno::EIDRM => :errno_eidrm_inspect,
81
+ # Errno::EILSEQ => :errno_eilseq_inspect,
82
+ # Errno::EINPROGRESS => :errno_einprogress_inspect,
83
+ # Errno::EINTR => :errno_eintr_inspect,
84
+ # Errno::EINVAL => :errno_einval_inspect,
85
+ # Errno::EIO => :errno_Eio_inspect,
86
+ # Errno::EIPSEC => :errno_eipsec_inspect,
87
+ # Errno::EISCONN => :errno_eisconn_inspect,
88
+ # Errno::EISDIR => :errno_eisdir_inspect,
89
+ # Errno::EISNAM => :errno_eisnam_inspect,
90
+ # Errno::EKEYEXPIRED => :errno_ekeyexpired_inspect,
91
+ # Errno::EKEYREJECTED => :errno_ekeyrejected_inspect,
92
+ # Errno::EKEYREVOKED => :errno_ekeyrevoked_inspect,
93
+ # Errno::EL2HLT => :errno_el2hlt_inspect,
94
+ # Errno::EL2NSYNC => :errno_el2nsync_inspect,
95
+ # Errno::EL3HLT => :errno_el3hlt_inspect,
96
+ # Errno::EL3RST => :errno_el3rst_inspect,
97
+ # Errno::ELIBACC => :errno_elibacc_inspect,
98
+ # Errno::ELIBBAD => :errno_elibbad_inspect,
99
+ # Errno::ELIBEXEC => :errno_elibexec_inspect,
100
+ # Errno::ELIBMAX => :errno_elibmax_inspect,
101
+ # Errno::ELIBSCN => :errno_elibscn_inspect,
102
+ # Errno::ELNRNG => :errno_elnrng_inspect,
103
+ # Errno::ELOOP => :errno_eloop_inspect,
104
+ # Errno::EMEDIUMTYPE => :errno_emediumtype_inspect,
105
+ # Errno::EMFILE => :errno_emfile_inspect,
106
+ # Errno::EMLINK => :errno_emlink_inspect,
107
+ # Errno::EMSGSIZE => :errno_emsgsize_inspect,
108
+ # Errno::EMULTIHOP => :errno_emultihop_inspect,
109
+ # Errno::ENAMETOOLONG => :errno_enametoolong_inspect,
110
+ # Errno::ENAVAIL => :errno_enavail_inspect,
111
+ # Errno::ENEEDAUTH => :errno_eneedauth_inspect,
112
+ # Errno::ENETDOWN => :errno_enetdown_inspect,
113
+ # Errno::ENETRESET => :errno_enetreset_inspect,
114
+ # Errno::ENETUNREACH => :errno_enetunreach_inspect,
115
+ # Errno::ENFILE => :errno_enfile_inspect,
116
+ # Errno::ENOANO => :errno_enoano_inspect,
117
+ # Errno::ENOATTR => :errno_enoattr_inspect,
118
+ # Errno::ENOBUFS => :errno_enobufs_inspect,
119
+ # Errno::ENOCSI => :errno_enocsi_inspect,
120
+ # Errno::ENODATA => :errno_enodata_inspect,
121
+ # Errno::ENODEV => :errno_enodev_inspect,
122
+ # Errno::ENOENT => :errno_enoent_inspect,
123
+ # Errno::ENOEXEC => :errno_enoexec_inspect,
124
+ # Errno::ENOKEY => :errno_enokey_inspect,
125
+ # Errno::ENOLCK => :errno_enolck_inspect,
126
+ # Errno::ENOLINK => :errno_enolink_inspect,
127
+ # Errno::ENOMEDIUM => :errno_enomedium_inspect,
128
+ # Errno::ENOMEM => :errno_enomem_inspect,
129
+ # Errno::ENOMSG => :errno_enomsg_inspect,
130
+ # Errno::ENONET => :errno_enonet_inspect,
131
+ # Errno::ENOPKG => :errno_enopkg_inspect,
132
+ # Errno::ENOPROTOOPT => :errno_enoprotoopt_inspect,
133
+ # Errno::ENOSPC => :errno_enospc_inspect,
134
+ # Errno::ENOSR => :errno_enosr_inspect,
135
+ # Errno::ENOSTR => :errno_enostr_inspect,
136
+ # Errno::ENOSYS => :errno_enosys_inspect,
137
+ # Errno::ENOTBLK => :errno_enotblk_inspect,
138
+ # Errno::ENOTCAPABLE => :errno_enotcapable_inspect,
139
+ # Errno::ENOTCONN => :errno_enotconn_inspect,
140
+ # Errno::ENOTDIR => :errno_enotdir_inspect,
141
+ # Errno::ENOTEMPTY => :errno_enotempty_inspect,
142
+ # Errno::ENOTNAM => :errno_enotnam_inspect,
143
+ # Errno::ENOTRECOVERABLE => :errno_enotrecoverable_inspect,
144
+ # Errno::ENOTSOCK => :errno_enotsock_inspect,
145
+ # Errno::ENOTSUP => :errno_enotsup_inspect,
146
+ # Errno::ENOTTY => :errno_enotty_inspect,
147
+ # Errno::ENOTUNIQ => :errno_enotuniq_inspect,
148
+ # Errno::ENXIO => :errno_enxio_inspect,
149
+ # Errno::EOPNOTSUPP => :errno_eopnotsupp_inspect,
150
+ # Errno::EOVERFLOW => :errno_eoverflow_inspect,
151
+ # Errno::EOWNERDEAD => :errno_eownerdead_inspect,
152
+ # Errno::EPERM => :errno_eperm_inspect,
153
+ # Errno::EPFNOSUPPORT => :errno_epfnosupport_inspect,
154
+ # Errno::EPIPE => :errno_epipe_inspect,
155
+ # Errno::EPROCLIM => :errno_eproclim_inspect,
156
+ # Errno::EPROCUNAVAIL => :errno_eprocunavail_inspect,
157
+ # Errno::EPROGMISMATCH => :errno_eprogmismatch_inspect,
158
+ # Errno::EPROGUNAVAIL => :errno_eprogunavail_inspect,
159
+ # Errno::EPROTO => :errno_eproto_inspect,
160
+ # Errno::EPROTONOSUPPORT => :errno_eprotonosupport_inspect,
161
+ # Errno::EPROTOTYPE => :errno_eprototype_inspect,
162
+ # Errno::ERANGE => :errno_erange_inspect,
163
+ # Errno::EREMCHG => :errno_eremchg_inspect,
164
+ # Errno::EREMOTE => :errno_eremote_inspect,
165
+ # Errno::EREMOTEIO => :errno_eremoteio_inspect,
166
+ # Errno::ERESTART => :errno_erestart_inspect,
167
+ # Errno::ERFKILL => :errno_erfkill_inspect,
168
+ # Errno::EROFS => :errno_erofs_inspect,
169
+ # Errno::ERPCMISMATCH => :errno_erpcmismatch_inspect,
170
+ # Errno::ESHUTDOWN => :errno_eshutdown_inspect,
171
+ # Errno::ESOCKTNOSUPPORT => :errno_esocktnosupport_inspect,
172
+ # Errno::ESPIPE => :errno_espipe_inspect,
173
+ # Errno::ESRCH => :errno_esrch_inspect,
174
+ # Errno::ESRMNT => :errno_esrmnt_inspect,
175
+ # Errno::ESTALE => :errno_estale_inspect,
176
+ # Errno::ESTRPIPE => :errno_estrpipe_inspect,
177
+ # Errno::ETIME => :errno_etime_inspect,
178
+ # Errno::ETIMEDOUT => :errno_etimedout_inspect,
179
+ # Errno::ETOOMANYREFS => :errno_etoomanyrefs_inspect,
180
+ # Errno::ETXTBSY => :errno_etxtbsy_inspect,
181
+ # Errno::EUCLEAN => :errno_euclean_inspect,
182
+ # Errno::EUNATCH => :errno_eunatch_inspect,
183
+ # Errno::EUSERS => :errno_eusers_inspect,
184
+ # Errno::EWOULDBLOCK => :errno_ewouldblock_inspect,
185
+ # Errno::EXDEV => :errno_exdev_inspect,
186
+ # Errno::EXFULL => :errno_exfull_inspect,
187
+ # Errno::EXXX => :errno_exxx_inspect,
188
+ # Errno::NOERROR => :errno_noerror_inspect,
189
+ # ThreadError => :thread_error_inspect,
190
+ # TypeError => :type_error_inspect,
191
+ # ZeroDivisionError => :zero_division_error_inspect,
192
+ # SystemStackError => :system_stack_error_inspect,
193
+ "sentinel" => nil
194
+ }
195
+
196
+ def prepare
197
+ super
198
+ end
199
+
200
+ def traceback_most_recent_call_last
201
+ super
202
+ end
203
+
204
+ def location_inspect(location)
205
+ super
206
+ end
207
+
208
+ def exception_inspect
209
+ super
210
+ end
211
+
212
+ Eturem.eturem_class = self
213
+ end
214
+ end
215
+
216
+ require "eturem"
@@ -4,6 +4,198 @@ require "eturem/base"
4
4
 
5
5
  module Eturem
6
6
  class Ja < Base
7
+
8
+ @inspect_methods = {
9
+ NoMemoryError => :no_memory_error_inspect,
10
+ # ScriptError => :script_error_inspect,
11
+ LoadError => :load_error_inspect,
12
+ # NotImplementedError => :not_implemented_error_inspect,
13
+ SyntaxError => :syntax_error_inspect,
14
+ # SecurityError => :security_error_inspect,
15
+ # SignalException => :signal_exception_inspect,
16
+ # Interrupt => :interrupt_inspect,
17
+ # StandardError => :standard_error_inspect,
18
+ ArgumentError => :argument_error_inspect,
19
+ # UncaughtThrowError => :uncaught_throw_error_inspect,
20
+ # EncodingError => :encoding_error_inspect,
21
+ # Encoding::CompatibilityError => :encoding_compatibility_error_inspect,
22
+ # Encoding::ConverterNotFoundError => :encoding_converter_not_found_error_inspect,
23
+ # Encoding::InvalidByteSequenceError => :encoding_invalid_byte_sequence_error_inspect,
24
+ # Encoding::UndefinedConversionError => :encoding_undefined_conversion_error_inspect,
25
+ # FiberError => :fiber_error_inspect,
26
+ # IOError => :io_error_inspect,
27
+ # EOFError => :eof_error_inspect,
28
+ # IndexError => :index_error_inspect,
29
+ # KeyError => :key_error_inspect,
30
+ # StopIteration => :stop_iteration_inspect,
31
+ # ClosedQueueError => :closed_queue_error_inspect,
32
+ # LocalJumpError => :local_jump_error_inspect,
33
+ # Math::DomainError => :math_domain_error_inspect,
34
+ NameError => :name_error_inspect,
35
+ # NoMethodError => :no_method_error_inspect,
36
+ # RangeError => :range_error_inspect,
37
+ # FloatDomainError => :float_domain_error_inspect,
38
+ # RegexpError => :regexp_error_inspect,
39
+ # RuntimeError => :runtime_error_inspect,
40
+ # FrozenError => :frozen_error_inspect,
41
+ # SystemCallError => :system_call_error_inspect,
42
+ # Errno::E2BIG => :errno_e2big_inspect,
43
+ # Errno::EACCES => :errno_eacces_inspect,
44
+ # Errno::EADDRINUSE => :errno_eaddrinuse_inspect,
45
+ # Errno::EADDRNOTAVAIL => :errno_eaddrnotavail_inspect,
46
+ # Errno::EADV => :errno_eadv_inspect,
47
+ # Errno::EAFNOSUPPORT => :errno_eafnosupport_inspect,
48
+ # Errno::EAGAIN => :errno_eagain_inspect,
49
+ # Errno::EALREADY => :errno_ealready_inspect,
50
+ # Errno::EAUTH => :errno_eauth_inspect,
51
+ # Errno::EBADE => :errno_ebade_inspect,
52
+ # Errno::EBADF => :errno_ebadf_inspect,
53
+ # Errno::EBADFD => :errno_ebadfd_inspect,
54
+ # Errno::EBADMSG => :errno_ebadmsg_inspect,
55
+ # Errno::EBADR => :errno_ebadr_inspect,
56
+ # Errno::EBADRPC => :errno_ebadrpc_inspect,
57
+ # Errno::EBADRQC => :errno_ebadrqc_inspect,
58
+ # Errno::EBADSLT => :errno_ebadslt_inspect,
59
+ # Errno::EBFONT => :errno_ebfont_inspect,
60
+ # Errno::EBUSY => :errno_ebusy_inspect,
61
+ # Errno::ECANCELED => :errno_ecanceled_inspect,
62
+ # Errno::ECAPMODE => :errno_ecapmode_inspect,
63
+ # Errno::ECHILD => :errno_echild_inspect,
64
+ # Errno::ECHRNG => :errno_echrng_inspect,
65
+ # Errno::ECOMM => :errno_ecomm_inspect,
66
+ # Errno::ECONNABORTED => :errno_econnaborted_inspect,
67
+ # Errno::ECONNREFUSED => :errno_econnrefused_inspect,
68
+ # Errno::ECONNRESET => :errno_econnreset_inspect,
69
+ # Errno::EDEADLK => :errno_edeadlk_inspect,
70
+ # Errno::EDEADLOCK => :errno_edeadlock_inspect,
71
+ # Errno::EDESTADDRREQ => :errno_edestaddrreq_inspect,
72
+ # Errno::EDOM => :errno_edom_inspect,
73
+ # Errno::EDOOFUS => :errno_edoofus_inspect,
74
+ # Errno::EDOTDOT => :errno_edotdot_inspect,
75
+ # Errno::EDQUOT => :errno_edquot_inspect,
76
+ # Errno::EEXIST => :errno_eexist_inspect,
77
+ # Errno::EFAULT => :errno_efault_inspect,
78
+ # Errno::EFBIG => :errno_efbig_inspect,
79
+ # Errno::EFTYPE => :errno_eftype_inspect,
80
+ # Errno::EHOSTDOWN => :errno_ehostdown_inspect,
81
+ # Errno::EHOSTUNREACH => :errno_ehostunreach_inspect,
82
+ # Errno::EHWPOISON => :errno_ehwpoison_inspect,
83
+ # Errno::EIDRM => :errno_eidrm_inspect,
84
+ # Errno::EILSEQ => :errno_eilseq_inspect,
85
+ # Errno::EINPROGRESS => :errno_einprogress_inspect,
86
+ # Errno::EINTR => :errno_eintr_inspect,
87
+ # Errno::EINVAL => :errno_einval_inspect,
88
+ # Errno::EIO => :errno_Eio_inspect,
89
+ # Errno::EIPSEC => :errno_eipsec_inspect,
90
+ # Errno::EISCONN => :errno_eisconn_inspect,
91
+ # Errno::EISDIR => :errno_eisdir_inspect,
92
+ # Errno::EISNAM => :errno_eisnam_inspect,
93
+ # Errno::EKEYEXPIRED => :errno_ekeyexpired_inspect,
94
+ # Errno::EKEYREJECTED => :errno_ekeyrejected_inspect,
95
+ # Errno::EKEYREVOKED => :errno_ekeyrevoked_inspect,
96
+ # Errno::EL2HLT => :errno_el2hlt_inspect,
97
+ # Errno::EL2NSYNC => :errno_el2nsync_inspect,
98
+ # Errno::EL3HLT => :errno_el3hlt_inspect,
99
+ # Errno::EL3RST => :errno_el3rst_inspect,
100
+ # Errno::ELIBACC => :errno_elibacc_inspect,
101
+ # Errno::ELIBBAD => :errno_elibbad_inspect,
102
+ # Errno::ELIBEXEC => :errno_elibexec_inspect,
103
+ # Errno::ELIBMAX => :errno_elibmax_inspect,
104
+ # Errno::ELIBSCN => :errno_elibscn_inspect,
105
+ # Errno::ELNRNG => :errno_elnrng_inspect,
106
+ # Errno::ELOOP => :errno_eloop_inspect,
107
+ # Errno::EMEDIUMTYPE => :errno_emediumtype_inspect,
108
+ # Errno::EMFILE => :errno_emfile_inspect,
109
+ # Errno::EMLINK => :errno_emlink_inspect,
110
+ # Errno::EMSGSIZE => :errno_emsgsize_inspect,
111
+ # Errno::EMULTIHOP => :errno_emultihop_inspect,
112
+ # Errno::ENAMETOOLONG => :errno_enametoolong_inspect,
113
+ # Errno::ENAVAIL => :errno_enavail_inspect,
114
+ # Errno::ENEEDAUTH => :errno_eneedauth_inspect,
115
+ # Errno::ENETDOWN => :errno_enetdown_inspect,
116
+ # Errno::ENETRESET => :errno_enetreset_inspect,
117
+ # Errno::ENETUNREACH => :errno_enetunreach_inspect,
118
+ # Errno::ENFILE => :errno_enfile_inspect,
119
+ # Errno::ENOANO => :errno_enoano_inspect,
120
+ # Errno::ENOATTR => :errno_enoattr_inspect,
121
+ # Errno::ENOBUFS => :errno_enobufs_inspect,
122
+ # Errno::ENOCSI => :errno_enocsi_inspect,
123
+ # Errno::ENODATA => :errno_enodata_inspect,
124
+ # Errno::ENODEV => :errno_enodev_inspect,
125
+ Errno::ENOENT => :errno_enoent_inspect,
126
+ # Errno::ENOEXEC => :errno_enoexec_inspect,
127
+ # Errno::ENOKEY => :errno_enokey_inspect,
128
+ # Errno::ENOLCK => :errno_enolck_inspect,
129
+ # Errno::ENOLINK => :errno_enolink_inspect,
130
+ # Errno::ENOMEDIUM => :errno_enomedium_inspect,
131
+ # Errno::ENOMEM => :errno_enomem_inspect,
132
+ # Errno::ENOMSG => :errno_enomsg_inspect,
133
+ # Errno::ENONET => :errno_enonet_inspect,
134
+ # Errno::ENOPKG => :errno_enopkg_inspect,
135
+ # Errno::ENOPROTOOPT => :errno_enoprotoopt_inspect,
136
+ # Errno::ENOSPC => :errno_enospc_inspect,
137
+ # Errno::ENOSR => :errno_enosr_inspect,
138
+ # Errno::ENOSTR => :errno_enostr_inspect,
139
+ # Errno::ENOSYS => :errno_enosys_inspect,
140
+ # Errno::ENOTBLK => :errno_enotblk_inspect,
141
+ # Errno::ENOTCAPABLE => :errno_enotcapable_inspect,
142
+ # Errno::ENOTCONN => :errno_enotconn_inspect,
143
+ # Errno::ENOTDIR => :errno_enotdir_inspect,
144
+ # Errno::ENOTEMPTY => :errno_enotempty_inspect,
145
+ # Errno::ENOTNAM => :errno_enotnam_inspect,
146
+ # Errno::ENOTRECOVERABLE => :errno_enotrecoverable_inspect,
147
+ # Errno::ENOTSOCK => :errno_enotsock_inspect,
148
+ # Errno::ENOTSUP => :errno_enotsup_inspect,
149
+ # Errno::ENOTTY => :errno_enotty_inspect,
150
+ # Errno::ENOTUNIQ => :errno_enotuniq_inspect,
151
+ # Errno::ENXIO => :errno_enxio_inspect,
152
+ # Errno::EOPNOTSUPP => :errno_eopnotsupp_inspect,
153
+ # Errno::EOVERFLOW => :errno_eoverflow_inspect,
154
+ # Errno::EOWNERDEAD => :errno_eownerdead_inspect,
155
+ # Errno::EPERM => :errno_eperm_inspect,
156
+ # Errno::EPFNOSUPPORT => :errno_epfnosupport_inspect,
157
+ # Errno::EPIPE => :errno_epipe_inspect,
158
+ # Errno::EPROCLIM => :errno_eproclim_inspect,
159
+ # Errno::EPROCUNAVAIL => :errno_eprocunavail_inspect,
160
+ # Errno::EPROGMISMATCH => :errno_eprogmismatch_inspect,
161
+ # Errno::EPROGUNAVAIL => :errno_eprogunavail_inspect,
162
+ # Errno::EPROTO => :errno_eproto_inspect,
163
+ # Errno::EPROTONOSUPPORT => :errno_eprotonosupport_inspect,
164
+ # Errno::EPROTOTYPE => :errno_eprototype_inspect,
165
+ # Errno::ERANGE => :errno_erange_inspect,
166
+ # Errno::EREMCHG => :errno_eremchg_inspect,
167
+ # Errno::EREMOTE => :errno_eremote_inspect,
168
+ # Errno::EREMOTEIO => :errno_eremoteio_inspect,
169
+ # Errno::ERESTART => :errno_erestart_inspect,
170
+ # Errno::ERFKILL => :errno_erfkill_inspect,
171
+ # Errno::EROFS => :errno_erofs_inspect,
172
+ # Errno::ERPCMISMATCH => :errno_erpcmismatch_inspect,
173
+ # Errno::ESHUTDOWN => :errno_eshutdown_inspect,
174
+ # Errno::ESOCKTNOSUPPORT => :errno_esocktnosupport_inspect,
175
+ # Errno::ESPIPE => :errno_espipe_inspect,
176
+ # Errno::ESRCH => :errno_esrch_inspect,
177
+ # Errno::ESRMNT => :errno_esrmnt_inspect,
178
+ # Errno::ESTALE => :errno_estale_inspect,
179
+ # Errno::ESTRPIPE => :errno_estrpipe_inspect,
180
+ # Errno::ETIME => :errno_etime_inspect,
181
+ # Errno::ETIMEDOUT => :errno_etimedout_inspect,
182
+ # Errno::ETOOMANYREFS => :errno_etoomanyrefs_inspect,
183
+ # Errno::ETXTBSY => :errno_etxtbsy_inspect,
184
+ # Errno::EUCLEAN => :errno_euclean_inspect,
185
+ # Errno::EUNATCH => :errno_eunatch_inspect,
186
+ # Errno::EUSERS => :errno_eusers_inspect,
187
+ # Errno::EWOULDBLOCK => :errno_ewouldblock_inspect,
188
+ # Errno::EXDEV => :errno_exdev_inspect,
189
+ # Errno::EXFULL => :errno_exfull_inspect,
190
+ # Errno::EXXX => :errno_exxx_inspect,
191
+ # Errno::NOERROR => :errno_noerror_inspect,
192
+ # ThreadError => :thread_error_inspect,
193
+ TypeError => :type_error_inspect,
194
+ ZeroDivisionError => :zero_division_error_inspect,
195
+ SystemStackError => :system_stack_error_inspect,
196
+ "sentinel" => nil
197
+ }
198
+
7
199
  def prepare
8
200
  super
9
201
  case @exception.class.to_s
@@ -17,110 +209,122 @@ module Eturem
17
209
  "エラー発生までの流れ:"
18
210
  end
19
211
 
20
- def location_inspect(location, label)
21
- "\"#{location.path}\" #{location.lineno}行目: '#{label}'"
212
+ def location_inspect(location)
213
+ %["#{location.path}" #{location.lineno}行目: '#{location.label}']
22
214
  end
23
215
 
24
- def output_exception
25
- puts exception_inspect
26
- end
27
-
28
216
  def exception_inspect
29
- ret = original_exception_inspect.chomp + "\n" + "ファイル\"#{@path}\" #{@lineno}行目でエラーが発生しました。\n"
30
- case @exception
31
- when LoadError
32
- return ret +
33
- "ファイル/ライブラリ '#{@exception.path}' が見つかりません。" +
34
- "ファイル/ライブラリ名を確認してください。"
35
- when SyntaxError
36
- return syntax_error_inspect(ret)
37
- when Interrupt
38
- return ret + "プログラムが途中で強制終了されました。"
39
- when ArgumentError
40
- if @given
41
- return ret +
42
- "引数の数が正しくありません。" +
43
- "「#{@method}」は本来" +
44
- (@expected =~ /^0$/ ? "引数が不要ですが、" : "#{@expected}個の引数を取りますが、") +
45
- "#{@given}個の引数が渡されています。"
46
- else
47
- return ret + "「#{@method}」への引数の数が正しくありません。"
48
- end
49
- when NameError, NoMethodError
50
- return name_error_inspect(ret)
51
- when TypeError
52
- return ret + "「#{@method}」への引数のタイプが正しくありません。"
53
- when ZeroDivisionError
54
- return ret + "割る数が 0 での割り算はできません。"
55
- else
56
- return ret
57
- end
217
+ return %[ファイル"#{@path}" #{@lineno}行目でエラーが発生しました。\n] + super.to_s
58
218
  end
59
219
 
60
- def syntax_error_inspect(ret)
61
- unexpected = transform_syntax_error_keyword(@unexpected)
62
- expected = transform_syntax_error_keyword(@expected)
63
- unexpected.each do |keyword|
64
- next unless keyword.match(/^「\s*(\S+)\s*」$/)
220
+ def no_memory_error_inspect
221
+ "メモリを確保できませんでした。あまりにも大量のデータを作成していませんか?"
222
+ end
223
+
224
+ def load_error_inspect
225
+ %[ファイル/ライブラリ "#{@exception.path}" が見つかりません。] +
226
+ %[ファイル/ライブラリ名を確認してください。]
227
+ end
228
+
229
+ def syntax_error_inspect
230
+ if @unexpected.match(/^'(.)'$/)
65
231
  highlight!(@script_lines[@lineno], Regexp.last_match(1), "\e[31m\e[4m")
232
+ elsif @unexpected.match(/^(?:keyword|modifier)_/)
233
+ highlight!(@script_lines[@lineno], Regexp.last_match.post_match, "\e[31m\e[4m")
66
234
  end
67
- keywords = get_keywords_from_script(%w[if unless case while until for begin def class module do])
235
+ unexpected = transform_syntax_error_keyword(@unexpected)
236
+ expected = @expected.split(/\s+or\s+/).map{ |ex| transform_syntax_error_keyword(ex) }
237
+ keywords = %w[if unless case while until for begin def class module do].select{ |keyword|
238
+ @script.index(keyword)
239
+ }.join(" / ")
240
+ keywords = keywords.empty? ? "ifなど" : "「#{keywords}」"
68
241
 
69
- if @expected == "end-of-input" || @expected == "$end"
70
- ret += "構文エラーです。余分な#{unexpected.join('または')}があります。"
71
- ret += "「#{keywords.join(' / ')}」と「end」の対応関係を確認してください。" if @unexpected == "keyword_end"
242
+ if expected.join == "end-of-input"
243
+ ret = "構文エラーです。余分な#{unexpected}があります。"
244
+ ret += "#{keywords}と「end」の対応関係を確認してください。" if unexpected == "end"
72
245
  return ret
73
- elsif @unexpected == "end-of-input" || @unexpected == "$end"
74
- ret = ret.chomp + "(ただし、エラーの原因はおそらくもっと前にあります。)\n" +
246
+ elsif unexpected == "end-of-input"
247
+ ret = "(ただし、実際のエラーの原因はおそらくもっと前にあります。)\n" +
75
248
  "構文エラーです。#{expected.join('または')}が足りません。"
76
- ret += "「#{keywords.join(' / ')}」に対応する「end」があるか確認してください。" if @expected == "keyword_end"
249
+ ret += "#{keywords}に対応する「end」があるか確認してください。" if expected.include?("end")
77
250
  return ret
78
251
  end
79
- return ret + "構文エラーです。" +
80
- "#{unexpected.join('または')}より前のどこかに、" +
81
- "#{expected.join('または')}を入れる必要があります。"
252
+ return "構文エラーです。#{expected.join('または')}が来るべき場所に、" +
253
+ "#{unexpected}が来てしまいました。"
82
254
  end
83
255
 
84
256
  def transform_syntax_error_keyword(keyword)
85
- keyword.split(/\s+or\s+/).map do |word|
86
- case word
87
- when "end-of-input", "$end"
88
- "end-of-input"
89
- when /^keyword\_/
90
- "「#{word.sub("keyword_", "")}」"
91
- when "'\\n'"
92
- "改行"
93
- when /^'[^']+'$/
94
- "「 #{word.gsub("'", "")} 」"
95
- else
96
- word
97
- end
257
+ case keyword
258
+ when "end-of-input", "$end"
259
+ "end-of-input"
260
+ when /^(?:keyword|modifier)_/
261
+ Regexp.last_match.post_match
262
+ when "'\\n'"
263
+ "改行"
264
+ else
265
+ keyword
98
266
  end
99
267
  end
100
268
 
101
- def get_keywords_from_script(keywords)
102
- keywords.select { |keyword| @script.index(keyword) }
269
+ def interrupt_inspect
270
+ "プログラムが途中で強制終了されました。"
103
271
  end
104
272
 
105
- def name_error_inspect(ret)
106
- ret = ret.lines.first + ret.lines.last
107
- if @exception.name.to_s.encode("UTF-8") == " "
108
- @range = default_range
109
- ret += "スクリプト中に全角空白が混じっています。"
110
- else
111
- ret += "#{@exception.is_a?(NoMethodError) ? "" : "変数/"}メソッド"
112
- ret += "「\e[31m\e[4m#{@exception.name}\e[0m」は存在しません。"
113
- if @did_you_mean
114
- did_you_mean = @did_you_mean.map{|d| "\e[33m#{d}\e[0m"}.join(" / ")
115
- ret += "「#{did_you_mean}」の入力ミスではありませんか?"
273
+ def argument_error_inspect
274
+ if @given
275
+ ret = "引数の数が正しくありません。「#{@method}」は本来"
276
+ case @expected
277
+ when "0"
278
+ ret += "引数が不要です"
279
+ when /^(\d+)\.\.(\d+)$/
280
+ ret += "#{Regexp.last_match(1)}~#{Regexp.last_match(2)}個の引数を取ります"
281
+ when /^(\d+)\+$/
282
+ ret += "#{Regexp.last_match(1)}個以上の引数を取ります"
116
283
  end
284
+ if @given == 0
285
+ ret += "が、引数が1つも渡されていません。"
286
+ else
287
+ ret += "が、#{@given}個の引数が渡されています。"
288
+ end
289
+ return ret
290
+ else
291
+ return "「#{@method}」への引数の数が正しくありません。"
292
+ end
293
+ end
294
+
295
+ def name_error_inspect
296
+ if @exception.name.to_s.encode("UTF-8").include?(" ")
297
+ @output_lines = default_output_lines
298
+ return "スクリプト中に全角空白が混じっています。"
299
+ end
300
+
301
+ ret = "#{@exception.is_a?(NoMethodError) ? "" : "変数/"}メソッド" +
302
+ "「\e[31m\e[4m#{@exception.name}\e[0m」は存在しません。"
303
+ if @did_you_mean
304
+ did_you_mean = @did_you_mean.map{ |d| "\e[33m#{d}\e[0m" }.join(" / ")
305
+ ret += "「#{did_you_mean}」の入力ミスではありませんか?"
117
306
  end
118
307
  return ret
119
308
  end
309
+
310
+ def errno_enoent_inspect
311
+ "ファイルアクセスに失敗しました。ファイルがありません。"
312
+ end
313
+
314
+ def type_error_inspect
315
+ "「#{@method}」への引数のタイプ(型)が正しくありません。"
316
+ end
317
+
318
+ def zero_division_error_inspect
319
+ "割る数が 0 での割り算はできません。"
320
+ end
321
+
322
+ def system_stack_error_inspect
323
+ "システムスタックがあふれました。意図しない無限ループが生じている可能性があります。"
324
+ end
325
+
326
+ Eturem.eturem_class = self
120
327
  end
121
-
122
- set_eturem_class Ja
123
328
  end
124
329
 
125
330
  require "eturem"
126
-
@@ -1,3 +1,3 @@
1
1
  module Eturem
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: eturem
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - nodai2hITC
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-05-04 00:00:00.000000000 Z
11
+ date: 2018-05-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -71,6 +71,7 @@ files:
71
71
  - eturem.gemspec
72
72
  - lib/eturem.rb
73
73
  - lib/eturem/base.rb
74
+ - lib/eturem/en.rb
74
75
  - lib/eturem/ja.rb
75
76
  - lib/eturem/version.rb
76
77
  homepage: https://github.com/nodai2hITC/eturem