From 0d4ddc9f66eb3b4dc3f6e7cb191b605b348e8189 Mon Sep 17 00:00:00 2001 From: murphy Date: Sun, 16 Apr 2006 03:20:37 +0000 Subject: Re-indented everything. Sorry to break the blame chain. --- lib/coderay/encoder.rb | 2 - lib/coderay/encoders/_map.rb | 12 ++-- lib/coderay/encoders/count.rb | 6 +- lib/coderay/encoders/debug.rb | 68 ++++++++++++---------- lib/coderay/encoders/div.rb | 6 +- lib/coderay/encoders/html/classes.rb | 6 +- lib/coderay/encoders/html/css.rb | 6 +- lib/coderay/encoders/html/output.rb | 2 +- lib/coderay/encoders/null.rb | 32 +++++------ lib/coderay/encoders/span.rb | 9 ++- lib/coderay/encoders/statistic.rb | 6 +- lib/coderay/encoders/tokens.rb | 70 +++++++++++------------ lib/coderay/encoders/xml.rb | 105 +++++++++++++++++----------------- lib/coderay/encoders/yaml.rb | 23 ++++---- lib/coderay/helpers/filetype.rb | 2 +- lib/coderay/helpers/gzip_simple.rb | 2 +- lib/coderay/scanner.rb | 1 - lib/coderay/scanners/_map.rb | 22 +++---- lib/coderay/scanners/c.rb | 6 +- lib/coderay/scanners/delphi.rb | 6 +- lib/coderay/scanners/html.rb | 6 +- lib/coderay/scanners/nitro_html.rb | 6 +- lib/coderay/scanners/plaintext.rb | 6 +- lib/coderay/scanners/rhtml.rb | 6 +- lib/coderay/scanners/ruby.rb | 7 ++- lib/coderay/scanners/ruby/patterns.rb | 12 ++-- lib/coderay/styles/_map.rb | 10 ++-- lib/coderay/styles/cycnus.rb | 36 ++++++------ lib/coderay/styles/murphy.rb | 36 ++++++------ 29 files changed, 275 insertions(+), 242 deletions(-) diff --git a/lib/coderay/encoder.rb b/lib/coderay/encoder.rb index 8f8375a..fd809d5 100644 --- a/lib/coderay/encoder.rb +++ b/lib/coderay/encoder.rb @@ -171,5 +171,3 @@ module CodeRay end end - -# vim:sw=2:ts=2:noet:tw=78 diff --git a/lib/coderay/encoders/_map.rb b/lib/coderay/encoders/_map.rb index b9fe5af..13c4a9d 100644 --- a/lib/coderay/encoders/_map.rb +++ b/lib/coderay/encoders/_map.rb @@ -1,8 +1,8 @@ module CodeRay - module Encoders - - map :stats => :statistic, - :plain => :text - - end +module Encoders + + map :stats => :statistic, + :plain => :text + +end end diff --git a/lib/coderay/encoders/count.rb b/lib/coderay/encoders/count.rb index d49e0bc..c662ead 100644 --- a/lib/coderay/encoders/count.rb +++ b/lib/coderay/encoders/count.rb @@ -6,12 +6,12 @@ module Encoders include Streamable register_for :count - protected - + protected + def setup options @out = 0 end - + def token text, kind @out += 1 end diff --git a/lib/coderay/encoders/debug.rb b/lib/coderay/encoders/debug.rb index 7358e8b..d6aac8b 100644 --- a/lib/coderay/encoders/debug.rb +++ b/lib/coderay/encoders/debug.rb @@ -1,38 +1,46 @@ module CodeRay - module Encoders - - # = Debug Encoder - class Debug < Encoder - - include Streamable - register_for :debug - - FILE_EXTENSION = 'raydebug' - - protected - def text_token text, kind - @out << - if kind == :space - text - else - text = text.gsub(/[)\\]/, '\\\\\0') - "#{kind}(#{text})" - end - end - - def block_token action, kind - @out << super - end +module Encoders + + # = Debug Encoder + # + # Fast encoder producing simple debug output. + # + # It is readable and diff-able and is used for testing. + # + # You cannot fully restore the tokens information from the + # output, because consecutive :space tokens are merged. + # Use Tokens#dump for caching purposes. + class Debug < Encoder + + include Streamable + register_for :debug + + FILE_EXTENSION = 'raydebug' + + protected + def text_token text, kind + @out << + if kind == :space + text + else + text = text.gsub(/[)\\]/, '\\\\\0') + "#{kind}(#{text})" + end + end - def open_token kind - "#{kind}<" - end + def block_token action, kind + @out << super + end - def close_token kind - ">" - end + def open_token kind + "#{kind}<" + end + def close_token kind + ">" end end + +end end diff --git a/lib/coderay/encoders/div.rb b/lib/coderay/encoders/div.rb index 2379a4c..c389a0d 100644 --- a/lib/coderay/encoders/div.rb +++ b/lib/coderay/encoders/div.rb @@ -1,4 +1,5 @@ -module CodeRay module Encoders +module CodeRay +module Encoders load :html @@ -15,4 +16,5 @@ module CodeRay module Encoders end -end end +end +end diff --git a/lib/coderay/encoders/html/classes.rb b/lib/coderay/encoders/html/classes.rb index 3d40a42..e21fce8 100644 --- a/lib/coderay/encoders/html/classes.rb +++ b/lib/coderay/encoders/html/classes.rb @@ -1,4 +1,5 @@ -module CodeRay module Encoders +module CodeRay +module Encoders class HTML @@ -68,4 +69,5 @@ module CodeRay module Encoders end -end end +end +end diff --git a/lib/coderay/encoders/html/css.rb b/lib/coderay/encoders/html/css.rb index ad055aa..fcd9859 100644 --- a/lib/coderay/encoders/html/css.rb +++ b/lib/coderay/encoders/html/css.rb @@ -1,4 +1,5 @@ -module CodeRay module Encoders +module CodeRay +module Encoders class HTML class CSS @@ -55,7 +56,8 @@ module CodeRay module Encoders end end -end end +end +end if $0 == __FILE__ require 'pp' diff --git a/lib/coderay/encoders/html/output.rb b/lib/coderay/encoders/html/output.rb index e9a3a41..203caca 100644 --- a/lib/coderay/encoders/html/output.rb +++ b/lib/coderay/encoders/html/output.rb @@ -1,5 +1,5 @@ module CodeRay - module Encoders +module Encoders class HTML diff --git a/lib/coderay/encoders/null.rb b/lib/coderay/encoders/null.rb index e995cb0..0e3d073 100644 --- a/lib/coderay/encoders/null.rb +++ b/lib/coderay/encoders/null.rb @@ -1,26 +1,26 @@ module CodeRay - module Encoders +module Encoders - # = Null Encoder - # - # Does nothing and returns an empty string. - class Null < Encoder + # = Null Encoder + # + # Does nothing and returns an empty string. + class Null < Encoder - include Streamable - register_for :null + include Streamable + register_for :null - # Defined for faster processing - def to_proc - proc {} - end - - protected + # Defined for faster processing + def to_proc + proc {} + end - def token(*) - # do nothing - end + protected + def token(*) + # do nothing end end + +end end diff --git a/lib/coderay/encoders/span.rb b/lib/coderay/encoders/span.rb index e222889..4d74277 100644 --- a/lib/coderay/encoders/span.rb +++ b/lib/coderay/encoders/span.rb @@ -1,5 +1,6 @@ -module CodeRay module Encoders - +module CodeRay +module Encoders + load :html class Span < HTML @@ -12,6 +13,8 @@ module CodeRay module Encoders :css => :style, :wrap => :span, }) + end -end end +end +end diff --git a/lib/coderay/encoders/statistic.rb b/lib/coderay/encoders/statistic.rb index b8905ff..0cf8831 100644 --- a/lib/coderay/encoders/statistic.rb +++ b/lib/coderay/encoders/statistic.rb @@ -1,4 +1,5 @@ -module CodeRay module Encoders +module CodeRay +module Encoders # Makes a statistic for the given tokens. class Statistic < Encoder @@ -76,4 +77,5 @@ Token Types (%d): end -end end +end +end diff --git a/lib/coderay/encoders/tokens.rb b/lib/coderay/encoders/tokens.rb index 4573307..2bcca40 100644 --- a/lib/coderay/encoders/tokens.rb +++ b/lib/coderay/encoders/tokens.rb @@ -1,44 +1,44 @@ module CodeRay - module Encoders +module Encoders - # The Tokens encoder converts the tokens to a simple - # readable format. It doesn't use colors and is mainly - # intended for console output. - # - # The tokens are converted with Tokens.write_token. - # - # The format is: - # - # \t \n - # - # Example: - # - # require 'coderay' - # puts CodeRay.scan("puts 3 + 4", :ruby).tokens - # - # prints: - # - # ident puts - # space - # integer 3 - # space - # operator + - # space - # integer 4 - # - class Tokens < Encoder + # The Tokens encoder converts the tokens to a simple + # readable format. It doesn't use colors and is mainly + # intended for console output. + # + # The tokens are converted with Tokens.write_token. + # + # The format is: + # + # \t \n + # + # Example: + # + # require 'coderay' + # puts CodeRay.scan("puts 3 + 4", :ruby).tokens + # + # prints: + # + # ident puts + # space + # integer 3 + # space + # operator + + # space + # integer 4 + # + class Tokens < Encoder - include Streamable - register_for :tokens + include Streamable + register_for :tokens - FILE_EXTENSION = 'tok' - - protected - def token *args - @out << CodeRay::Tokens.write_token(*args) - end + FILE_EXTENSION = 'tok' + protected + def token *args + @out << CodeRay::Tokens.write_token(*args) end end + +end end diff --git a/lib/coderay/encoders/xml.rb b/lib/coderay/encoders/xml.rb index 5596f46..246fe0a 100644 --- a/lib/coderay/encoders/xml.rb +++ b/lib/coderay/encoders/xml.rb @@ -1,70 +1,71 @@ module CodeRay - module Encoders +module Encoders - # = Debug Encoder - class XML < Encoder + # = XML Encoder + # + # Uses REXML. Very slow. + class XML < Encoder - include Streamable - register_for :xml + include Streamable + register_for :xml - FILE_EXTENSION = 'xml' + FILE_EXTENSION = 'xml' - require 'rexml/document' + require 'rexml/document' - DEFAULT_OPTIONS = { - :tab_width => 8, - :pretty => -1, - :transitive => false, - } + DEFAULT_OPTIONS = { + :tab_width => 8, + :pretty => -1, + :transitive => false, + } - protected - - def setup options - @out = '' - @doc = REXML::Document.new - @doc << REXML::XMLDecl.new - @tab_width = options[:tab_width] - @root = @node = @doc.add_element('coderay-tokens') - end - - def finish options - @doc.write @out, options[:pretty], options[:transitive], true - @out + protected + + def setup options + @out = '' + @doc = REXML::Document.new + @doc << REXML::XMLDecl.new + @tab_width = options[:tab_width] + @root = @node = @doc.add_element('coderay-tokens') + end + + def finish options + @doc.write @out, options[:pretty], options[:transitive], true + @out + end + + def text_token text, kind + if kind == :space + token = @node + else + token = @node.add_element kind.to_s end - - def text_token text, kind - if kind == :space - token = @node + text.scan(/(\x20+)|(\t+)|(\n)|[^\x20\t\n]+/) do |space, tab, nl| + case + when space + token << REXML::Text.new(space, true) + when tab + token << REXML::Text.new(tab, true) + when nl + token << REXML::Text.new(nl, true) else - token = @node.add_element kind.to_s - end - text.scan(/(\x20+)|(\t+)|(\n)|[^\x20\t\n]+/) do |space, tab, nl| - case - when space - token << REXML::Text.new(space, true) - when tab - token << REXML::Text.new(tab, true) - when nl - token << REXML::Text.new(nl, true) - else - token << REXML::Text.new($&) - end + token << REXML::Text.new($&) end end + end - def open_token kind - @node = @node.add_element kind.to_s - end + def open_token kind + @node = @node.add_element kind.to_s + end - def close_token kind - if @node == @root - raise 'no token to close!' - end - @node = @node.parent + def close_token kind + if @node == @root + raise 'no token to close!' end - + @node = @node.parent end end + +end end - diff --git a/lib/coderay/encoders/yaml.rb b/lib/coderay/encoders/yaml.rb index 4e2b7a1..b842647 100644 --- a/lib/coderay/encoders/yaml.rb +++ b/lib/coderay/encoders/yaml.rb @@ -1,19 +1,22 @@ module CodeRay - module Encoders +module Encoders - class YAML < Encoder + # = YAML Encoder + # + # Slow. + class YAML < Encoder - register_for :yaml + register_for :yaml - FILE_EXTENSION = 'yaml' - - protected - def compile tokens, options - require 'yaml' - @out = tokens.to_a.to_yaml - end + FILE_EXTENSION = 'yaml' + protected + def compile tokens, options + require 'yaml' + @out = tokens.to_a.to_yaml end end + +end end diff --git a/lib/coderay/helpers/filetype.rb b/lib/coderay/helpers/filetype.rb index 7f34c35..8e6e16b 100644 --- a/lib/coderay/helpers/filetype.rb +++ b/lib/coderay/helpers/filetype.rb @@ -80,7 +80,7 @@ end if $0 == __FILE__ $VERBOSE = true - eval DATA.read, nil, $0, __LINE__+4 + eval DATA.read, nil, $0, __LINE__+4 end __END__ diff --git a/lib/coderay/helpers/gzip_simple.rb b/lib/coderay/helpers/gzip_simple.rb index 02d1ffd..357ce6b 100644 --- a/lib/coderay/helpers/gzip_simple.rb +++ b/lib/coderay/helpers/gzip_simple.rb @@ -89,7 +89,7 @@ class String end if $0 == __FILE__ - eval DATA.read, nil, $0, __LINE__+4 + eval DATA.read, nil, $0, __LINE__+4 end __END__ diff --git a/lib/coderay/scanner.rb b/lib/coderay/scanner.rb index eae4c0e..8affb53 100644 --- a/lib/coderay/scanner.rb +++ b/lib/coderay/scanner.rb @@ -232,4 +232,3 @@ class String end end end -# vim:sw=2:ts=2:noet:tw=78 diff --git a/lib/coderay/scanners/_map.rb b/lib/coderay/scanners/_map.rb index f6e4452..1482ee9 100644 --- a/lib/coderay/scanners/_map.rb +++ b/lib/coderay/scanners/_map.rb @@ -1,14 +1,14 @@ module CodeRay - module Scanners - - map :cpp => :c, - :plain => :plaintext, - :pascal => :delphi, - :irb => :ruby, - :xml => :html, - :xhtml => :nitro_html +module Scanners + + map :cpp => :c, + :plain => :plaintext, + :pascal => :delphi, + :irb => :ruby, + :xml => :html, + :xhtml => :nitro_html - default :plain - - end + default :plain + +end end diff --git a/lib/coderay/scanners/c.rb b/lib/coderay/scanners/c.rb index ae0af73..effaaa1 100644 --- a/lib/coderay/scanners/c.rb +++ b/lib/coderay/scanners/c.rb @@ -1,4 +1,5 @@ -module CodeRay module Scanners +module CodeRay +module Scanners class C < Scanner @@ -150,4 +151,5 @@ module CodeRay module Scanners end -end end +end +end diff --git a/lib/coderay/scanners/delphi.rb b/lib/coderay/scanners/delphi.rb index d02c632..c92fab5 100644 --- a/lib/coderay/scanners/delphi.rb +++ b/lib/coderay/scanners/delphi.rb @@ -1,4 +1,5 @@ -module CodeRay module Scanners +module CodeRay +module Scanners class Delphi < Scanner @@ -124,4 +125,5 @@ module CodeRay module Scanners end -end end +end +end diff --git a/lib/coderay/scanners/html.rb b/lib/coderay/scanners/html.rb index e8eea61..186a255 100644 --- a/lib/coderay/scanners/html.rb +++ b/lib/coderay/scanners/html.rb @@ -1,4 +1,5 @@ -module CodeRay module Scanners +module CodeRay +module Scanners # HTML Scanner # @@ -162,4 +163,5 @@ module CodeRay module Scanners end -end end +end +end diff --git a/lib/coderay/scanners/nitro_html.rb b/lib/coderay/scanners/nitro_html.rb index 86d4992..119924b 100644 --- a/lib/coderay/scanners/nitro_html.rb +++ b/lib/coderay/scanners/nitro_html.rb @@ -1,4 +1,5 @@ -module CodeRay module Scanners +module CodeRay +module Scanners load :html load :ruby @@ -120,4 +121,5 @@ module CodeRay module Scanners end -end end +end +end diff --git a/lib/coderay/scanners/plaintext.rb b/lib/coderay/scanners/plaintext.rb index 0aebf35..3824ee9 100644 --- a/lib/coderay/scanners/plaintext.rb +++ b/lib/coderay/scanners/plaintext.rb @@ -1,4 +1,5 @@ -module CodeRay module Scanners +module CodeRay +module Scanners class Plaintext < Scanner @@ -10,4 +11,5 @@ module CodeRay module Scanners end -end end +end +end diff --git a/lib/coderay/scanners/rhtml.rb b/lib/coderay/scanners/rhtml.rb index 77a4366..3b1817e 100644 --- a/lib/coderay/scanners/rhtml.rb +++ b/lib/coderay/scanners/rhtml.rb @@ -1,4 +1,5 @@ -module CodeRay module Scanners +module CodeRay +module Scanners load :html load :ruby @@ -60,4 +61,5 @@ module CodeRay module Scanners end -end end +end +end diff --git a/lib/coderay/scanners/ruby.rb b/lib/coderay/scanners/ruby.rb index 1dbcb17..6e08a1f 100644 --- a/lib/coderay/scanners/ruby.rb +++ b/lib/coderay/scanners/ruby.rb @@ -1,4 +1,5 @@ -module CodeRay module Scanners +module CodeRay +module Scanners # This scanner is really complex, since Ruby _is_ a complex language! # @@ -390,5 +391,7 @@ module CodeRay module Scanners end end -end end +end +end + # vim:fdm=marker diff --git a/lib/coderay/scanners/ruby/patterns.rb b/lib/coderay/scanners/ruby/patterns.rb index 28439ec..63d12f0 100644 --- a/lib/coderay/scanners/ruby/patterns.rb +++ b/lib/coderay/scanners/ruby/patterns.rb @@ -1,8 +1,7 @@ -module CodeRay module Scanners +module CodeRay +module Scanners -class Ruby - - module Patterns # :nodoc: + module Ruby::Patterns # :nodoc: RESERVED_WORDS = %w[ and def end in or unless begin @@ -210,9 +209,8 @@ class Ruby super kind, interpreted, delim, heredoc, paren, paren_depth, pattern, :initial end end unless defined? StringState - + end end - -end end +end diff --git a/lib/coderay/styles/_map.rb b/lib/coderay/styles/_map.rb index 33c2327..25687d6 100644 --- a/lib/coderay/styles/_map.rb +++ b/lib/coderay/styles/_map.rb @@ -1,7 +1,7 @@ module CodeRay - module Styles - - default :cycnus - - end +module Styles + + default :cycnus + +end end diff --git a/lib/coderay/styles/cycnus.rb b/lib/coderay/styles/cycnus.rb index b635706..5037044 100644 --- a/lib/coderay/styles/cycnus.rb +++ b/lib/coderay/styles/cycnus.rb @@ -1,16 +1,16 @@ module CodeRay - module Styles - - class CYcnus < Style - - register_for :cycnus - - code_background = '#f8f8f8' - numbers_background = '#def' - border_color = 'silver' - normal_color = '#100' - - CSS_MAIN_STYLES = <<-MAIN +module Styles + + class Cycnus < Style + + register_for :cycnus + + code_background = '#f8f8f8' + numbers_background = '#def' + border_color = 'silver' + normal_color = '#100' + + CSS_MAIN_STYLES = <<-MAIN .CodeRay { background-color: #{code_background}; border: 1px solid #{border_color}; @@ -39,9 +39,9 @@ ol.CodeRay { font-size: 10pt } ol.CodeRay li { white-space: pre } .CodeRay .code pre { overflow: auto } - MAIN + MAIN - TOKEN_COLORS = <<-'TOKENS' + TOKEN_COLORS = <<-'TOKENS' .af { color:#00C } .an { color:#007 } .av { color:#700 } @@ -117,9 +117,9 @@ ol.CodeRay li { white-space: pre } .ty { color:#339; font-weight:bold } .v { color:#036 } .xt { color:#444 } - TOKENS - - end - + TOKENS + end + +end end diff --git a/lib/coderay/styles/murphy.rb b/lib/coderay/styles/murphy.rb index f5cb2cb..9377a10 100644 --- a/lib/coderay/styles/murphy.rb +++ b/lib/coderay/styles/murphy.rb @@ -1,16 +1,16 @@ module CodeRay - module Styles - - class Murphy < Style - - register_for :murphy - - code_background = '#001129' - numbers_background = code_background - border_color = 'silver' - normal_color = '#C0C0C0' - - CSS_MAIN_STYLES = <<-MAIN +module Styles + + class Murphy < Style + + register_for :murphy + + code_background = '#001129' + numbers_background = code_background + border_color = 'silver' + normal_color = '#C0C0C0' + + CSS_MAIN_STYLES = <<-MAIN .CodeRay { background-color: #{code_background}; border: 1px solid #{border_color}; @@ -39,9 +39,9 @@ ol.CodeRay { font-size: 10pt; } ol.CodeRay li { white-space: pre; } .CodeRay .code pre { overflow: auto; } - MAIN + MAIN - TOKEN_COLORS = <<-'TOKENS' + TOKEN_COLORS = <<-'TOKENS' .af { color:#00C; } .an { color:#007; } .av { color:#700; } @@ -111,9 +111,9 @@ ol.CodeRay li { white-space: pre; } .ty { color:#339; font-weight:bold; } .v { color:#036; } .xt { color:#444; } - TOKENS - - end - + TOKENS + end + +end end -- cgit v1.2.1