Skip to content

Commit cbf002e

Browse files
committed
trying to reduce "complexity" of #raise_inspect (rubychan#135)
1 parent 65b8ab0 commit cbf002e

File tree

1 file changed

+20
-10
lines changed

1 file changed

+20
-10
lines changed

lib/coderay/scanner.rb

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -294,9 +294,7 @@ def reset_instance
294294
tokens:
295295
%s
296296
297-
current line: %d column: %d pos: %d
298-
matched: %p state: %p
299-
bol?: %p, eos?: %p
297+
%s
300298
301299
surrounding code:
302300
%p ~~ %p
@@ -306,21 +304,33 @@ def reset_instance
306304
307305
MESSAGE
308306

309-
# Scanner error with additional status information
310-
def raise_inspect message, tokens, state = self.state, ambit = 30, backtrace = caller
311-
raise ScanError, SCAN_ERROR_MESSAGE % raise_inspect_arguments(message, tokens, state, ambit), backtrace
312-
end
313-
314307
def raise_inspect_arguments message, tokens, state, ambit
315308
return File.basename(caller[0]),
316309
message,
317310
tokens_size(tokens),
318311
tokens_last(tokens, 10).map(&:inspect).join("\n"),
312+
scanner_state_info(state),
313+
binary_string[pos - ambit, ambit],
314+
binary_string[pos, ambit]
315+
end
316+
317+
SCANNER_STATE_INFO = <<-INFO
318+
current line: %d column: %d pos: %d
319+
matched: %p state: %p
320+
bol?: %p, eos?: %p
321+
INFO
322+
323+
def scanner_state_info state
324+
SCANNER_STATE_INFO % [
319325
line, column, pos,
320326
matched, state || 'No state given!',
321327
bol?, eos?,
322-
binary_string[pos - ambit, ambit],
323-
binary_string[pos, ambit]
328+
]
329+
end
330+
331+
# Scanner error with additional status information
332+
def raise_inspect message, tokens, state = self.state, ambit = 30, backtrace = caller
333+
raise ScanError, SCAN_ERROR_MESSAGE % raise_inspect_arguments(message, tokens, state, ambit), backtrace
324334
end
325335

326336
def tokens_size tokens

0 commit comments

Comments
 (0)