From a2834bb05c4ab5bd32437f333a26f8286438ade4 Mon Sep 17 00:00:00 2001 From: murphy Date: Sun, 16 Apr 2006 00:42:38 +0000 Subject: =?UTF-8?q?All=20scanners=20revisited=20not=20to=20produce=20error?= =?UTF-8?q?s=20unless=20in=20DEBUG=20mode.=20[thx@Daniel]=20Fixed=20numeri?= =?UTF-8?q?zation=20for=20input=20not=20ending=20with=20\n.=20Added=20test?= =?UTF-8?q?=20cases=20in=20C=20scanner=20tests.=20Added=20WoN=C3=A1Do=20as?= =?UTF-8?q?=20contributer=20for=20last=20Ruby=20scanner=20fix.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Updated TODO. --- lib/coderay/encoders/html/numerization.rb | 14 +++++++++++--- lib/coderay/scanners/c.rb | 6 +++++- lib/coderay/scanners/delphi.rb | 6 +++++- lib/coderay/scanners/html.rb | 2 +- lib/coderay/scanners/ruby.rb | 6 ++++-- 5 files changed, 26 insertions(+), 8 deletions(-) (limited to 'lib/coderay') diff --git a/lib/coderay/encoders/html/numerization.rb b/lib/coderay/encoders/html/numerization.rb index 19c760e..1e1f952 100644 --- a/lib/coderay/encoders/html/numerization.rb +++ b/lib/coderay/encoders/html/numerization.rb @@ -48,9 +48,6 @@ module Encoders raise ArgumentError, 'Invalid value %p for :bolding; false or Integer expected.' % bold_every end - line_count = count("\n") - line_count += 1 unless self[-1] == ?\n - case mode when :inline max_width = (start + line_count).to_s.size @@ -106,6 +103,17 @@ module Encoders self end + def line_count + line_count = count("\n") + position_of_last_newline = rindex(?\n) + if position_of_last_newline + after_last_newline = self[position_of_last_newline + 1 .. -1] + ends_with_newline = after_last_newline[/\A(?:<\/span>)*\z/] + line_count += 1 if not ends_with_newline + end + line_count + end + end end diff --git a/lib/coderay/scanners/c.rb b/lib/coderay/scanners/c.rb index ae7ef83..ae0af73 100644 --- a/lib/coderay/scanners/c.rb +++ b/lib/coderay/scanners/c.rb @@ -135,7 +135,11 @@ module CodeRay module Scanners end match ||= matched - raise_inspect [match, kind], tokens if kind == :error + if $DEBUG and (not kind or kind == :error) + raise_inspect 'Error token %p in line %d' % + [[match, kind], line], tokens + end + raise_inspect 'Empty token', tokens unless match tokens << [match, kind] diff --git a/lib/coderay/scanners/delphi.rb b/lib/coderay/scanners/delphi.rb index 77c3839..d02c632 100644 --- a/lib/coderay/scanners/delphi.rb +++ b/lib/coderay/scanners/delphi.rb @@ -109,7 +109,11 @@ module CodeRay module Scanners end match ||= matched - raise [match, kind], tokens if kind == :error + if $DEBUG and (not kind or kind == :error) + raise_inspect 'Error token %p in line %d' % + [[match, kind], line], tokens + end + raise_inspect 'Empty token', tokens unless match tokens << [match, kind] diff --git a/lib/coderay/scanners/html.rb b/lib/coderay/scanners/html.rb index a1efa9e..e8eea61 100644 --- a/lib/coderay/scanners/html.rb +++ b/lib/coderay/scanners/html.rb @@ -145,7 +145,7 @@ module CodeRay module Scanners match ||= matched if $DEBUG and (not kind or kind == :error) raise_inspect 'Error token %p in line %d' % - [[match, kind], line], tokens + [[match, kind], line], tokens end raise_inspect 'Empty token', tokens unless match diff --git a/lib/coderay/scanners/ruby.rb b/lib/coderay/scanners/ruby.rb index 8127944..1dbcb17 100644 --- a/lib/coderay/scanners/ruby.rb +++ b/lib/coderay/scanners/ruby.rb @@ -366,9 +366,11 @@ module CodeRay module Scanners fancy_allowed = fancy_allowed == :set last_token_dot = last_token_dot == :set - if $DEBUG - raise_inspect 'error token %p in line %d' % [[match, type], line], tokens if not type or type == :error + if $DEBUG and (not kind or kind == :error) + raise_inspect 'Error token %p in line %d' % + [[match, kind], line], tokens end + raise_inspect 'Empty token', tokens unless match tokens << [match, type] -- cgit v1.2.1