From e127b7d57b06554e708752bbbc2a85e833633c26 Mon Sep 17 00:00:00 2001 From: murphy Date: Mon, 7 Jan 2008 14:42:47 +0000 Subject: Lib: - Encoder: removed a warning - Encoders::HTML: don't shadow outer variable - Plugin: move require_plugin into class namespace - Ruby Scanner: - "alias" keyword recognition - better regexp/division distinction - recognize ~, !, !=, and !~ as method names (partly Ruby 1.9 only) - reordered states for speed Tests: - updated coderay-suite to use gem instead of require_gem - general improvements (more colors!, new parameter: new, new syntax lang.test for only and new) - fixed ruby suite - adjusted a lot of Ruby tests (alias uses methods now) - new tests: ruby/operators, ruby/regexp Samples: - fixed/updated ('bout time) Rake tasks: - updated to use new rubygems API --- lib/coderay/encoder.rb | 2 +- lib/coderay/encoders/html.rb | 2 +- lib/coderay/encoders/html/numerization.rb | 10 ++++----- lib/coderay/helpers/plugin.rb | 4 ++-- lib/coderay/scanners/ruby.rb | 36 +++++++++++++++++++------------ lib/coderay/scanners/ruby/patterns.rb | 17 ++++++--------- 6 files changed, 38 insertions(+), 33 deletions(-) (limited to 'lib/coderay') diff --git a/lib/coderay/encoder.rb b/lib/coderay/encoder.rb index e543c8c..ced0f6c 100644 --- a/lib/coderay/encoder.rb +++ b/lib/coderay/encoder.rb @@ -140,7 +140,7 @@ module CodeRay else raise 'Unknown token text type: %p' % text end - @out << out if @out + @out << out if defined?(@out) && @out end def text_token text, kind diff --git a/lib/coderay/encoders/html.rb b/lib/coderay/encoders/html.rb index 4981585..2edcf1d 100644 --- a/lib/coderay/encoders/html.rb +++ b/lib/coderay/encoders/html.rb @@ -136,7 +136,7 @@ module Encoders when :debug classes.inspect end - " title=\"#{title}\"" + title ? " title=\"#{title}\"" : '' end def setup options diff --git a/lib/coderay/encoders/html/numerization.rb b/lib/coderay/encoders/html/numerization.rb index 1e4a4ed..d784bbe 100644 --- a/lib/coderay/encoders/html/numerization.rb +++ b/lib/coderay/encoders/html/numerization.rb @@ -51,12 +51,12 @@ module Encoders case mode when :inline max_width = (start + line_count).to_s.size - line = start + line_number = start gsub!(/^/) do - line_number = bolding.call line - indent = ' ' * (max_width - line.to_s.size) - res = "#{indent}#{line_number} " - line += 1 + line_number_text = bolding.call line_number + indent = ' ' * (max_width - line_number.to_s.size) # TODO: Optimize (10^x) + res = "#{indent}#{line_number_text} " + line_number += 1 res end diff --git a/lib/coderay/helpers/plugin.rb b/lib/coderay/helpers/plugin.rb index e6017d5..e1a945f 100644 --- a/lib/coderay/helpers/plugin.rb +++ b/lib/coderay/helpers/plugin.rb @@ -22,7 +22,7 @@ module CodeRay # # Generators[:fancy] #-> FancyGenerator # # or -# require_plugin 'Generators/fancy' +# CodeRay.require_plugin 'Generators/fancy' module PluginHost # Raised if Encoders::[] fails because: @@ -318,7 +318,7 @@ end # CodeRay.require_plugin '/' # # Returns the loaded plugin. -def require_plugin path +def self.require_plugin path host_id, plugin_id = path.split '/', 2 host = PluginHost.host_by_id(host_id) raise PluginHost::HostNotFound, diff --git a/lib/coderay/scanners/ruby.rb b/lib/coderay/scanners/ruby.rb index d497731..f8f27b7 100644 --- a/lib/coderay/scanners/ruby.rb +++ b/lib/coderay/scanners/ruby.rb @@ -168,8 +168,7 @@ module Scanners end end ## experimental! - value_expected = :set if - patterns::REGEXP_ALLOWED[match] or check(/#{patterns::VALUE_FOLLOWS}/o) + value_expected = :set if check(/#{patterns::VALUE_FOLLOWS}/o) elsif last_token_dot and match = scan(/#{patterns::METHOD_NAME_OPERATOR}/o) kind = :ident @@ -286,6 +285,18 @@ module Scanners next end + elsif state == :module_expected + if match = scan(/<> # append or shift left, shift right | <=?>? | >=? # comparison, rocket operator - | ===? # simple equality and case equality + | ===? | =~ # simple equality, case equality, match + | ![~=@]? # negation with and without @, not-equal and not-match /ox METHOD_NAME_EX = / #{IDENT} (?:[?!]|=(?!>))? | #{METHOD_NAME_OPERATOR} /ox INSTANCE_VARIABLE = / @ #{IDENT} /ox @@ -83,6 +79,7 @@ module Scanners | ['"] ) /ox + METHOD_NAME_OR_SYMBOL = / #{METHOD_NAME_EX} | #{SYMBOL} /ox # TODO investigste \M, \c and \C escape sequences # (?: M-\\C-|C-\\M-|M-\\c|c\\M-|c|C-|M-)? (?: \\ (?: [0-7]{3} | x[0-9A-Fa-f]{2} | . ) ) -- cgit v1.2.1