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/duo.rb | 5 +++++ lib/coderay/encoders/html/numerization.rb | 4 +++- lib/coderay/scanner.rb | 18 ++++++++++-------- lib/coderay/scanners/c.rb | 6 +++--- 4 files changed, 21 insertions(+), 12 deletions(-) (limited to 'lib/coderay') diff --git a/lib/coderay/duo.rb b/lib/coderay/duo.rb index 8187277..1957c95 100644 --- a/lib/coderay/duo.rb +++ b/lib/coderay/duo.rb @@ -1,5 +1,10 @@ module CodeRay + # = Duo + # + # $Id: scanner.rb 123 2006-03-21 14:46:34Z murphy $ + # + # TODO: Doc. class Duo attr_accessor :scanner, :encoder diff --git a/lib/coderay/encoders/html/numerization.rb b/lib/coderay/encoders/html/numerization.rb index c5d96f3..19c760e 100644 --- a/lib/coderay/encoders/html/numerization.rb +++ b/lib/coderay/encoders/html/numerization.rb @@ -57,8 +57,10 @@ module Encoders line = start gsub!(/^/) do line_number = bolding.call line + indent = ' ' * (max_width - line.to_s.size) + res = "#{indent}#{line_number} " line += 1 - "#{ line_number.rjust(max_width) } " + res end when :table 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 diff --git a/lib/coderay/scanners/c.rb b/lib/coderay/scanners/c.rb index 8fae829..5764254 100644 --- a/lib/coderay/scanners/c.rb +++ b/lib/coderay/scanners/c.rb @@ -110,7 +110,7 @@ module CodeRay module Scanners kind = :error state = :initial else - raise "else case \" reached; %p not handled." % peek(1), tokens + raise_inspect "else case \" reached; %p not handled." % peek(1), tokens end elsif state == :include_expected @@ -128,12 +128,12 @@ module CodeRay module Scanners end else - raise 'else-case reached', tokens + raise_inspect 'else-case reached', tokens end match ||= matched - raise [match, kind], tokens if kind == :error + raise_inspect [match, kind], tokens if kind == :error tokens << [match, kind] -- cgit v1.2.1