summaryrefslogtreecommitdiff
path: root/lib/coderay
diff options
context:
space:
mode:
authorKornelius Kalnbach <murphy@rubychan.de>2013-06-10 18:23:17 +0200
committerKornelius Kalnbach <murphy@rubychan.de>2013-06-10 18:23:17 +0200
commit65a4b4dfe93e9be0d9f753f063b8f77f8be5af77 (patch)
treeb05d46a6dce4f95318f502958e307478de61b6d0 /lib/coderay
parentc386e044cff195ae922a0b7625dfa498954bf772 (diff)
downloadcoderay-65a4b4dfe93e9be0d9f753f063b8f77f8be5af77.tar.gz
trying to reduce "complexity" of #raise_inspect (#135)
Diffstat (limited to 'lib/coderay')
-rw-r--r--lib/coderay/scanner.rb14
1 files changed, 11 insertions, 3 deletions
diff --git a/lib/coderay/scanner.rb b/lib/coderay/scanner.rb
index 9a5be58..68451ae 100644
--- a/lib/coderay/scanner.rb
+++ b/lib/coderay/scanner.rb
@@ -289,7 +289,7 @@ module CodeRay
SCAN_ERROR_MESSAGE = <<-MESSAGE
-***ERROR in %s: %s (after %d tokens)
+***ERROR in %s: %s (after %s tokens)
tokens:
%s
@@ -311,8 +311,8 @@ surrounding code:
raise ScanError, SCAN_ERROR_MESSAGE % [
File.basename(caller[0]),
msg,
- tokens.respond_to?(:size) ? tokens.size : '[tokens.size undefined]',
- tokens.respond_to?(:last) ? tokens.last(10).map(&:inspect).join("\n") : '[tokens.last undefined]',
+ tokens_size,
+ tokens_last(10).map(&:inspect).join("\n"),
line, column, pos,
matched, state || 'No state given!',
bol?, eos?,
@@ -321,6 +321,14 @@ surrounding code:
], backtrace
end
+ def tokens_size
+ tokens.size if tokens.respond_to?(:size)
+ end
+
+ def tokens_last n
+ tokens.respond_to?(:last) ? tokens.last(n) : []
+ end
+
# Shorthand for scan_until(/\z/).
# This method also avoids a JRuby 1.9 mode bug.
def scan_rest