summaryrefslogtreecommitdiff
path: root/lib/coderay/scanner.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/coderay/scanner.rb')
-rw-r--r--lib/coderay/scanner.rb29
1 files changed, 18 insertions, 11 deletions
diff --git a/lib/coderay/scanner.rb b/lib/coderay/scanner.rb
index 62327c7..5993b4c 100644
--- a/lib/coderay/scanner.rb
+++ b/lib/coderay/scanner.rb
@@ -117,9 +117,6 @@ module CodeRay
setup
end
- # More mnemonic accessor name for the input string.
- alias code string
-
def reset
super
reset_instance
@@ -131,6 +128,10 @@ module CodeRay
reset_instance
end
+ # More mnemonic accessor name for the input string.
+ alias code string
+ alias code= string=
+
# Scans the code and returns all tokens in a Tokens object.
def tokenize new_string=nil, options = {}
options = @options.merge(options)
@@ -148,6 +149,11 @@ module CodeRay
def tokens
@cached_tokens ||= tokenize
end
+
+ # Whether the scanner is in streaming mode.
+ def streaming?
+ !!@options[:stream]
+ end
# Traverses the tokens.
def each &block
@@ -195,7 +201,7 @@ module CodeRay
raise ScanError, <<-EOE % [
-***ERROR in %s: %s
+***ERROR in %s: %s (after %d tokens)
tokens:
%s
@@ -211,13 +217,14 @@ surrounding code:
***ERROR***
EOE
- File.basename(caller[0]),
- msg,
- tokens.last(10).map { |t| t.inspect }.join("\n"),
- line, pos,
- matched, state, bol?, eos?,
- string[pos-ambit,ambit],
- string[pos,ambit],
+ File.basename(caller[0]),
+ msg,
+ tokens.size,
+ tokens.last(10).map { |t| t.inspect }.join("\n"),
+ line, pos,
+ matched, state, bol?, eos?,
+ string[pos-ambit,ambit],
+ string[pos,ambit],
]
end