Skip to content

Commit

Permalink
trying to reduce "complexity" of #raise_inspect (#135)
Browse files Browse the repository at this point in the history
  • Loading branch information
korny committed Jun 10, 2013
1 parent 65a4b4d commit 65b8ab0
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions lib/coderay/scanner.rb
Expand Up @@ -307,25 +307,27 @@ def reset_instance
MESSAGE

# Scanner error with additional status information
def raise_inspect msg, tokens, state = self.state, ambit = 30, backtrace = caller
raise ScanError, SCAN_ERROR_MESSAGE % [
File.basename(caller[0]),
msg,
tokens_size,
tokens_last(10).map(&:inspect).join("\n"),
def raise_inspect message, tokens, state = self.state, ambit = 30, backtrace = caller
raise ScanError, SCAN_ERROR_MESSAGE % raise_inspect_arguments(message, tokens, state, ambit), backtrace
end

def raise_inspect_arguments message, tokens, state, ambit
return File.basename(caller[0]),
message,
tokens_size(tokens),
tokens_last(tokens, 10).map(&:inspect).join("\n"),
line, column, pos,
matched, state || 'No state given!',
bol?, eos?,
binary_string[pos - ambit, ambit],
binary_string[pos, ambit],
], backtrace
binary_string[pos, ambit]
end

def tokens_size
def tokens_size tokens
tokens.size if tokens.respond_to?(:size)
end

def tokens_last n
def tokens_last tokens, n
tokens.respond_to?(:last) ? tokens.last(n) : []
end

Expand Down

0 comments on commit 65b8ab0

Please sign in to comment.