diff options
author | murphy <murphy@rubychan.de> | 2006-03-23 00:05:58 +0000 |
---|---|---|
committer | murphy <murphy@rubychan.de> | 2006-03-23 00:05:58 +0000 |
commit | 7863986fad84f56ba537ce3714d614c33391fd85 (patch) | |
tree | d1fc02f8da8dcb55dd1018203adf18d9b0d31ee7 /lib/coderay/scanner.rb | |
parent | 2ee9927772880382e8ab3819805e6e3c62723395 (diff) | |
download | coderay-7863986fad84f56ba537ce3714d614c33391fd85.tar.gz |
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.
Diffstat (limited to 'lib/coderay/scanner.rb')
-rw-r--r-- | lib/coderay/scanner.rb | 18 |
1 files changed, 10 insertions, 8 deletions
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
|