diff options
author | murphy <murphy@rubychan.de> | 2008-01-07 14:42:47 +0000 |
---|---|---|
committer | murphy <murphy@rubychan.de> | 2008-01-07 14:42:47 +0000 |
commit | e127b7d57b06554e708752bbbc2a85e833633c26 (patch) | |
tree | ccd44c344594ccacdcd95a1e1dfc35488cb2c58d | |
parent | bbbbc70a0b2efcd03bbcaf4e08ac139e7969e608 (diff) | |
download | coderay-e127b7d57b06554e708752bbbc2a85e833633c26.tar.gz |
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
27 files changed, 334 insertions, 153 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} | . ) ) diff --git a/rake_tasks/gem.rake b/rake_tasks/gem.rake index cf729a8..91483a2 100644 --- a/rake_tasks/gem.rake +++ b/rake_tasks/gem.rake @@ -87,7 +87,7 @@ namespace :gem do $gemfile = "coderay-#$version.gem"
Dir[GEMDIR + '/*.gem'].each { |g| rm g }
cp "pkg/#$gemfile", GEMDIR
- system 'ruby -S index_gem_repository.rb -d gem_server --no-quick'
+ system 'gem generate_index -d gem_server'
end
desc 'Upload gemfile to ' + FTP_DOMAIN
@@ -109,7 +109,7 @@ namespace :gem do desc 'Build the Gem and install it locally'
task :install => :make do
- system "ruby -S gem install --no-rdoc pkg/#{$gemfile}"
+ system "gem install --no-rdoc pkg/#{$gemfile}"
end
end
diff --git a/sample/css.expected b/sample/css.expected index 92441e0..bda52ff 100644 --- a/sample/css.expected +++ b/sample/css.expected @@ -27,12 +27,14 @@ ol.CodeRay li { white-space: pre } .CodeRay .code pre { overflow: auto } +.CodeRay .debug { color:white ! important; background:blue ! important; } + .CodeRay .af { color:#00C } .CodeRay .an { color:#007 } .CodeRay .av { color:#700 } .CodeRay .aw { color:#C00 } .CodeRay .bi { color:#509; font-weight:bold } -.CodeRay .c { color:#888 } +.CodeRay .c { color:#666; } .CodeRay .ch { color:#04D } .CodeRay .ch .k { color:#04D } @@ -68,7 +70,7 @@ ol.CodeRay li { white-space: pre } .CodeRay .la { color:#970; font-weight:bold } .CodeRay .lv { color:#963 } .CodeRay .oc { color:#40E; font-weight:bold } -.CodeRay .on { color:#000; font-weight:bold } +.CodeRay .of { color:#000; font-weight:bold } .CodeRay .op { } .CodeRay .pc { color:#038; font-weight:bold } .CodeRay .pd { color:#369; font-weight:bold } diff --git a/sample/div.expected b/sample/div.expected index ec9676d..ef5ff90 100644 --- a/sample/div.expected +++ b/sample/div.expected @@ -2,14 +2,14 @@ <div class="code"><pre><span style="color:#080; font-weight:bold">for</span> a <span style="color:#080; font-weight:bold">in</span> <span style="color:#00D; font-weight:bold">0</span>..<span style="color:#00D; font-weight:bold">255</span> a = a.chr <span style="color:#080; font-weight:bold">begin</span> - x = eval(<span style="background-color:#fff0f0"><span style="color:#710">"</span><span style="color:#D20">?</span><span style="color:#04D">\\</span><span style="background-color:#fff0f0"><span style="color:#710">#{</span>a<span style="color:#710">}</span></span><span style="color:#710">"</span></span>) + x = eval(<span style="background-color:#fff0f0"><span style="color:#710">"</span><span style="color:#D20">?</span><span style="color:#04D">\\</span><span style="background: #eee"><span style="font-weight: bold; color: #888">#{</span>a<span style="font-weight: bold; color: #888">}</span></span><span style="color:#710">"</span></span>) <span style="color:#080; font-weight:bold">if</span> x == a[<span style="color:#00D; font-weight:bold">0</span>] <span style="color:#080; font-weight:bold">next</span> <span style="color:#080; font-weight:bold">else</span> - print <span style="background-color:#fff0f0"><span style="color:#710">"</span><span style="background-color:#fff0f0"><span style="color:#710">#{</span>a<span style="color:#710">}</span></span><span style="color:#D20">: </span><span style="background-color:#fff0f0"><span style="color:#710">#{</span>x<span style="color:#710">}</span></span><span style="color:#710">"</span></span> + print <span style="background-color:#fff0f0"><span style="color:#710">"</span><span style="background: #eee"><span style="font-weight: bold; color: #888">#{</span>a<span style="font-weight: bold; color: #888">}</span></span><span style="color:#D20">: </span><span style="background: #eee"><span style="font-weight: bold; color: #888">#{</span>x<span style="font-weight: bold; color: #888">}</span></span><span style="color:#710">"</span></span> <span style="color:#080; font-weight:bold">end</span> <span style="color:#080; font-weight:bold">rescue</span> <span style="color:#036; font-weight:bold">SyntaxError</span> => boom - print <span style="background-color:#fff0f0"><span style="color:#710">"</span><span style="background-color:#fff0f0"><span style="color:#710">#{</span>a<span style="color:#710">}</span></span><span style="color:#D20">: error</span><span style="color:#710">"</span></span> + print <span style="background-color:#fff0f0"><span style="color:#710">"</span><span style="background: #eee"><span style="font-weight: bold; color: #888">#{</span>a<span style="font-weight: bold; color: #888">}</span></span><span style="color:#D20">: error</span><span style="color:#710">"</span></span> <span style="color:#080; font-weight:bold">end</span> puts <span style="color:#080; font-weight:bold">end</span> diff --git a/sample/highlight.expected b/sample/highlight.expected index 7b50566..07956ad 100644 --- a/sample/highlight.expected +++ b/sample/highlight.expected @@ -33,12 +33,14 @@ ol.CodeRay li { white-space: pre } .CodeRay .code pre { overflow: auto } +.CodeRay .debug { color:white ! important; background:blue ! important; } + .CodeRay .af { color:#00C } .CodeRay .an { color:#007 } .CodeRay .av { color:#700 } .CodeRay .aw { color:#C00 } .CodeRay .bi { color:#509; font-weight:bold } -.CodeRay .c { color:#888 } +.CodeRay .c { color:#666; } .CodeRay .ch { color:#04D } .CodeRay .ch .k { color:#04D } @@ -67,14 +69,14 @@ ol.CodeRay li { white-space: pre } .CodeRay .il { background: #eee } .CodeRay .il .il { background: #ddd } .CodeRay .il .il .il { background: #ccc } -.CodeRay .il .dl { font-weight: bold ! important; color: #888 ! important } +.CodeRay .il .idl { font-weight: bold; color: #888 } .CodeRay .in { color:#B2B; font-weight:bold } .CodeRay .iv { color:#33B } .CodeRay .la { color:#970; font-weight:bold } .CodeRay .lv { color:#963 } .CodeRay .oc { color:#40E; font-weight:bold } -.CodeRay .on { color:#000; font-weight:bold } +.CodeRay .of { color:#000; font-weight:bold } .CodeRay .op { } .CodeRay .pc { color:#038; font-weight:bold } .CodeRay .pd { color:#369; font-weight:bold } @@ -136,9 +138,9 @@ ol.CodeRay li { white-space: pre } </tt>puts <span style="background-color:#fff0f0"><span style="color:#710"><<HTML</span></span><span style="background-color:#fff0f0"><span style="color:#D20"><tt> </tt><html><tt> </tt><head><tt> -</tt></span><span style="background-color:#fff0f0"><span style="color:#710">#{</span>output.stylesheet <span style="color:#038; font-weight:bold">true</span><span style="color:#710">}</span></span><span style="color:#D20"><tt> +</tt></span><span style="background: #eee"><span style="font-weight: bold; color: #888">#{</span>output.stylesheet <span style="color:#038; font-weight:bold">true</span><span style="font-weight: bold; color: #888">}</span></span><span style="color:#D20"><tt> </tt><body><tt> -</tt></span><span style="background-color:#fff0f0"><span style="color:#710">#{</span>output<span style="color:#710">}</span></span><span style="color:#D20"><tt> +</tt></span><span style="background: #eee"><span style="font-weight: bold; color: #888">#{</span>output<span style="font-weight: bold; color: #888">}</span></span><span style="color:#D20"><tt> </tt></body><tt> </tt></html></span><span style="color:#710"><tt> </tt>HTML</span></span><tt> diff --git a/sample/html.expected b/sample/html.expected index 1e29612..4e4c99a 100644 --- a/sample/html.expected +++ b/sample/html.expected @@ -34,12 +34,14 @@ ol.CodeRay li { white-space: pre } .CodeRay .code pre { overflow: auto } +.CodeRay .debug { color:white ! important; background:blue ! important; } + .CodeRay .af { color:#00C } .CodeRay .an { color:#007 } .CodeRay .av { color:#700 } .CodeRay .aw { color:#C00 } .CodeRay .bi { color:#509; font-weight:bold } -.CodeRay .c { color:#888 } +.CodeRay .c { color:#666; } .CodeRay .ch { color:#04D } .CodeRay .ch .k { color:#04D } @@ -68,14 +70,14 @@ ol.CodeRay li { white-space: pre } .CodeRay .il { background: #eee } .CodeRay .il .il { background: #ddd } .CodeRay .il .il .il { background: #ccc } -.CodeRay .il .dl { font-weight: bold ! important; color: #888 ! important } +.CodeRay .il .idl { font-weight: bold; color: #888 } .CodeRay .in { color:#B2B; font-weight:bold } .CodeRay .iv { color:#33B } .CodeRay .la { color:#970; font-weight:bold } .CodeRay .lv { color:#963 } .CodeRay .oc { color:#40E; font-weight:bold } -.CodeRay .on { color:#000; font-weight:bold } +.CodeRay .of { color:#000; font-weight:bold } .CodeRay .op { } .CodeRay .pc { color:#038; font-weight:bold } .CodeRay .pd { color:#369; font-weight:bold } @@ -537,9 +539,9 @@ ol.CodeRay li { white-space: pre } </tt> add(<span class="co">RESERVED_WORDS</span>, <span class="sy">:reserved</span>).<tt> </tt> add(<span class="co">PREDEFINED_CONSTANTS</span>, <span class="sy">:pre_constant</span>)<tt> </tt><tt> -</tt> <span class="co">METHOD_NAME</span> = <span class="rx"><span class="dl">/</span><span class="k"> </span><span class="il"><span class="dl">#{</span><span class="co">IDENT</span><span class="dl">}</span></span><span class="k"> [?!]? </span><span class="dl">/</span><span class="mod">xo</span></span><tt> +</tt> <span class="co">METHOD_NAME</span> = <span class="rx"><span class="dl">/</span><span class="k"> </span><span class="il"><span class="idl">#{</span><span class="co">IDENT</span><span class="idl">}</span></span><span class="k"> [?!]? </span><span class="dl">/</span><span class="mod">xo</span></span><tt> </tt> <span class="co">METHOD_NAME_EX</span> = <span class="rx"><span class="dl">/</span><span class="k"><tt> -</tt> </span><span class="il"><span class="dl">#{</span><span class="co">METHOD_NAME</span><span class="dl">}</span></span><span class="k"> # common methods: split, foo=, empty?, gsub!<tt> +</tt> </span><span class="il"><span class="idl">#{</span><span class="co">METHOD_NAME</span><span class="idl">}</span></span><span class="k"> # common methods: split, foo=, empty?, gsub!<tt> </tt> | </span><span class="ch">\*</span><span class="ch">\*</span><span class="k">? # multiplication and power<tt> </tt> | [-+~]@? # plus, minus<tt> </tt> | [</span><span class="ch">\/</span><span class="k">%&|^`] # division, modulo or format strings, &and, |or, ^xor, `system`<tt> @@ -548,11 +550,11 @@ ol.CodeRay li { white-space: pre } </tt> | << | >> # append or shift left, shift right<tt> </tt> | ===? # simple equality and case equality<tt> </tt> </span><span class="dl">/</span><span class="mod">ox</span></span><tt> -</tt> <span class="co">GLOBAL_VARIABLE</span> = <span class="rx"><span class="dl">/</span><span class="k"> </span><span class="ch">\$</span><span class="k"> (?: </span><span class="il"><span class="dl">#{</span><span class="co">IDENT</span><span class="dl">}</span></span><span class="k"> | </span><span class="ch">\d</span><span class="k">+ | [~&+`'=</span><span class="ch">\/</span><span class="k">,;_.<>!@0$?*":F</span><span class="ch">\\</span><span class="k">] | -[a-zA-Z_0-9] ) </span><span class="dl">/</span><span class="mod">ox</span></span><tt> +</tt> <span class="co">GLOBAL_VARIABLE</span> = <span class="rx"><span class="dl">/</span><span class="k"> </span><span class="ch">\$</span><span class="k"> (?: </span><span class="il"><span class="idl">#{</span><span class="co">IDENT</span><span class="idl">}</span></span><span class="k"> | </span><span class="ch">\d</span><span class="k">+ | [~&+`'=</span><span class="ch">\/</span><span class="k">,;_.<>!@0$?*":F</span><span class="ch">\\</span><span class="k">] | -[a-zA-Z_0-9] ) </span><span class="dl">/</span><span class="mod">ox</span></span><tt> </tt><tt> </tt> <span class="co">DOUBLEQ</span> = <span class="rx"><span class="dl">/</span><span class="k"> " [^"</span><span class="ch">\#</span><span class="ch">\\</span><span class="k">]* (?: (?: </span><span class="ch">\#</span><span class="ch">\{</span><span class="k">.*?</span><span class="ch">\}</span><span class="k"> | </span><span class="ch">\#</span><span class="k">(?:$")? | </span><span class="ch">\\</span><span class="k">. ) [^"</span><span class="ch">\#</span><span class="ch">\\</span><span class="k">]* )* "? </span><span class="dl">/</span><span class="mod">ox</span></span><tt> </tt> <span class="co">SINGLEQ</span> = <span class="rx"><span class="dl">/</span><span class="k"> ' [^'</span><span class="ch">\\</span><span class="k">]* (?: </span><span class="ch">\\</span><span class="k">. [^'</span><span class="ch">\\</span><span class="k">]* )* '? </span><span class="dl">/</span><span class="mod">ox</span></span><tt> -</tt> <span class="co">STRING</span> = <span class="rx"><span class="dl">/</span><span class="k"> </span><span class="il"><span class="dl">#{</span><span class="co">SINGLEQ</span><span class="dl">}</span></span><span class="k"> | </span><span class="il"><span class="dl">#{</span><span class="co">DOUBLEQ</span><span class="dl">}</span></span><span class="k"> </span><span class="dl">/</span><span class="mod">ox</span></span><tt> +</tt> <span class="co">STRING</span> = <span class="rx"><span class="dl">/</span><span class="k"> </span><span class="il"><span class="idl">#{</span><span class="co">SINGLEQ</span><span class="idl">}</span></span><span class="k"> | </span><span class="il"><span class="idl">#{</span><span class="co">DOUBLEQ</span><span class="idl">}</span></span><span class="k"> </span><span class="dl">/</span><span class="mod">ox</span></span><tt> </tt> <span class="co">SHELL</span> = <span class="rx"><span class="dl">/</span><span class="k"> ` [^`</span><span class="ch">\#</span><span class="ch">\\</span><span class="k">]* (?: (?: </span><span class="ch">\#</span><span class="ch">\{</span><span class="k">.*?</span><span class="ch">\}</span><span class="k"> | </span><span class="ch">\#</span><span class="k">(?:$`)? | </span><span class="ch">\\</span><span class="k">. ) [^`</span><span class="ch">\#</span><span class="ch">\\</span><span class="k">]* )* `? </span><span class="dl">/</span><span class="mod">ox</span></span><tt> </tt> <span class="co">REGEXP</span> = <span class="rx"><span class="dl">/</span><span class="k"> </span><span class="ch">\/</span><span class="k"> [^</span><span class="ch">\/</span><span class="ch">\#</span><span class="ch">\\</span><span class="k">]* (?: (?: </span><span class="ch">\#</span><span class="ch">\{</span><span class="k">.*?</span><span class="ch">\}</span><span class="k"> | </span><span class="ch">\#</span><span class="k">(?:$</span><span class="ch">\/</span><span class="k">)? | </span><span class="ch">\\</span><span class="k">. ) [^</span><span class="ch">\/</span><span class="ch">\#</span><span class="ch">\\</span><span class="k">]* )* </span><span class="ch">\/</span><span class="k">? </span><span class="dl">/</span><span class="mod">ox</span></span><tt> </tt> <tt> @@ -561,9 +563,9 @@ ol.CodeRay li { white-space: pre } </tt> <span class="co">HEXADECIMAL</span> = <span class="rx"><span class="dl">/</span><span class="k">0x[0-9A-Fa-f]+(?:_[0-9A-Fa-f]+)*</span><span class="dl">/</span></span><tt> </tt> <span class="co">BINARY</span> = <span class="rx"><span class="dl">/</span><span class="k">0b[01]+(?:_[01]+)*</span><span class="dl">/</span></span><tt> </tt><tt> -</tt> <span class="co">EXPONENT</span> = <span class="rx"><span class="dl">/</span><span class="k"> [eE] [+-]? </span><span class="il"><span class="dl">#{</span><span class="co">DECIMAL</span><span class="dl">}</span></span><span class="k"> </span><span class="dl">/</span><span class="mod">ox</span></span><tt> -</tt> <span class="co">FLOAT</span> = <span class="rx"><span class="dl">/</span><span class="k"> </span><span class="il"><span class="dl">#{</span><span class="co">DECIMAL</span><span class="dl">}</span></span><span class="k"> (?: </span><span class="il"><span class="dl">#{</span><span class="co">EXPONENT</span><span class="dl">}</span></span><span class="k"> | </span><span class="ch">\.</span><span class="k"> </span><span class="il"><span class="dl">#{</span><span class="co">DECIMAL</span><span class="dl">}</span></span><span class="k"> </span><span class="il"><span class="dl">#{</span><span class="co">EXPONENT</span><span class="dl">}</span></span><span class="k">? ) </span><span class="dl">/</span></span><tt> -</tt> <span class="co">INTEGER</span> = <span class="rx"><span class="dl">/</span><span class="il"><span class="dl">#{</span><span class="co">OCTAL</span><span class="dl">}</span></span><span class="k">|</span><span class="il"><span class="dl">#{</span><span class="co">HEXADECIMAL</span><span class="dl">}</span></span><span class="k">|</span><span class="il"><span class="dl">#{</span><span class="co">BINARY</span><span class="dl">}</span></span><span class="k">|</span><span class="il"><span class="dl">#{</span><span class="co">DECIMAL</span><span class="dl">}</span></span><span class="dl">/</span></span><tt> +</tt> <span class="co">EXPONENT</span> = <span class="rx"><span class="dl">/</span><span class="k"> [eE] [+-]? </span><span class="il"><span class="idl">#{</span><span class="co">DECIMAL</span><span class="idl">}</span></span><span class="k"> </span><span class="dl">/</span><span class="mod">ox</span></span><tt> +</tt> <span class="co">FLOAT</span> = <span class="rx"><span class="dl">/</span><span class="k"> </span><span class="il"><span class="idl">#{</span><span class="co">DECIMAL</span><span class="idl">}</span></span><span class="k"> (?: </span><span class="il"><span class="idl">#{</span><span class="co">EXPONENT</span><span class="idl">}</span></span><span class="k"> | </span><span class="ch">\.</span><span class="k"> </span><span class="il"><span class="idl">#{</span><span class="co">DECIMAL</span><span class="idl">}</span></span><span class="k"> </span><span class="il"><span class="idl">#{</span><span class="co">EXPONENT</span><span class="idl">}</span></span><span class="k">? ) </span><span class="dl">/</span></span><tt> +</tt> <span class="co">INTEGER</span> = <span class="rx"><span class="dl">/</span><span class="il"><span class="idl">#{</span><span class="co">OCTAL</span><span class="idl">}</span></span><span class="k">|</span><span class="il"><span class="idl">#{</span><span class="co">HEXADECIMAL</span><span class="idl">}</span></span><span class="k">|</span><span class="il"><span class="idl">#{</span><span class="co">BINARY</span><span class="idl">}</span></span><span class="k">|</span><span class="il"><span class="idl">#{</span><span class="co">DECIMAL</span><span class="idl">}</span></span><span class="dl">/</span></span><tt> </tt> <tt> </tt> <span class="r">def</span> <span class="fu">reset</span><tt> </tt> <span class="r">super</span><tt> @@ -579,7 +581,7 @@ ol.CodeRay li { white-space: pre } </tt> <span class="iv">@regexp_allowed</span> = <span class="sy">:set</span> <span class="r">if</span> <span class="iv">@regexp_allowed</span> <span class="r">or</span> <span class="iv">@scanner</span>.matched.index(<span class="i">?\n</span>) <span class="c"># delayed flag setting</span><tt> </tt><tt> </tt> <span class="r">elsif</span> <span class="iv">@state</span> == <span class="sy">:def_expected</span><tt> -</tt> <span class="r">if</span> <span class="iv">@scanner</span>.scan(<span class="rx"><span class="dl">/</span><span class="k"> (?: (?:</span><span class="il"><span class="dl">#{</span><span class="co">IDENT</span><span class="dl">}</span></span><span class="k">(?:</span><span class="ch">\.</span><span class="k">|::))* | (?:@@?|$)? </span><span class="il"><span class="dl">#{</span><span class="co">IDENT</span><span class="dl">}</span></span><span class="k">(?:</span><span class="ch">\.</span><span class="k">|::) ) </span><span class="il"><span class="dl">#{</span><span class="co">METHOD_NAME_EX</span><span class="dl">}</span></span><span class="k"> </span><span class="dl">/</span><span class="mod">ox</span></span>)<tt> +</tt> <span class="r">if</span> <span class="iv">@scanner</span>.scan(<span class="rx"><span class="dl">/</span><span class="k"> (?: (?:</span><span class="il"><span class="idl">#{</span><span class="co">IDENT</span><span class="idl">}</span></span><span class="k">(?:</span><span class="ch">\.</span><span class="k">|::))* | (?:@@?|$)? </span><span class="il"><span class="idl">#{</span><span class="co">IDENT</span><span class="idl">}</span></span><span class="k">(?:</span><span class="ch">\.</span><span class="k">|::) ) </span><span class="il"><span class="idl">#{</span><span class="co">METHOD_NAME_EX</span><span class="idl">}</span></span><span class="k"> </span><span class="dl">/</span><span class="mod">ox</span></span>)<tt> </tt> kind = <span class="sy">:method</span><tt> </tt> <span class="iv">@state</span> = <span class="sy">:initial</span><tt> </tt> <span class="r">else</span><tt> @@ -592,7 +594,7 @@ ol.CodeRay li { white-space: pre } </tt> <span class="r">if</span> <span class="iv">@scanner</span>.scan(<span class="rx"><span class="dl">/</span><span class="k"><<</span><span class="dl">/</span></span>)<tt> </tt> kind = <span class="sy">:operator</span><tt> </tt> <span class="r">else</span><tt> -</tt> <span class="r">if</span> <span class="iv">@scanner</span>.scan(<span class="rx"><span class="dl">/</span><span class="k"> (?: </span><span class="il"><span class="dl">#{</span><span class="co">IDENT</span><span class="dl">}</span></span><span class="k"> (?:</span><span class="ch">\.</span><span class="k">|::))* </span><span class="il"><span class="dl">#{</span><span class="co">IDENT</span><span class="dl">}</span></span><span class="k"> </span><span class="dl">/</span><span class="mod">ox</span></span>)<tt> +</tt> <span class="r">if</span> <span class="iv">@scanner</span>.scan(<span class="rx"><span class="dl">/</span><span class="k"> (?: </span><span class="il"><span class="idl">#{</span><span class="co">IDENT</span><span class="idl">}</span></span><span class="k"> (?:</span><span class="ch">\.</span><span class="k">|::))* </span><span class="il"><span class="idl">#{</span><span class="co">IDENT</span><span class="idl">}</span></span><span class="k"> </span><span class="dl">/</span><span class="mod">ox</span></span>)<tt> </tt> kind = <span class="sy">:method</span><tt> </tt> <span class="r">else</span><tt> </tt> <span class="iv">@scanner</span>.scan(<span class="rx"><span class="dl">/</span><span class="k">.</span><span class="dl">/</span></span>)<tt> @@ -605,9 +607,9 @@ ol.CodeRay li { white-space: pre } </tt> <span class="c"># IDENTIFIERS, KEYWORDS</span><tt> </tt> <span class="r">if</span> <span class="iv">@scanner</span>.scan(<span class="co">GLOBAL_VARIABLE</span>)<tt> </tt> kind = <span class="sy">:global_variable</span><tt> -</tt> <span class="r">elsif</span> <span class="iv">@scanner</span>.scan(<span class="rx"><span class="dl">/</span><span class="k"> @@ </span><span class="il"><span class="dl">#{</span><span class="co">IDENT</span><span class="dl">}</span></span><span class="k"> </span><span class="dl">/</span><span class="mod">ox</span></span>)<tt> +</tt> <span class="r">elsif</span> <span class="iv">@scanner</span>.scan(<span class="rx"><span class="dl">/</span><span class="k"> @@ </span><span class="il"><span class="idl">#{</span><span class="co">IDENT</span><span class="idl">}</span></span><span class="k"> </span><span class="dl">/</span><span class="mod">ox</span></span>)<tt> </tt> kind = <span class="sy">:class_variable</span><tt> -</tt> <span class="r">elsif</span> <span class="iv">@scanner</span>.scan(<span class="rx"><span class="dl">/</span><span class="k"> @ </span><span class="il"><span class="dl">#{</span><span class="co">IDENT</span><span class="dl">}</span></span><span class="k"> </span><span class="dl">/</span><span class="mod">ox</span></span>)<tt> +</tt> <span class="r">elsif</span> <span class="iv">@scanner</span>.scan(<span class="rx"><span class="dl">/</span><span class="k"> @ </span><span class="il"><span class="idl">#{</span><span class="co">IDENT</span><span class="idl">}</span></span><span class="k"> </span><span class="dl">/</span><span class="mod">ox</span></span>)<tt> </tt> kind = <span class="sy">:instance_variable</span><tt> </tt> <span class="r">elsif</span> <span class="iv">@scanner</span>.scan(<span class="rx"><span class="dl">/</span><span class="k"> __END__</span><span class="ch">\n</span><span class="k"> ( (?!</span><span class="ch">\#</span><span class="k">CODE</span><span class="ch">\#</span><span class="k">) .* )? | </span><span class="ch">\#</span><span class="k">[^</span><span class="ch">\n</span><span class="k">]* | =begin(?=</span><span class="ch">\s</span><span class="k">).*? </span><span class="ch">\n</span><span class="k">=end(?=</span><span class="ch">\s</span><span class="k">|</span><span class="ch">\z</span><span class="k">)(?:[^</span><span class="ch">\n</span><span class="k">]*)? </span><span class="dl">/</span><span class="mod">x</span></span>)<tt> </tt> kind = <span class="sy">:comment</span><tt> @@ -635,7 +637,7 @@ ol.CodeRay li { white-space: pre } </tt> <span class="iv">@scanner</span>.scan(<span class="co">REGEXP</span>)<tt> </tt> kind = <span class="sy">:regexp</span><tt> </tt> <span class="c">## %strings</span><tt> -</tt> <span class="r">elsif</span> <span class="iv">@scanner</span>.scan(<span class="rx"><span class="dl">/</span><span class="k">:(?:</span><span class="il"><span class="dl">#{</span><span class="co">GLOBAL_VARIABLE</span><span class="dl">}</span></span><span class="k">|</span><span class="il"><span class="dl">#{</span><span class="co">METHOD_NAME_EX</span><span class="dl">}</span></span><span class="k">|</span><span class="il"><span class="dl">#{</span><span class="co">STRING</span><span class="dl">}</span></span><span class="k">)</span><span class="dl">/</span><span class="mod">ox</span></span>)<tt> +</tt> <span class="r">elsif</span> <span class="iv">@scanner</span>.scan(<span class="rx"><span class="dl">/</span><span class="k">:(?:</span><span class="il"><span class="idl">#{</span><span class="co">GLOBAL_VARIABLE</span><span class="idl">}</span></span><span class="k">|</span><span class="il"><span class="idl">#{</span><span class="co">METHOD_NAME_EX</span><span class="idl">}</span></span><span class="k">|</span><span class="il"><span class="idl">#{</span><span class="co">STRING</span><span class="idl">}</span></span><span class="k">)</span><span class="dl">/</span><span class="mod">ox</span></span>)<tt> </tt> kind = <span class="sy">:global_variable</span><tt> </tt> <span class="r">elsif</span> <span class="iv">@scanner</span>.scan(<span class="rx"><span class="dl">/</span><span class="k"><tt> </tt> </span><span class="ch">\?</span><span class="k"> (?:<tt> @@ -653,7 +655,7 @@ ol.CodeRay li { white-space: pre } </tt> kind = <span class="sy">:float</span><tt> </tt> <span class="r">elsif</span> <span class="iv">@scanner</span>.scan(<span class="co">INTEGER</span>)<tt> </tt> kind = <span class="sy">:integer</span><tt> -</tt> <span class="r">elsif</span> <span class="iv">@scanner</span>.scan(<span class="rx"><span class="dl">/</span><span class="k">:(?:</span><span class="il"><span class="dl">#{</span><span class="co">GLOBAL_VARIABLE</span><span class="dl">}</span></span><span class="k">|</span><span class="il"><span class="dl">#{</span><span class="co">METHOD_NAME_EX</span><span class="dl">}</span></span><span class="k">|</span><span class="il"><span class="dl">#{</span><span class="co">STRING</span><span class="dl">}</span></span><span class="k">)</span><span class="dl">/</span><span class="mod">ox</span></span>)<tt> +</tt> <span class="r">elsif</span> <span class="iv">@scanner</span>.scan(<span class="rx"><span class="dl">/</span><span class="k">:(?:</span><span class="il"><span class="idl">#{</span><span class="co">GLOBAL_VARIABLE</span><span class="idl">}</span></span><span class="k">|</span><span class="il"><span class="idl">#{</span><span class="co">METHOD_NAME_EX</span><span class="idl">}</span></span><span class="k">|</span><span class="il"><span class="idl">#{</span><span class="co">STRING</span><span class="idl">}</span></span><span class="k">)</span><span class="dl">/</span><span class="mod">ox</span></span>)<tt> </tt> kind = <span class="sy">:global_variable</span><tt> </tt> <span class="r">else</span><tt> </tt> <span class="iv">@scanner</span>.scan(<span class="rx"><span class="dl">/</span><span class="k">.</span><span class="dl">/</span><span class="mod">m</span></span>)<tt> @@ -757,7 +759,7 @@ ol.CodeRay li { white-space: pre } </tt> <span class="r">when</span> <span class="s"><span class="dl">'</span><span class="k">xhtml</span><span class="dl">'</span></span><tt> </tt> <span class="iv">@HTML_BR</span> = <span class="s"><span class="dl">"</span><span class="k"><br /></span><span class="ch">\n</span><span class="dl">"</span></span><tt> </tt> <span class="r">else</span><tt> -</tt> raise <span class="s"><span class="dl">"</span><span class="k">Unknown HTML level: </span><span class="il"><span class="dl">#{</span>level<span class="dl">}</span></span><span class="dl">"</span></span><tt> +</tt> raise <span class="s"><span class="dl">"</span><span class="k">Unknown HTML level: </span><span class="il"><span class="idl">#{</span>level<span class="idl">}</span></span><span class="dl">"</span></span><tt> </tt> <span class="r">end</span><tt> </tt> <span class="r">end</span><tt> </tt><tt> @@ -777,14 +779,14 @@ ol.CodeRay li { white-space: pre } </tt> <span class="r">def</span> <span class="fu">to_html</span> token<tt> </tt> css_class = <span class="co">ClassOfKind</span>[token.kind]<tt> </tt> <span class="r">if</span> <span class="r">defined?</span> ::<span class="co">DEBUG</span> <span class="r">and</span> <span class="r">not</span> <span class="co">ClassOfKind</span>.has_key? token.kind<tt> -</tt> warn <span class="s"><span class="dl">"</span><span class="k">no token class found for :</span><span class="il"><span class="dl">#{</span>token.kind<span class="dl">}</span></span><span class="dl">"</span></span><tt> +</tt> warn <span class="s"><span class="dl">"</span><span class="k">no token class found for :</span><span class="il"><span class="idl">#{</span>token.kind<span class="idl">}</span></span><span class="dl">"</span></span><tt> </tt> <span class="r">end</span><tt> </tt> <tt> </tt> text = text_to_html token.text<tt> </tt> <span class="r">if</span> css_class == <span class="sy">:NO_HIGHLIGHT</span><tt> </tt> text<tt> </tt> <span class="r">else</span><tt> -</tt> <span class="s"><span class="dl">"</span><span class="k"><span class=</span><span class="ch">\"</span><span class="il"><span class="dl">#{</span>css_class<span class="dl">}</span></span><span class="ch">\"</span><span class="k">></span><span class="il"><span class="dl">#{</span>text<span class="dl">}</span></span><span class="k"></span></span><span class="dl">"</span></span><tt> +</tt> <span class="s"><span class="dl">"</span><span class="k"><span class=</span><span class="ch">\"</span><span class="il"><span class="idl">#{</span>css_class<span class="idl">}</span></span><span class="ch">\"</span><span class="k">></span><span class="il"><span class="idl">#{</span>text<span class="idl">}</span></span><span class="k"></span></span><span class="dl">"</span></span><tt> </tt> <span class="r">end</span><tt> </tt> <span class="r">end</span><tt> </tt> <tt> diff --git a/sample/html2.expected b/sample/html2.expected index ead61b2..e276d3e 100644 --- a/sample/html2.expected +++ b/sample/html2.expected @@ -34,12 +34,14 @@ ol.CodeRay li { white-space: pre } .CodeRay .code pre { overflow: auto } +.CodeRay .debug { color:white ! important; background:blue ! important; } + .CodeRay .af { color:#00C } .CodeRay .an { color:#007 } .CodeRay .av { color:#700 } .CodeRay .aw { color:#C00 } .CodeRay .bi { color:#509; font-weight:bold } -.CodeRay .c { color:#888 } +.CodeRay .c { color:#666; } .CodeRay .ch { color:#04D } .CodeRay .ch .k { color:#04D } @@ -68,14 +70,14 @@ ol.CodeRay li { white-space: pre } .CodeRay .il { background: #eee } .CodeRay .il .il { background: #ddd } .CodeRay .il .il .il { background: #ccc } -.CodeRay .il .dl { font-weight: bold ! important; color: #888 ! important } +.CodeRay .il .idl { font-weight: bold; color: #888 } .CodeRay .in { color:#B2B; font-weight:bold } .CodeRay .iv { color:#33B } .CodeRay .la { color:#970; font-weight:bold } .CodeRay .lv { color:#963 } .CodeRay .oc { color:#40E; font-weight:bold } -.CodeRay .on { color:#000; font-weight:bold } +.CodeRay .of { color:#000; font-weight:bold } .CodeRay .op { } .CodeRay .pc { color:#038; font-weight:bold } .CodeRay .pd { color:#369; font-weight:bold } @@ -129,10 +131,10 @@ ol.CodeRay li { white-space: pre } </tt></pre></td> <td class="code"><pre ondblclick="with (this.style) { overflow = (overflow == 'auto' || overflow == '') ? 'visible' : 'auto' }">require <span style="background-color:#fff0f0"><span style="color:#710">'</span><span style="color:#D20">coderay</span><span style="color:#710">'</span></span><tt> </tt><tt> -</tt><span style="color:#888"># scan this file</span><tt> +</tt><span style="color:#666;"># scan this file</span><tt> </tt>tokens = <span style="color:#036; font-weight:bold">CodeRay</span>.scan(<span style="color:#036; font-weight:bold">File</span>.read(<span style="color:#d70; font-weight:bold">$0</span>) * <span style="color:#00D; font-weight:bold">1</span>, <span style="color:#A60">:ruby</span>)<tt> </tt><tt> -</tt><span style="color:#888"># output it with two styles of line numbers</span><tt> +</tt><span style="color:#666;"># output it with two styles of line numbers</span><tt> </tt>out = tokens.div(<span style="color:#A60">:line_numbers</span> => <span style="color:#A60">:table</span>)<tt> </tt>out << <span style="background-color:#fff0f0"><span style="color:#710">'</span><span style="color:#D20"><hr /></span><span style="color:#710">'</span></span><tt> </tt>out << tokens.div(<span style="color:#A60">:line_numbers</span> => <span style="color:#A60">:inline</span>, <span style="color:#A60">:line_number_start</span> => <span style="color:#00D; font-weight:bold">8</span>)<tt> @@ -143,10 +145,10 @@ ol.CodeRay li { white-space: pre } <hr /><div class="CodeRay"> <div class="code"><pre><span class="no"> 8</span> require <span style="background-color:#fff0f0"><span style="color:#710">'</span><span style="color:#D20">coderay</span><span style="color:#710">'</span></span> <span class="no"> 9</span> -<span class="no"><strong>10</strong></span> <span style="color:#888"># scan this file</span> +<span class="no"><strong>10</strong></span> <span style="color:#666;"># scan this file</span> <span class="no">11</span> tokens = <span style="color:#036; font-weight:bold">CodeRay</span>.scan(<span style="color:#036; font-weight:bold">File</span>.read(<span style="color:#d70; font-weight:bold">$0</span>) * <span style="color:#00D; font-weight:bold">1</span>, <span style="color:#A60">:ruby</span>) <span class="no">12</span> -<span class="no">13</span> <span style="color:#888"># output it with two styles of line numbers</span> +<span class="no">13</span> <span style="color:#666;"># output it with two styles of line numbers</span> <span class="no">14</span> out = tokens.div(<span style="color:#A60">:line_numbers</span> => <span style="color:#A60">:table</span>) <span class="no">15</span> out << <span style="background-color:#fff0f0"><span style="color:#710">'</span><span style="color:#D20"><hr /></span><span style="color:#710">'</span></span> <span class="no">16</span> out << tokens.div(<span style="color:#A60">:line_numbers</span> => <span style="color:#A60">:inline</span>, <span style="color:#A60">:line_number_start</span> => <span style="color:#00D; font-weight:bold">8</span>) diff --git a/sample/html_list.expected b/sample/html_list.expected index aec2cf5..9065842 100644 --- a/sample/html_list.expected +++ b/sample/html_list.expected @@ -34,12 +34,14 @@ ol.CodeRay li { white-space: pre } .CodeRay .code pre { overflow: auto } +.CodeRay .debug { color:white ! important; background:blue ! important; } + .CodeRay .af { color:#00C } .CodeRay .an { color:#007 } .CodeRay .av { color:#700 } .CodeRay .aw { color:#C00 } .CodeRay .bi { color:#509; font-weight:bold } -.CodeRay .c { color:#888 } +.CodeRay .c { color:#666; } .CodeRay .ch { color:#04D } .CodeRay .ch .k { color:#04D } @@ -68,14 +70,14 @@ ol.CodeRay li { white-space: pre } .CodeRay .il { background: #eee } .CodeRay .il .il { background: #ddd } .CodeRay .il .il .il { background: #ccc } -.CodeRay .il .dl { font-weight: bold ! important; color: #888 ! important } +.CodeRay .il .idl { font-weight: bold; color: #888 } .CodeRay .in { color:#B2B; font-weight:bold } .CodeRay .iv { color:#33B } .CodeRay .la { color:#970; font-weight:bold } .CodeRay .lv { color:#963 } .CodeRay .oc { color:#40E; font-weight:bold } -.CodeRay .on { color:#000; font-weight:bold } +.CodeRay .of { color:#000; font-weight:bold } .CodeRay .op { } .CodeRay .pc { color:#038; font-weight:bold } .CodeRay .pd { color:#369; font-weight:bold } diff --git a/sample/load_encoder.rb b/sample/load_encoder.rb index 39d310d..9594bfa 100644 --- a/sample/load_encoder.rb +++ b/sample/load_encoder.rb @@ -11,14 +11,14 @@ print 'Now it is loaded: ' p yaml_encoder
puts 'See?'
-tokens_encoder = require_plugin 'CodeRay::Encoders/tokens'
+tokens_encoder = CodeRay.require_plugin 'CodeRay::Encoders/tokens'
print 'Require is also possible: '
p tokens_encoder
puts 'See?'
puts 'Now load some mapped encoders: stats and plain.'
-require_plugin 'CodeRay::Encoders/stats'
-require_plugin 'CodeRay::Encoders/plain'
+CodeRay.require_plugin 'CodeRay::Encoders/stats'
+CodeRay.require_plugin 'CodeRay::Encoders/plain'
puts 'Require all Encoders:'
CodeRay::Encoders.load_all
diff --git a/sample/load_scanner.rb b/sample/load_scanner.rb index 5e503f0..23be8a2 100644 --- a/sample/load_scanner.rb +++ b/sample/load_scanner.rb @@ -11,14 +11,14 @@ print 'Now it is loaded: ' p ruby_scanner
puts 'See?'
-c_scanner = require_plugin 'CodeRay::Scanners/c'
+c_scanner = CodeRay.require_plugin 'CodeRay::Scanners/c'
print 'Require is also possible: '
p c_scanner
puts 'See?'
puts 'Now load some mapped scanners: cpp and plain.'
-require_plugin 'CodeRay::Scanners/cpp'
-require_plugin 'CodeRay::Scanners/plain'
+CodeRay.require_plugin 'CodeRay::Scanners/cpp'
+CodeRay.require_plugin 'CodeRay::Scanners/plain'
puts 'Require all Scanners:'
CodeRay::Scanners.load_all
diff --git a/sample/more.expected b/sample/more.expected index aa26e61..72632d3 100644 --- a/sample/more.expected +++ b/sample/more.expected @@ -1,2 +1,2 @@ -Input: 4983B, Output: 22546B +Input: 4983B, Output: 22625B Take a look with your browser. diff --git a/sample/scanner.expected b/sample/scanner.expected index d35a06d..5015168 100644 --- a/sample/scanner.expected +++ b/sample/scanner.expected @@ -13,4 +13,4 @@ false 2 > has a string? -"ruby_code" (ident), "(" (operator), ":can" (symbol), "," (operator), " " (space), "BE" (constant), "," (operator), " " (space), "%r[" (delimiter), "q" (content), "[" (nesting_delimiter), "ui" (content), "]" (nesting_delimiter), "te " (content), "#{" (delimiter), " " (space), "/" (delimiter), "comple" (content), "/" (delimiter), "x" (modifier), " " (space), "}" (delimiter), "," (content), "]" (delimiter), " " (space), "=" (operator), ">" (operator), " " (space), "$-s" (global_variable), "," (operator), " " (space), "&" (operator), "?\xee" (integer), ")" (operator) +"ruby_code" (ident), "(" (operator), ":can" (symbol), "," (operator), " " (space), "BE" (constant), "," (operator), " " (space), "%r[" (delimiter), "q" (content), "[" (nesting_delimiter), "ui" (content), "]" (nesting_delimiter), "te " (content), "#{" (inline_delimiter), " " (space), "/" (delimiter), "comple" (content), "/" (delimiter), "x" (modifier), " " (space), "}" (inline_delimiter), "," (content), "]" (delimiter), " " (space), "=" (operator), ">" (operator), " " (space), "$-s" (global_variable), "," (operator), " " (space), "&" (operator), "?\xee" (integer), ")" (operator) diff --git a/sample/suite.rb b/sample/suite.rb index 0313ddc..c586697 100644 --- a/sample/suite.rb +++ b/sample/suite.rb @@ -23,6 +23,7 @@ class CodeRaySuite < TestCase def test_ALL dir do for input in Dir["*.rb"] - %w(server.rb stream.rb suite.rb) + next if input[/^load_/] puts "[ testing #{input}... ]" name = File.basename(input, ".rb") output = name + '.expected' diff --git a/test/scanners/coderay_suite.rb b/test/scanners/coderay_suite.rb index 122d9cd..04b385a 100644 --- a/test/scanners/coderay_suite.rb +++ b/test/scanners/coderay_suite.rb @@ -12,7 +12,8 @@ begin rescue LoadError begin require 'rubygems' - require_gem 'term-ansicolor' + gem 'term-ansicolor' + require 'term/ansicolor' rescue LoadError # ignore end @@ -21,6 +22,9 @@ end unless ENV['nocolor'] if defined? Term::ANSIColor class String include Term::ANSIColor + def green_or_red result + result ? green : red + end end else class String @@ -31,6 +35,9 @@ else end END end + def green_or_red result + result ? upcase : downcase + end end end $DEBUG = debug @@ -91,15 +98,15 @@ module Enumerable end module CodeRay - + require 'test/unit' - + class TestCase < Test::Unit::TestCase if ENV['deluxe'] - MAX_CODE_SIZE_TO_HIGHLIGHT = 200_000 - MAX_CODE_SIZE_TO_TEST = 1_000_000 - DEFAULT_MAX = 512 + MAX_CODE_SIZE_TO_HIGHLIGHT = 5_000_000 + MAX_CODE_SIZE_TO_TEST = 5_000_000 + DEFAULT_MAX = 1024 else MAX_CODE_SIZE_TO_HIGHLIGHT = 20_000 MAX_CODE_SIZE_TO_TEST = 100_000 @@ -110,7 +117,7 @@ module CodeRay def inherited child CodeRay::TestSuite << child.suite end - + # Calls its block with the working directory set to the examples # for this test case. def dir @@ -119,11 +126,11 @@ module CodeRay yield end end - + def lang @lang ||= name.downcase.to_sym end - + def extension extension = nil if extension @extension = extension.to_s @@ -155,13 +162,13 @@ module CodeRay puts 'Finished in '.green + '%0.2fs'.white % time_for_lang + '.'.green end - + def examples_test scanner, max self.class.dir do extension = 'in.' + self.class.extension for example_filename in Dir["*.#{extension}"] name = File.basename(example_filename, ".#{extension}") - next if ENV['only'] and ENV['only'] != name + next if ENV['lang'] && ENV['only'] && ENV['only'] != name print name_and_size = ('%15s'.cyan + ' %4.0fK: '.yellow) % [ name, File.size(example_filename) / 1024.0 ] time_for_file = Benchmark.realtime do @@ -179,16 +186,16 @@ module CodeRay return end code = File.open(example_filename, 'rb') { |f| break f.read } - + incremental_test scanner, code, max unless ENV['noincremental'] - + unless ENV['noshuffled'] or code.size < [0].pack('Q').size shuffled_test scanner, code, max else print '-skipped- '.concealed end - - tokens = compare_test scanner, code, name + + tokens = complete_test scanner, code, name identity_test scanner, tokens @@ -200,51 +207,73 @@ module CodeRay end def random_test scanner, max - print "Random test...".red + print "Random test...".yellow + ok = true for size in (0..max).progress srand size + 17 scanner.string = Array.new(size) { rand 256 }.pack 'c*' - scanner.tokenize + begin + scanner.tokenize + rescue + flunk "Random test failed at #{size} #{RUBY_VERSION < '1.9' ? 'bytes' : 'chars'}!" unless ENV['noassert'] + ok = false + break + end end - print "\b\b\b" + print "\b" * 'Random test...'.size + print 'Random test'.green_or_red(ok) puts ' - finished'.green end def incremental_test scanner, code, max - print 'incremental...'.red + print 'incremental...'.yellow + ok = true for size in (0..max).progress break if size > code.size scanner.string = code[0,size] - scanner.tokenize + begin + scanner.tokenize + rescue + flunk "Incremental test failed at #{size} #{RUBY_VERSION < '1.9' ? 'bytes' : 'chars'}!" unless ENV['noassert'] + ok = false + break + end end - print "\b\b\b" - print ', '.red + print "\b" * 'incremental...'.size + print 'incremental, '.green_or_red(ok) end - + def shuffled_test scanner, code, max - print 'shuffled...'.red + print 'shuffled...'.yellow code_bits = code[0,max].unpack('Q*') # split into quadwords... + ok = true for i in (0..max / 4).progress srand i code_bits.shuffle! # ...mix... scanner.string = code_bits.pack('Q*') # ...and join again - scanner.tokenize + begin + scanner.tokenize + rescue + flunk 'shuffle test failed!' unless ENV['noassert'] + ok = false + break + end end - + # highlighted = highlighter.encode_tokens scanner.tokenize # File.open(name + '.shuffled.html', 'w') { |f| f.write highlighted } - print "\b\b\b" - print ', '.red + print "\b" * 'shuffled...'.size + print 'shuffled, '.green_or_red(ok) end - def compare_test scanner, code, name - print 'complete...'.red + def complete_test scanner, code, name + print 'complete...'.yellow expected_filename = name + '.expected.' + Tokenizer.file_extension scanner.string = code tokens = scanner.tokens result = Tokenizer.encode_tokens tokens - - if File.exist? expected_filename + + if File.exist?(expected_filename) && !(ENV['lang'] && ENV['new'] && name == ENV['new']) expected = File.open(expected_filename, 'rb') { |f| break f.read } ok = expected == result actual_filename = expected_filename.sub('.expected.', '.actual.') @@ -259,67 +288,91 @@ module CodeRay unless ENV['noassert'] assert(ok, "Scan error: unexpected output".red) end + print "\b" * 'complete...'.size + print 'complete, '.green_or_red(ok) else - print "\b" * 'complete...'.size, "new test..." File.open(expected_filename, 'wb') { |f| f.write result } + print "\b" * 'complete...'.size, "new test, ".blue end - print "\b\b\b" - print ', '.red - tokens end def identity_test scanner, tokens - print 'identity...'.red - unless scanner.instance_of? CodeRay::Scanners[:debug] - assert_equal scanner.code, tokens.text + print 'identity...'.yellow + if scanner.instance_of? CodeRay::Scanners[:debug] + ok = true + else + ok = scanner.code == tokens.text + unless ok + flunk 'identity test failed!' unless ENV['noassert'] + end end - print "\b\b\b" - print ', '.red + print "\b" * 'identity...'.size + print 'identity, '.green_or_red(ok) end Highlighter = CodeRay::Encoders[:html].new( :tab_width => 2, - :line_numbers => :inline, + :line_numbers => :table, :wrap => :page, :hint => :debug, :css => :class ) - + def highlight_test tokens, name - print 'highlighting, '.red - highlighted = Highlighter.encode_tokens tokens - File.open(name + '.actual.html', 'w') { |f| f.write highlighted } + print 'highlighting...'.yellow + ok = true + begin + highlighted = Highlighter.encode_tokens tokens + rescue + flunk 'highlighting test failed!' unless ENV['noassert'] + ok = false + break + end + File.open(name + '.actual.html', 'w') { |f| f.write highlighted } + print "\b" * 'highlighting...'.size + print 'highlighting, '.green_or_red(ok) end - + end require 'test/unit/testsuite' - + class TestSuite @suite = Test::Unit::TestSuite.new 'CodeRay::Scanners' class << self - + def << sub_suite @suite << sub_suite end - + def load_suite name begin suite = File.join($mydir, name, 'suite.rb') require suite rescue LoadError $stderr.puts <<-ERR - + !! Suite #{suite} not found - + ERR false end end - + + def check_env_lang + for key in %w(only new) + if ENV[key] && ENV[key][/^(\w+)\.([\w_]+)$/] + ENV['lang'] = $1 + ENV[key] = $2 + end + end + end + def load + ENV['only'] = ENV['new'] if ENV['new'] + check_env_lang subsuite = ARGV.find { |a| break $& if a[/^[^-].*/] } || ENV['lang'] if subsuite load_suite(subsuite) or exit @@ -329,7 +382,7 @@ module CodeRay end end end - + def run load $VERBOSE = true @@ -339,5 +392,5 @@ module CodeRay end end end - + end
\ No newline at end of file diff --git a/test/scanners/ruby/evil.expected.raydebug b/test/scanners/ruby/evil.expected.raydebug index cca15dd..84ac855 100644 --- a/test/scanners/ruby/evil.expected.raydebug +++ b/test/scanners/ruby/evil.expected.raydebug @@ -44,10 +44,10 @@ ident(p)operator(()pre_constant(false) operator(::) ident(to_s)operator(\)) reserved(class) class(C2) reserved(class) operator(<<)class(self) reserved(def) pre_constant(self)operator(.)ident(p8)operator(;) ident(p) integer(8) reserved(end) - reserved(alias) ident(p?) ident(p) - reserved(alias) ident(P?) ident(p) - reserved(alias) operator([)operator(]) ident(p) - reserved(alias) operator(<=>) ident(p) + reserved(alias) method(p?) method(p) + reserved(alias) method(P?) method(p) + reserved(alias) method([]) method(p) + reserved(alias) method(<=>) method(p) reserved(end) ident(q)operator(=)integer(9) @@ -881,7 +881,7 @@ reserved(class) operator(<<)class(a) reserved(def) method(foobar) pre_constant(self)operator(*)integer(101) reserved(end) - reserved(alias) ident(eql?) operator(==) + reserved(alias) method(eql?) method(==) reserved(end) ident(p) ident(a)operator(.)ident(foobar) diff --git a/test/scanners/ruby/example.expected.raydebug b/test/scanners/ruby/example.expected.raydebug index 492a67a..5a684e6 100644 --- a/test/scanners/ruby/example.expected.raydebug +++ b/test/scanners/ruby/example.expected.raydebug @@ -217,7 +217,7 @@ reserved(class) class(Set) reserved(def) method(size) instance_variable(@hash)operator(.)ident(size) reserved(end) - reserved(alias) ident(length) ident(size) + reserved(alias) method(length) method(size) comment(# Returns true if the set contains no elements.) reserved(def) method(empty?) @@ -288,7 +288,7 @@ reserved(class) class(Set) reserved(def) method(include?)operator(()ident(o)operator(\)) instance_variable(@hash)operator(.)ident(include?)operator(()ident(o)operator(\)) reserved(end) - reserved(alias) ident(member?) ident(include?) + reserved(alias) method(member?) method(include?) comment(# Returns true if the set is a superset of the given set.) reserved(def) method(superset?)operator(()ident(set)operator(\)) @@ -331,7 +331,7 @@ reserved(class) class(Set) instance_variable(@hash)operator([)ident(o)operator(]) operator(=) pre_constant(true) pre_constant(self) reserved(end) - reserved(alias) operator(<<) ident(add) + reserved(alias) method(<<) method(add) comment(# Adds the given object to the set and returns self. If the) comment(# object is already in the set, returns nil.) @@ -373,7 +373,7 @@ reserved(class) class(Set) ident(each) operator({) operator(|)ident(o)operator(|) ident(set) operator(<<) reserved(yield)operator(()ident(o)operator(\)) operator(}) ident(replace)operator(()ident(set)operator(\)) reserved(end) - reserved(alias) ident(map!) ident(collect!) + reserved(alias) method(map!) method(collect!) comment(# Equivalent to Set#delete_if, but returns nil if no changes were) comment(# made.) @@ -410,8 +410,8 @@ reserved(class) class(Set) ident(enum)operator(.)ident(is_a?)operator(()constant(Enumerable)operator(\)) reserved(or) ident(raise) constant(ArgumentError)operator(,) string<delimiter(")content(value must be enumerable)delimiter(")> ident(dup)operator(.)ident(merge)operator(()ident(enum)operator(\)) reserved(end) - reserved(alias) operator(+) operator(|) comment(##) - reserved(alias) ident(union) operator(|) comment(##) + reserved(alias) method(+) method(|) comment(##) + reserved(alias) method(union) method(|) comment(##) comment(# Returns a new set built by duplicating the set, removing every) comment(# element that appears in the given enumerable object.) @@ -419,7 +419,7 @@ reserved(class) class(Set) ident(enum)operator(.)ident(is_a?)operator(()constant(Enumerable)operator(\)) reserved(or) ident(raise) constant(ArgumentError)operator(,) string<delimiter(")content(value must be enumerable)delimiter(")> ident(dup)operator(.)ident(subtract)operator(()ident(enum)operator(\)) reserved(end) - reserved(alias) ident(difference) operator(-) comment(##) + reserved(alias) method(difference) method(-) comment(##) comment(# Returns a new array containing elements common to the set and the) comment(# given enumerable object.) @@ -429,7 +429,7 @@ reserved(class) class(Set) ident(enum)operator(.)ident(each) operator({) operator(|)ident(o)operator(|) ident(n)operator(.)ident(add)operator(()ident(o)operator(\)) reserved(if) ident(include?)operator(()ident(o)operator(\)) operator(}) ident(n) reserved(end) - reserved(alias) ident(intersection) operator(&) comment(##) + reserved(alias) method(intersection) method(&) comment(##) comment(# Returns a new array containing elements exclusive between the set) comment(# and the given enumerable object. (set ^ enum\) is equivalent to) @@ -508,7 +508,7 @@ reserved(class) class(Set) reserved(class) operator(<<) class(dig) operator(=) operator({)operator(}) comment(# :nodoc:) ident(include) constant(TSort) - reserved(alias) ident(tsort_each_node) ident(each_key) + reserved(alias) method(tsort_each_node) method(each_key) reserved(def) method(tsort_each_child)operator(()ident(node)operator(,) operator(&)ident(block)operator(\)) ident(fetch)operator(()ident(node)operator(\))operator(.)ident(each)operator(()operator(&)ident(block)operator(\)) reserved(end) diff --git a/test/scanners/ruby/operators.expected.raydebug b/test/scanners/ruby/operators.expected.raydebug new file mode 100644 index 0000000..56d9ac3 --- /dev/null +++ b/test/scanners/ruby/operators.expected.raydebug @@ -0,0 +1,51 @@ +reserved(class) class(Feeling) + + reserved(def) method(~) + ident(p) symbol(:drunk) + reserved(end) + + reserved(def) method(!) + ident(p) symbol(:alert) + reserved(end) + + reserved(alias) method(not) method(!@) + reserved(alias) method(tilde) method(~@) + + reserved(def) method(-@) + ident(p) symbol(:bad) + reserved(end) + + reserved(def) method(+@) + ident(p) symbol(:good) + reserved(end) + +reserved(end) + +ident(feeling) operator(=) constant(Feeling)operator(.)ident(new) + +operator(-)ident(feeling) comment(# => :bad) +operator(+)ident(feeling) comment(# => :good) +operator(!)ident(feeling) comment(# => :alert) +operator(~)ident(feeling) comment(# => :drunk) + +reserved(def) method(=~) ident(other) + ident(bla) +reserved(end) + +ident(feeling)operator(.)ident(!) comment(# => :alert) +ident(feeling)operator(.)ident(~) comment(# => :drunk) +ident(feeling)operator(.)ident(!@) comment(# => :alert) +ident(feeling)operator(.)ident(~@) comment(# => :drunk) +ident(feeling)operator(.)ident(-@)operator(()operator(\)) comment(# => :bad) +ident(feeling)operator(.)ident(+@)operator(()operator(\)) comment(# => :good) + +comment(# >> :bad) +comment(# >> :good) +comment(# >> :alert) +comment(# >> :drunk) +comment(# >> :alert) +comment(# >> :drunk) +comment(# >> :alert) +comment(# >> :drunk) +comment(# >> :bad) +comment(# >> :good) diff --git a/test/scanners/ruby/operators.in.rb b/test/scanners/ruby/operators.in.rb new file mode 100644 index 0000000..8fa7090 --- /dev/null +++ b/test/scanners/ruby/operators.in.rb @@ -0,0 +1,51 @@ +class Feeling + + def ~ + p :drunk + end + + def ! + p :alert + end + + alias not !@ + alias tilde ~@ + + def -@ + p :bad + end + + def +@ + p :good + end + +end + +feeling = Feeling.new + +-feeling # => :bad ++feeling # => :good +!feeling # => :alert +~feeling # => :drunk + +def =~ other + bla +end + +feeling.! # => :alert +feeling.~ # => :drunk +feeling.!@ # => :alert +feeling.~@ # => :drunk +feeling.-@() # => :bad +feeling.+@() # => :good + +# >> :bad +# >> :good +# >> :alert +# >> :drunk +# >> :alert +# >> :drunk +# >> :alert +# >> :drunk +# >> :bad +# >> :good diff --git a/test/scanners/ruby/pleac.expected.raydebug b/test/scanners/ruby/pleac.expected.raydebug index b1e7762..0a9a6ac 100644 --- a/test/scanners/ruby/pleac.expected.raydebug +++ b/test/scanners/ruby/pleac.expected.raydebug @@ -4021,7 +4021,7 @@ comment(#=> bar) comment(# You can also take a reference to an existing method before) comment(# redefining a new one, using the `alias' keyword) reserved(def) method(foo)operator(;) ident(puts) string<delimiter(')content(foo)delimiter(')>operator(;) reserved(end) -reserved(alias) ident(foo_orig) ident(foo) +reserved(alias) method(foo_orig) method(foo) reserved(def) method(foo)operator(;) ident(puts) string<delimiter(')content(bar)delimiter(')>operator(;) reserved(end) ident(foo_orig) ident(foo) diff --git a/test/scanners/ruby/regexp.expected.raydebug b/test/scanners/ruby/regexp.expected.raydebug new file mode 100644 index 0000000..43f1d91 --- /dev/null +++ b/test/scanners/ruby/regexp.expected.raydebug @@ -0,0 +1,5 @@ +comment(# Regexp or division?) +ident(some_string)operator(.)ident(to_i) regexp<delimiter(/)char(\\s)content(+)delimiter(/)> +ident(some_string)operator(.)ident(split) operator(/) operator(+)regexp<delimiter(/)content( this is a regexp after a division )delimiter(/)> +ident(some_string)operator(.)ident(split) operator(/) operator(+) regexp<delimiter(/)content( this one, too )delimiter(/)> +ident(some_string)operator(.)ident(split) regexp<delimiter(/)content(- )delimiter(/)> comment(# and this one is a regexp without division)
\ No newline at end of file diff --git a/test/scanners/ruby/regexp.in.rb b/test/scanners/ruby/regexp.in.rb new file mode 100644 index 0000000..956e6b8 --- /dev/null +++ b/test/scanners/ruby/regexp.in.rb @@ -0,0 +1,5 @@ +# Regexp or division? +some_string.to_i /\s+/ +some_string.split / +/ this is a regexp after a division / +some_string.split / + / this one, too / +some_string.split /- / # and this one is a regexp without division
\ No newline at end of file diff --git a/test/scanners/ruby/suite.rb b/test/scanners/ruby/suite.rb index ca390f5..bcc5702 100644 --- a/test/scanners/ruby/suite.rb +++ b/test/scanners/ruby/suite.rb @@ -1,2 +1,2 @@ -class Scheme < CodeRay::TestCase +class Ruby < CodeRay::TestCase end |