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 --- sample/css.expected | 6 ++++-- sample/div.expected | 6 +++--- sample/highlight.expected | 12 +++++++----- sample/html.expected | 40 +++++++++++++++++++++------------------- sample/html2.expected | 16 +++++++++------- sample/html_list.expected | 8 +++++--- sample/load_encoder.rb | 6 +++--- sample/load_scanner.rb | 6 +++--- sample/more.expected | 2 +- sample/scanner.expected | 2 +- sample/suite.rb | 1 + 11 files changed, 58 insertions(+), 47 deletions(-) (limited to 'sample') 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 @@
for a in 0..255
         a = a.chr
         begin
-                x = eval("?\\#{a}")
+                x = eval("?\\#{a}")
                 if x == a[0]
                         next
                 else
-                        print "#{a}: #{x}"
+                        print "#{a}: #{x}"
                 end
         rescue SyntaxError => boom
-                print "#{a}: error"
+                print "#{a}: error"
         end
         puts
 end
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 }
 puts <<HTML
 <html>
 <head>
-#{output.stylesheet true}
+#{output.stylesheet true}
 <body>
-#{output}
+#{output}
 </body>
 </html>
 HTML
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 }
       add(RESERVED_WORDS, :reserved).
       add(PREDEFINED_CONSTANTS, :pre_constant)
 
-    METHOD_NAME = / #{IDENT} [?!]? /xo
+    METHOD_NAME = / #{IDENT} [?!]? /xo
     METHOD_NAME_EX = /
-     #{METHOD_NAME}  # common methods: split, foo=, empty?, gsub!
+     #{METHOD_NAME}  # common methods: split, foo=, empty?, gsub!
      | \*\*?         # multiplication and power
      | [-+~]@?       # plus, minus
      | [\/%&|^`]     # division, modulo or format strings, &and, |or, ^xor, `system`
@@ -548,11 +550,11 @@ ol.CodeRay li { white-space: pre }
      | << | >>       # append or shift left, shift right
      | ===?          # simple equality and case equality
     /ox
-    GLOBAL_VARIABLE = / \$ (?: #{IDENT} | \d+ | [~&+`'=\/,;_.<>!@0$?*":F\\] | -[a-zA-Z_0-9] ) /ox
+    GLOBAL_VARIABLE = / \$ (?: #{IDENT} | \d+ | [~&+`'=\/,;_.<>!@0$?*":F\\] | -[a-zA-Z_0-9] ) /ox
 
     DOUBLEQ = / "  [^"\#\\]*  (?: (?: \#\{.*?\} | \#(?:$")?  | \\. ) [^"\#\\]*  )* "?  /ox
     SINGLEQ = / '  [^'\\]*    (?:                              \\.   [^'\\]*    )* '?  /ox
-    STRING  = / #{SINGLEQ} | #{DOUBLEQ} /ox
+    STRING  = / #{SINGLEQ} | #{DOUBLEQ} /ox
     SHELL   = / `  [^`\#\\]*  (?: (?: \#\{.*?\} | \#(?:$`)?  | \\. ) [^`\#\\]*  )* `?  /ox
     REGEXP  = / \/ [^\/\#\\]* (?: (?: \#\{.*?\} | \#(?:$\/)? | \\. ) [^\/\#\\]* )* \/? /ox
     
@@ -561,9 +563,9 @@ ol.CodeRay li { white-space: pre }
     HEXADECIMAL = /0x[0-9A-Fa-f]+(?:_[0-9A-Fa-f]+)*/
     BINARY = /0b[01]+(?:_[01]+)*/
 
-    EXPONENT = / [eE] [+-]? #{DECIMAL} /ox
-    FLOAT = / #{DECIMAL} (?: #{EXPONENT} | \. #{DECIMAL} #{EXPONENT}? ) /
-    INTEGER = /#{OCTAL}|#{HEXADECIMAL}|#{BINARY}|#{DECIMAL}/
+    EXPONENT = / [eE] [+-]? #{DECIMAL} /ox
+    FLOAT = / #{DECIMAL} (?: #{EXPONENT} | \. #{DECIMAL} #{EXPONENT}? ) /
+    INTEGER = /#{OCTAL}|#{HEXADECIMAL}|#{BINARY}|#{DECIMAL}/
     
     def reset
       super
@@ -579,7 +581,7 @@ ol.CodeRay li { white-space: pre }
         @regexp_allowed = :set if @regexp_allowed or @scanner.matched.index(?\n)  # delayed flag setting
 
       elsif @state == :def_expected
-        if @scanner.scan(/ (?: (?:#{IDENT}(?:\.|::))* | (?:@@?|$)? #{IDENT}(?:\.|::) ) #{METHOD_NAME_EX} /ox)
+        if @scanner.scan(/ (?: (?:#{IDENT}(?:\.|::))* | (?:@@?|$)? #{IDENT}(?:\.|::) ) #{METHOD_NAME_EX} /ox)
           kind = :method
           @state = :initial
         else
@@ -592,7 +594,7 @@ ol.CodeRay li { white-space: pre }
         if @scanner.scan(/<</)
           kind = :operator
         else
-          if @scanner.scan(/ (?: #{IDENT} (?:\.|::))* #{IDENT} /ox)
+          if @scanner.scan(/ (?: #{IDENT} (?:\.|::))* #{IDENT} /ox)
             kind = :method
           else
             @scanner.scan(/./)
@@ -605,9 +607,9 @@ ol.CodeRay li { white-space: pre }
         # IDENTIFIERS, KEYWORDS
         if @scanner.scan(GLOBAL_VARIABLE)
           kind = :global_variable
-        elsif @scanner.scan(/ @@ #{IDENT} /ox)
+        elsif @scanner.scan(/ @@ #{IDENT} /ox)
           kind = :class_variable
-        elsif @scanner.scan(/ @ #{IDENT} /ox)
+        elsif @scanner.scan(/ @ #{IDENT} /ox)
           kind = :instance_variable
         elsif @scanner.scan(/ __END__\n ( (?!\#CODE\#) .* )? | \#[^\n]* | =begin(?=\s).*? \n=end(?=\s|\z)(?:[^\n]*)? /x)
           kind = :comment
@@ -635,7 +637,7 @@ ol.CodeRay li { white-space: pre }
            @scanner.scan(REGEXP)
           kind = :regexp
         ## %strings
-        elsif @scanner.scan(/:(?:#{GLOBAL_VARIABLE}|#{METHOD_NAME_EX}|#{STRING})/ox)
+        elsif @scanner.scan(/:(?:#{GLOBAL_VARIABLE}|#{METHOD_NAME_EX}|#{STRING})/ox)
           kind = :global_variable
         elsif @scanner.scan(/
           \? (?:
@@ -653,7 +655,7 @@ ol.CodeRay li { white-space: pre }
           kind = :float
         elsif @scanner.scan(INTEGER)
           kind = :integer
-        elsif @scanner.scan(/:(?:#{GLOBAL_VARIABLE}|#{METHOD_NAME_EX}|#{STRING})/ox)
+        elsif @scanner.scan(/:(?:#{GLOBAL_VARIABLE}|#{METHOD_NAME_EX}|#{STRING})/ox)
           kind = :global_variable
         else
           @scanner.scan(/./m)
@@ -757,7 +759,7 @@ ol.CodeRay li { white-space: pre }
         when 'xhtml'
           @HTML_BR = "<br />\n"
       else
-        raise "Unknown HTML level: #{level}"
+        raise "Unknown HTML level: #{level}"
       end
     end
 
@@ -777,14 +779,14 @@ ol.CodeRay li { white-space: pre }
     def to_html token
       css_class = ClassOfKind[token.kind]
       if defined? ::DEBUG and not ClassOfKind.has_key? token.kind
-        warn "no token class found for :#{token.kind}"
+        warn "no token class found for :#{token.kind}"
       end
         
       text = text_to_html token.text
       if css_class == :NO_HIGHLIGHT
         text
       else
-        "<span class=\"#{css_class}\">#{text}</span>"
+        "<span class=\"#{css_class}\">#{text}</span>"
       end
     end
     
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 }
 
require 'coderay'
 
-# scan this file
+# scan this file
 tokens = CodeRay.scan(File.read($0) * 1, :ruby)
 
-# output it with two styles of line numbers
+# output it with two styles of line numbers
 out = tokens.div(:line_numbers => :table)
 out << '<hr />'
 out << tokens.div(:line_numbers => :inline, :line_number_start => 8)
@@ -143,10 +145,10 @@ ol.CodeRay li { white-space: pre }
 
 8 require 'coderay'
  9 
-10 # scan this file
+10 # scan this file
 11 tokens = CodeRay.scan(File.read($0) * 1, :ruby)
 12 
-13 # output it with two styles of line numbers
+13 # output it with two styles of line numbers
 14 out = tokens.div(:line_numbers => :table)
 15 out << '<hr />'
 16 out << tokens.div(:line_numbers => :inline, :line_number_start => 8)
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'
-- 
cgit v1.2.1