From 7863986fad84f56ba537ce3714d614c33391fd85 Mon Sep 17 00:00:00 2001 From: murphy Date: Thu, 23 Mar 2006 00:05:58 +0000 Subject: HTML Encoder: inline numerization corrected. New demo: demo/demo_html_list.rb. Some demos adjusted. C Scanner: error messages fixed. Rakefile: test_demos now in debug mode. test/suite.rb is using reusable Scanners now. --- lib/coderay/scanner.rb | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) (limited to 'lib/coderay/scanner.rb') diff --git a/lib/coderay/scanner.rb b/lib/coderay/scanner.rb index 5ff07a0..16998f2 100644 --- a/lib/coderay/scanner.rb +++ b/lib/coderay/scanner.rb @@ -91,14 +91,15 @@ module CodeRay # TokenStream with the +block+ as callback to handle the tokens. # # Else, a Tokens object is used. - def initialize code, options = {}, &block + def initialize code='', options = {}, &block @options = self.class::DEFAULT_OPTIONS.merge options raise "I am only the basic Scanner class. I can't scan "\ "anything. :( Use my subclasses." if self.class == Scanner # I love this hack. It seems to silence # all dos/unix/mac newline problems. - super code.gsub(/\r\n?/, "\n") + code = code.gsub(/\r\n?/, "\n") if code.index ?\r + super code if @options[:stream] warn "warning in CodeRay::Scanner.new: :stream is set, "\ @@ -117,12 +118,13 @@ module CodeRay def reset super - reset_tokens + reset_instance end - def string= str - super - reset_tokens + def string= code + code = code.gsub(/\r\n?/, "\n") if code.index ?\r + super code + reset_instance end # Scans the code and returns all tokens in a Tokens object. @@ -168,10 +170,10 @@ module CodeRay "#{self.class}#scan_tokens not implemented." end - def reset_tokens + def reset_instance @tokens.clear @cached_tokens = nil - end + end # Scanner error with additional status information def raise_inspect msg, tokens, ambit = 30 -- cgit v1.2.1