diff options
Diffstat (limited to 'lib/coderay')
-rw-r--r-- | lib/coderay/encoder.rb | 2 | ||||
-rw-r--r-- | lib/coderay/encoders/html.rb | 2 | ||||
-rw-r--r-- | lib/coderay/encoders/html/numerization.rb | 10 | ||||
-rw-r--r-- | lib/coderay/helpers/plugin.rb | 4 | ||||
-rw-r--r-- | lib/coderay/scanners/ruby.rb | 36 | ||||
-rw-r--r-- | lib/coderay/scanners/ruby/patterns.rb | 17 |
6 files changed, 38 insertions, 33 deletions
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 = "<span class=\"no\">#{indent}#{line_number}</span> " - line += 1 + line_number_text = bolding.call line_number + indent = ' ' * (max_width - line_number.to_s.size) # TODO: Optimize (10^x) + res = "<span class=\"no\">#{indent}#{line_number_text}</span> " + 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 '<Host ID>/<Plugin ID>' # # 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(/<</) + kind = :operator + else + state = :initial + if match = scan(/ (?:#{patterns::IDENT}::)* #{patterns::IDENT} /ox) + kind = :class + else + next + end + end + elsif state == :undef_expected state = :undef_comma_expected if match = scan(/#{patterns::METHOD_NAME_EX}/o) @@ -307,6 +318,15 @@ module Scanners next end + elsif state == :alias_expected + if match = scan(/(#{patterns::METHOD_NAME_OR_SYMBOL})([ \t]+)(#{patterns::METHOD_NAME_OR_SYMBOL})/o) + tokens << [self[1], (self[1][0] == ?: ? :symbol : :method)] + tokens << [self[2], :space] + tokens << [self[3], (self[3][0] == ?: ? :symbol : :method)] + end + state = :initial + next + elsif state == :undef_comma_expected if match = scan(/,/) kind = :operator @@ -316,18 +336,6 @@ module Scanners next end - elsif state == :module_expected - if match = scan(/<</) - kind = :operator - else - state = :initial - if match = scan(/ (?:#{patterns::IDENT}::)* #{patterns::IDENT} /ox) - kind = :class - else - next - end - end - end # }}} diff --git a/lib/coderay/scanners/ruby/patterns.rb b/lib/coderay/scanners/ruby/patterns.rb index 39962ec..88fd1e0 100644 --- a/lib/coderay/scanners/ruby/patterns.rb +++ b/lib/coderay/scanners/ruby/patterns.rb @@ -14,19 +14,14 @@ module Scanners DEF_KEYWORDS = %w[ def ] UNDEF_KEYWORDS = %w[ undef ] + ALIAS_KEYWORDS = %w[ alias ] MODULE_KEYWORDS = %w[class module] DEF_NEW_STATE = WordList.new(:initial). add(DEF_KEYWORDS, :def_expected). add(UNDEF_KEYWORDS, :undef_expected). + add(ALIAS_KEYWORDS, :alias_expected). add(MODULE_KEYWORDS, :module_expected) - IDENTS_ALLOWING_REGEXP = %w[ - and or not while until unless if then elsif when sub sub! gsub gsub! - scan slice slice! split - ] - REGEXP_ALLOWED = WordList.new(false). - add(IDENTS_ALLOWING_REGEXP, :set) - PREDEFINED_CONSTANTS = %w[ nil true false self DATA ARGV ARGF __FILE__ __LINE__ @@ -41,12 +36,13 @@ module Scanners METHOD_NAME = / #{IDENT} [?!]? /ox METHOD_NAME_OPERATOR = / \*\*? # multiplication and power - | [-+]@? # plus, minus - | [\/%&|^`~] # division, modulo or format strings, &and, |or, ^xor, `system`, tilde + | [-+~]@? # plus, minus, tilde with and without @ + | [\/%&|^`] # division, modulo or format strings, &and, |or, ^xor, `system` | \[\]=? # array getter and setter | << | >> # 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} | . ) ) |