summaryrefslogtreecommitdiff
path: root/lib/coderay/scanner.rb
diff options
context:
space:
mode:
authormurphy <murphy@rubychan.de>2010-05-01 01:31:56 +0000
committermurphy <murphy@rubychan.de>2010-05-01 01:31:56 +0000
commitfa975bbf5d40644d987887b4cf273a3f02612f03 (patch)
tree5ffada8100c1b6cb9057dec7985daaf6d1851396 /lib/coderay/scanner.rb
parente271dc13633fa6dba9fb87f415d72505af0cc88c (diff)
downloadcoderay-fa975bbf5d40644d987887b4cf273a3f02612f03.tar.gz
Direct Streaming! See #142 and Changes.textile.
Diffstat (limited to 'lib/coderay/scanner.rb')
-rw-r--r--lib/coderay/scanner.rb21
1 files changed, 4 insertions, 17 deletions
diff --git a/lib/coderay/scanner.rb b/lib/coderay/scanner.rb
index 165fd7f..286561d 100644
--- a/lib/coderay/scanner.rb
+++ b/lib/coderay/scanner.rb
@@ -61,11 +61,6 @@ module CodeRay
class << self
- # Returns if the Scanner can be used in streaming mode.
- def streamable?
- is_a? Streamable
- end
-
def normify code
code = code.to_s.dup
# try using UTF-8
@@ -115,9 +110,6 @@ module CodeRay
# overwrite default options here.)
# * +block+ is the callback for streamed highlighting.
#
- # If you set :stream to +true+ in the options, the Scanner uses a
- # TokenStream with the +block+ as callback to handle the tokens.
- #
# Else, a Tokens object is used.
def initialize code='', options = {}, &block
raise "I am only the basic Scanner class. I can't scan "\
@@ -129,16 +121,13 @@ module CodeRay
@tokens = options[:tokens]
if @options[:stream]
- warn "warning in CodeRay::Scanner.new: :stream is set, "\
- "but no block was given" unless block_given?
- raise NotStreamableError, self unless kind_of? Streamable
- @tokens ||= TokenStream.new(&block)
+ raise NotImplementedError unless @tokens.is_a? Encoders::Encoder
else
warn "warning in CodeRay::Scanner.new: Block given, "\
"but :stream is #{@options[:stream]}" if block_given?
@tokens ||= Tokens.new
end
- @tokens.scanner = self
+ @tokens.scanner = self if @tokens.respond_to? :scanner=
setup
end
@@ -162,7 +151,7 @@ module CodeRay
# Returns the Plugin ID for this scanner.
def lang
- self.class.plugin_id
+ self.class.plugin_id.to_s
end
# Scans the code and returns all tokens in a Tokens object.
@@ -191,8 +180,6 @@ module CodeRay
# Traverses the tokens.
def each &block
- raise ArgumentError,
- 'Cannot traverse TokenStream.' if @options[:stream]
tokens.each(&block)
end
include Enumerable
@@ -246,7 +233,7 @@ module CodeRay
# Resets the scanner.
def reset_instance
- @tokens.clear unless @options[:keep_tokens]
+ @tokens.clear if @tokens.respond_to?(:clear) && !@options[:keep_tokens]
@cached_tokens = nil
@bin_string = nil if defined? @bin_string
end